public class Bouncer { float xPos; float yPos; float xOld = width/2; float yOld = height-100; //was -100 float x2Old = width/2; float y2Old = height-200; //was -200 float left = 0; float right = width; float myfloor = height; float ceiling = height-100; float friction = random(0.3f,0.7f); float elastic = random(0.3f,0.7f); //0.3 and 0.7 float gravity; float rot; float xd, yd; float xVel, newXVel; float yVel, newYVel; float xDelta, yDelta, distance; Bouncer (float xp, float yp, float rp, float xv, float yv) { xPos = xp; yPos = yp; rot = rp; xVel = xv; yVel = yv; gravity = 1; } void bounce () { x2Old = xOld; y2Old = yOld; xOld = xPos; yOld = yPos; if (yPos > myfloor){ gravity = -1; } else { gravity = 1; } yVel = yVel + (gravity * elastic); xPos = xPos + xVel; yPos = yPos + yVel; if (xPos > right){ xPos = right; xVel = xVel * -elastic; // xVel--; } else if (xPos < left){ xPos = left; xVel = xVel * -elastic; // xVel--; } if (!click){ if (gravity == 1){ if (yPos > myfloor){ yVel = yVel * elastic; xVel = xVel * friction; // yVel-=5; } } else { if (yPos < myfloor){ yVel = yVel * elastic; xVel = xVel * friction; gravity = 1; gravity+=20; } } } xDelta = attackX - xPos; yDelta = attackY - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (!click && distance < 80){ yVel = random(-5,5); } else if (click && distance < 250){ newXVel = xVel * elastic + (attackX - xPos) * friction; newYVel = yVel * elastic + (attackY - yPos) * friction; xVel = xVel - ((xVel - newXVel) * .05f); yVel = yVel - ((yVel - newYVel) * .05f); } strokeWeight(3); stroke(strokeVar); stroke((abs(yVel) + abs(xVel))*2,120); stroke(0); line(xPos, yPos, xOld-5, yOld-5); stroke(strokeVar/2); // stroke(255,0,0,120); stroke(252,113,5,200); // stroke((abs(yVel) + abs(xVel))*4,0,0); //main color: stroke(252,113,5,200); line(xPos, yPos, xOld-5, yOld-5); stroke(strokeVar/4); stroke((abs(yVel) + abs(xVel))*16,0,0); stroke(252,183,5,120); line(xOld, yOld, x2Old-5, y2Old-5); strokeWeight(1); }//end of bounce method } //end of Bouncer class