import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; public class bouncers9 extends BApplet { // Set the font and its size (in units of pixels) int xWidth = 600, yHeight = 600; int total = 1000; Bouncer[] bouncer = new Bouncer[total]; Meander m1 = new Meander(); boolean clear = true; boolean click = false; int counter = 0; int strokeVar = 2; void setup() { size(600,600); noBackground(); noStroke(); fill(75); rect(0,0,width,height); ellipseMode(CENTER_DIAMETER); for (int i=0; i right){ xDelta = random (-1,0); } else { xDelta = random(-1,1); } if (yPos < bottom){ yDelta = random(0,1); } else if (yPos > top){ yDelta = random (-1,0); } else { yDelta = random(-1,1); } xSpeed = xSpeed + xDelta; ySpeed = ySpeed + yDelta; if (xSpeed > xMax){ xSpeed = xMax; } else if (xSpeed < -xMax){ xSpeed = -xMax; } if (ySpeed > yMax){ ySpeed = yMax; } else if (ySpeed < -yMax){ ySpeed = -yMax; } xPos = xPos + xSpeed; yPos = yPos + ySpeed; if (random(100) < 2){ xPos += random(-50,50); yPos += random(-50,50); xSpeed = random(-5,5); ySpeed = random(-5,5); } } } class Bouncer { float xPos; float yPos; float xOld = mouseX; float yOld = mouseY; float x2Old = mouseX; float y2Old = mouseY; float left = 0; float right = width; float floor = height/2 + random(-2,2); float ceiling = 0; float friction = random(0.1f,0.8f); float elastic = random(0.1f,0.8f); float gravity; float xd, yd; float xVel, newXVel; float yVel, newYVel; float xDelta, yDelta, distance; float randomXVar = random(-10,10); float randomYVar = random(-10,10); Bouncer (float xp, float yp, float xv, float yv) { xPos = xp; yPos = yp; xVel = xv; yVel = yv; } void bounce () { x2Old = xOld; y2Old = yOld; xOld = xPos; yOld = yPos; if (xPos > right){ xPos = right; xVel = xVel * -elastic; } else if (xPos < left){ xPos = left; xVel = xVel * -elastic; } xDelta = mouseX - xPos; yDelta = mouseY - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (!click && distance < 25){ //gravity = gravity * -1; if (mouseX > pmouseX){ xd = mouseX - pmouseX; if (xd > 25){ xd = 25; } xVel = random(0,xd); } else if (pmouseX > mouseX){ xd = mouseX - pmouseX; if (xd < -25){ xd = -25; } xVel = random(xd,0); } else { xVel = random(-5,5); } if (mouseY > pmouseY){ yd = mouseY - pmouseY; if (yd > 25){ yd = 25; } yVel = random(0,yd); } else if (pmouseY > mouseY){ yd = mouseY - pmouseY; if (yd < -25){ yd = -25; } yVel = random(yd,0); } else { yVel = random(-5,5); } } if (!click || (click && distance >= 150)){ newXVel = xVel * elastic + ((m1.xPos + randomXVar) - xPos) * friction; newYVel = yVel * elastic + ((m1.yPos + randomYVar) - yPos) * friction; xVel = xVel - ((xVel - newXVel) * .05f); yVel = yVel - ((yVel - newYVel) * .05f); } else if (click && distance < 150){ newXVel = xVel * elastic + (mouseX - xPos) * friction; newYVel = yVel * elastic + (mouseY - yPos) * friction; xVel = xVel - ((xVel - newXVel) * .1f); yVel = yVel - ((yVel - newYVel) * .1f); } xPos = xPos + xVel; yPos = yPos + yVel; stroke(abs(yVel) + abs(xVel)); strokeWidth(2); line(xPos, yPos, xOld, yOld); if (xVel < 0){ if(random(50)<5){ stroke(100,100,255); } else { stroke(0,0,(abs(yVel) + abs(xVel))*5 + 100); } } else { if(random(50)<5){ stroke(255,100,100); } else { stroke((abs(yVel) + abs(xVel))*5 + 100,0,0); } } strokeWidth(0); line(xPos, yPos, xOld, yOld); } } }