Tiffany - M

By Tiffany
//Keep the cursor from the monster, unless you want him to eat it! int numMonsters = 10; Monster[] monsters = new Monster[numMonsters]; Monster m1; Monster m2; boolean eaten = false; float timeEaten; PImage cursor; PFont font; void setup() { size(600, 400); frameRate(30); smooth(); background(255); cursor = loadImage( "cursor.png"); font = loadFont("DIN-Medium-24.vlw"); noCursor(); monsters = new Monster[numMonsters]; for (int i =0 ; i < numMonsters; i++) { float x = random(mouseX+i); float y = random(mouseY+i); float e = 0.1 + random(i/50); float r = random(30, 40); monsters[i] = new Monster (x, y, e, r); } } // end void setup void draw() { background(255); noStroke(); if (eaten == false) { for (int i =0 ; i < numMonsters; i++) { monsters[i].draw(mouseX, mouseY); } } else { for (int i =0 ; i < numMonsters; i++) { monsters[i].draw(random(width+10*i), random(height+ 10*i)); } } //eating the cursor if (get(mouseX, mouseY) != -1) { eaten = true; timeEaten = millis(); if (millis() - timeEaten < 3000) { textFont(font); fill(100); text("YUM", mouseX, mouseY); } } else if (eaten == false) { image(cursor, mouseX, mouseY); } else if ((eaten == true) && (millis()- timeEaten) > 2000) { eaten = false; } } // end void draw; class BodyPart { float x,y; float radius; BodyPart(float _x, float _y, float _radius, float _ang) { x = _x; y = _y; radius = _radius; } void update(float _x, float _y){ if(dist(x,y,_x,_y)> 5) { float d = dist(x,y,_x,_y); float angle = atan2((y-_y),(x-_x)); x = _x + cos(angle) * 5; y = _y + sin(angle) * 5; } else { float d = dist(x,y,_x,_y); float angle = atan2((y-_y),(x-_x)); x = _x + cos(angle) * d; y = _y + sin(angle) * d; } //draw(); } void draw() { fill(0); ellipse(x,y,radius,radius); } } class Monster { float x,y; float px,py; float easing; int age; float radius; float mx,my; float _mx, _my; BodyPart parts[]; int num_of_BodyPart = 30; Monster(float _x, float _y, float _e, float _r) { x = _x; y = _y; px = x; py = y; easing = _e; age = 0; radius = _r; parts = new BodyPart[num_of_BodyPart]; for(int i=0;i<parts.length;i++){ //parts[i] = new BodyPart(width/2, height/2, num_of_BodyPart-i, 0); parts[i] = new BodyPart(width/2, height/2, radius-i, 0); } } void draw(float _x, float _y) { px = x; py = y; x += (_x - x)*easing; y += (_y - y)*easing; age++; //draw(); for(int i=0;i<num_of_BodyPart;i++){ if(i == 0){ parts[i].update(x,y); } else { parts[i].update(parts[i-1].x,parts[i-1].y); } parts[i].draw(); } } }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*