Charlene - M

By Charlene
Monster[]monsters; int numMonsters = 20; PShape s; PShape s2; void setup() { size(600, 400); smooth(); s = loadShape("Monster2.svg"); s2 = loadShape("Monster.svg"); monsters = new Monster [numMonsters]; for(int i = 0; i < numMonsters; i++) { float x = width/2; float y = height/2; float sd = 0; monsters[i] = new Monster(x, y, sd); } } void draw() { background(255); for(int i = 0; i < numMonsters; i++) { monsters[i].display(); monsters[i].move(); } } class Monster { float x; float y; float speed; float d; Monster(float xpos, float ypos, float sd) { x = xpos; y = ypos; speed = sd; } void move() { x += random(-1, 1) * speed; y += random(-1, 1) * speed; x = constrain(x, 0, width); y = constrain(y, 0, height); if(dist(x, y, mouseX, mouseY) < 20) { speed = speed - speed; } else if(dist(x, y, mouseX, mouseY) > 20) { speed = speed + 0.05; } } void display() { d = dist(x, y, mouseX, mouseY); shape(s, x, y, d/2, d/2); shape(s2, x, y, 90, 80); shapeMode(CENTER); } }

Post a Comment

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

*
*