// ------------------------------------------------------------- // Homage to Winsor McCay // by Lauren Langley, based on program written by Hye Yeon Nam // Concept: to pay homage to Winsor McCay, pioneer of animation // All data images are artworks by McCay // Object named 'aggravator' is controlled by mouse detection // Aggravator animation is paused when encounters moon object // Aggravator attracts animated figure object called 'subject' // Subject object animates when encounters moon object // Moon objects can be added and deleted // // Keyboard controls: // -- Press UP arrow increase number of moon objects (max of 10) // -- Press DOWN to decrease number of moon objects // ------------------------------------------------------------- int numFrames = 2; //Define arrays PImage[] mccay = new PImage[numFrames]; PImage[] nemo = new PImage[numFrames]; //Define variables ArrayList objects; PImage aggravatorImg; PImage subjectsImg; PImage moonImg; PImage backImg; //Setup interactive object characteristics int initialaggravatorCount = 1; //mccay float aggravatorMinSpeed = 30; float aggravatorMaxSpeed = 80; float aggravatorWidth = 75; float aggravatorHeight = 81; float aggravatorSenseRadius = 60; int initialsubjectsCount = 5; //nemo float subjectsMinSpeed = 30; float subjectsMaxSpeed = 70; float subjectsWidth = 80; float subjectsHeight = 125; float subjectsSenseRadius = 70; int initialmoonCount = 0; //moon float moonMinSpeed = 20; float moonMaxSpeed = 40; float moonWidth = 50; float moonHeight = 50; float moonSenseRadius = 60; float objectMaxNumber = 16; //max number of all objects allowed on canvas //========================= void setup() { size(650, 411); frameRate(8); mccay[0] = loadImage("mccay1.png"); mccay[1] = loadImage("mccay2.png"); nemo[0] = loadImage("nemo1.png"); nemo[1] = loadImage("nemo2.png"); aggravatorImg = loadImage("mccay1.png"); subjectsImg = loadImage("nemo1.png"); moonImg = loadImage("moon.png"); backImg = loadImage("back.png"); objects = new ArrayList(); for (int i = 0; i 6) { objects.remove(objects.size()-1); } } } } //===================== void addaggravator() { aggravator a = new aggravator (aggravatorImg, random(10, width-10), random(10, height-10), aggravatorWidth, aggravatorHeight, random(aggravatorMinSpeed, aggravatorMaxSpeed), aggravatorSenseRadius); objects.add(a); } void addsubjects(float x, float y) { subjects a = new subjects (subjectsImg, random(10, width-10), random(10, height-10), subjectsWidth, subjectsHeight, random(subjectsMinSpeed, subjectsMaxSpeed), subjectsSenseRadius); objects.add(a); } void addmoon(float x, float y) { moon a = new moon (moonImg, random(10, width-10), random(10, height-10), moonWidth, moonHeight, random(moonMinSpeed, moonMaxSpeed), moonSenseRadius); objects.add(a); } void draw() { image(backImg, 0, 0); //Draw Subject sense radius Subject a; //class, a is containor for(int i=0; i width) { x = width; } if (x < 0) { x = 0; } if (y > height) { y = height; } if (y < 0) { y = 0; } } } } //=============================== //Aggravator class = mccay object //=============================== class aggravator extends Subject { //Constructor aggravator (PImage indectImg, float x, float y, float w, float h, float speed, float senseRadius) { super(aggravatorImg, x, y, w, h, speed, senseRadius); this.senseRadiusColor = color(31,234,255,40); //black alpha this.senseRadiusStrokeWeight = 0; this.senseRadiusStrokeColor = color(255,255,255,0); } void determineTarget(ArrayList aggravators) { this.x = mouseX; this.y = mouseY; } void draw() { if(canSeeThemoon()) { img = aggravatorImg; } else { frame++; if(frame == numFrames) { frame = 0; } img = mccay[frame]; } super.draw(); } } //========================================= //subjects class = nemo objects //========================================= class subjects extends Subject { //Constructor subjects (PImage subjectsImg, float x, float y, float w, float h, float speed, float senseRadius) { super(subjectsImg, x, y, w, h, speed, senseRadius); this.senseRadiusColor = color(255,0,0,30); //red alpha this.senseRadiusStrokeWeight = 0; } void determineTarget(ArrayList objects) { super.determineTarget(objects); //no movement by default this.setSubjectTarget(null, true); Subject a; boolean foundmoon = canSeeThemoon(); for(int i = 0; i < objects.size(); i++) { a = (Subject) objects.get(i); if (a instanceof aggravator) { if (this.getDistance(a) <= this.senseRadius ) { if (foundmoon) { //move towards the aggravator this.setSubjectTarget(a, true); } else { //move away from the aggravator this.setSubjectTarget(a, false); } } } } } void draw() { if(canSeeThemoon()) { frame++; if(frame == numFrames) { frame = 0; } img = nemo[frame]; } else { img = subjectsImg; } super.draw(); } void drawSenseRadius() { super.drawSenseRadius(); fill(0); boolean canSeemoon = canSeeThemoon(); } void pickRandomsubjectsWithinRadius() { float senseRadius = this.w *6; ArrayList subjectss = getobjectsWithinRadius(objects, senseRadius); //subjectss within radius Subject a; for(int i = 0; i < subjectss.size(); i++) { a = (Subject) subjectss.get(i); if ( !(a instanceof subjects) ) { subjectss.remove(i); i--; } } //randomly pick subject within radius and make it the target if (subjectss.size() > 0) { subjects b = (subjects) subjectss.get((int)random(subjectss.size()) ); this.setSubjectTarget(b, true); } } } //=========== //moon class //=========== class moon extends Subject { //Constructor moon (PImage Img, float x, float y, float w, float h, float speed, float senseRadius) { super(Img, x, y, w, h, speed, senseRadius); this.senseRadiusColor = color(255,187,103,70); //yellow this.senseRadiusStrokeWeight = 0; } void determineTarget(ArrayList objects) { float n = random(0, 100); if (n <= 10) { //move randomly this.setTarget(this.x + random(-50, 50), this.y + random(-50, 50), true); } else if (n <= 15) { //move towards objects pickRandomsubjectsWithinRadius(); } else { //stay in place this.setSubjectTarget(null, true); } } void pickRandomsubjectsWithinRadius() { float senseRadius = this.w *4; ArrayList subjectss = getobjectsWithinRadius(objects, senseRadius); //subjectss within radius Subject a; for(int i = 0; i < subjectss.size(); i++) { a = (Subject) subjectss.get(i); if ( !(a instanceof subjects) ) { subjectss.remove(i); i--; } } //randomly pick a subject within radius and make it the target if (subjectss.size() > 0) { subjects b = (subjects) subjectss.get((int)random(subjectss.size()) ); this.setSubjectTarget(b, true); } } }