//PROCESSING MONSTER
//Move the mouse through the monster in order to
//push it in that direction.
//Greg Batha - Exercise L
//DESMA 28 Interactivity
//global variables
PShape jellyShape;
PShape jellyFace;
Jelly[] jellies = new Jelly[10];
Jelly j1;
void setup(){
size(600, 400);
smooth();
background(0);
fill(255);
rect(-1, -1, width+2, height-50);
jellyShape = loadShape("jellyShape.svg");
jellyFace = loadShape("jellyFace.svg");
for(int i = 0; i < jellies.length; i++){
float place = i * (width/15);
float jsize = random(25, 125);
jellies[i] = new Jelly(place, jsize);
}
}
void draw(){
background(0);
rect(-1, -1, width+2, height-50);
for (int i = 0; i < jellies.length; i++) {
jellies[i].move();
jellies[i].display();
}
//println(brightness(get(mouseX, mouseY)));
//mouse velocity test
//println((mouseX - pmouseX) + ", " + (mouseY - pmouseY));
//get color test
//println(j1.vertVelocity + ", " + j1.horizVelocity);
}
class Jelly{
//class variables
float jellyx;
float jellyy;
float jellyWidth;
float jellyHeight;
float origJellyHeight;
float angle;
float speed;
float radius;
boolean jumping;
float[] horizVelArray;
float[] vertVelArray;
int velCount;
float vertAccel;
float horizAccel;
float vertVelocity;
float horizVelocity;
Jelly(float xIn, float heightIn){
jellyHeight = heightIn;
origJellyHeight = jellyHeight;
jellyWidth = jellyHeight * 1.2442;
jellyx = xIn;
jellyy = height - jellyHeight - 49;
angle = 0.0;
speed = 0.1;
radius = 5;
jumping = false;
horizVelArray = new float[5];
vertVelArray = new float[5];
velCount = 0;
}
void move(){
if (mouseX > jellyx && mouseX < jellyx + jellyWidth && mouseY > jellyy
&& mouseY < mouseY + jellyy + jellyHeight && jumping == false){
//if velCount < array.length then array[velcount] = mouse speed
if(velCount < horizVelArray.length){
horizVelArray[velCount] = mouseX - pmouseX;
if(mouseY - pmouseY < 0){
vertVelArray[velCount] = mouseY - pmouseY;
}
else {
vertVelArray[velCount] = -(mouseY - pmouseY);
}
velCount++;
}
//else jumping = true, for loop determines velocity
else {
for(int i = 0; i < horizVelArray.length; i ++){
horizVelocity += horizVelArray[i];
}
horizVelocity = constrain(horizVelocity / horizVelArray.length, -10, 10);
for(int i = 0; i < vertVelArray.length; i ++){
vertVelocity += vertVelArray[i];
}
vertVelocity = constrain(vertVelocity / vertVelArray.length, -15, 0);
velCount = 0;
jumping = true;
}
}
//adjusts position while jumping == true
if(jumping == true ){
if(jellyx <= 0 || jellyx >= width-jellyWidth){
horizVelocity = -horizVelocity;
}
jellyx = constrain(jellyx+horizVelocity / 2, 0, width - jellyWidth);
jellyy = constrain(jellyy+vertVelocity / 2, -800, height - jellyHeight - 49);
vertVelocity += 0.2;
if(jellyy == height - jellyHeight - 49){
jumping = false;
}
}
else {
angle += speed;
float sinval = sin(angle);
float yoffset = sinval * radius;
jellyHeight = origJellyHeight + yoffset;
jellyy = height - jellyHeight - 49;
}
}
void display(){
shape(jellyShape, jellyx, jellyy, jellyWidth, jellyHeight);
shape(jellyFace, jellyx, jellyy, jellyWidth, origJellyHeight);
}
}
Gregory - M
on Monday, Nov 24, 2008 – 7:07 am
One Comment
omg greg are they riceballs? so freaking adorable. great job on the movement/interaction!