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 bouncers11 extends BApplet { // Sound code modified from source by [rocha] int xWidth = 800, yHeight = 400; 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(800,400); noBackground(); noStroke(); fill(75); rect(0,0,width,height); ellipseMode(CENTER_DIAMETER); colorMode(HSB, 500); 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(50) < 5){ xPos += random(-50,50); yPos += random(-50,50); } } } class Bouncer { float xPos; float yPos; float xOld = mouseX; float yOld = mouseY; float x2Old = mouseX; float y2Old = mouseY; float x3Old = mouseX; float y3Old = mouseY; float left = 0; float right = width; float bottom = 0; float top = height; float friction = random(0.2f,0.5f); float elastic = random(0.4f,0.8f); float gravity; float xd, yd; float xVel, newXVel; float yVel, newYVel; float totalVel; float xDelta, yDelta, distance; float x2Delta, y2Delta, distance2; 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 () { x3Old = x2Old; y3Old = y2Old; x2Old = xOld; y2Old = yOld; xOld = xPos; yOld = yPos; xDelta = mouseX - xPos; yDelta = mouseY - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); x2Delta = m1.xPos - xPos; y2Delta = m1.yPos - yPos; distance2 = sqrt(sq(x2Delta) + sq(y2Delta))/5; if (!click && distance < 30){ //gravity = gravity * -1; if (mouseX > pmouseX){ xd = mouseX - pmouseX; if (xd > 50){ xd = 50; } xVel = random(0,xd); } else if (pmouseX > mouseX){ xd = mouseX - pmouseX; if (xd < -50){ xd = -50; } xVel = random(xd,0); } else { xVel = random(-5,5); } if (mouseY > pmouseY){ yd = mouseY - pmouseY; if (yd > 50){ yd = 50; } yVel = random(0,yd); } else if (pmouseY > mouseY){ yd = mouseY - pmouseY; if (yd < -50){ yd = -50; } yVel = random(yd,0); } else { yVel = random(-5,5); } } if (!click || (click && distance >= 200)){ 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 < 200){ 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; totalVel = (abs(xVel) + abs(yVel)); if (xVel < 0){ if(random(50)<5){ stroke(totalVel*12,500,500); } else { stroke(totalVel*12,500,300); } } else { if(random(50)<5){ stroke(totalVel*12,500,500); } else { stroke(totalVel*12,500,300); } } strokeWidth(2); line(xPos, yPos, xOld, yOld); stroke(totalVel*10,500,500); strokeWidth(1); line(xOld, yOld, x2Old, y2Old); stroke(totalVel*8,500,500); strokeWidth(0); line(x2Old, y2Old, x3Old, y3Old); } } }