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 distort1 extends BApplet { int xWidth = 650, yHeight = 285; int total = 20615; int totalButtons = 7; Bouncer[] bouncer = new Bouncer[total]; Button[] selects = new Button[totalButtons]; Follower f1 = new Follower(); Button lineToggle = new Button(28,290,10,4,false,100); Button clearScreen = new Button(12,290,10,4,false,101); Slider alphaSlider = new Slider(150,289,10,6,false,101); boolean clear = true; boolean click = false; boolean binary = true; int counter = 0; int strokeVar = 2; int selected = 0; int alphaVar; int[] tbgPixels; void setup() { size(650,300); tbgPixels = new int[width*height]; noBackground(); fill(222,222,197); noStroke(); rect(0,0,width,height); ellipseMode(CENTER_DIAMETER); for (int c=0; c 288 && mouseX > 554 && mouseX < 634){ fill(149,56,0); stroke(222,222,197); rect(542,288,92,8); } else { fill(222,222,197,50); stroke(149,56,0); rect(542,288,92,8); } } class Follower { float xPos,yPos,xp2,yp2; void move(){ xp2 = xPos; yp2 = yPos; xPos -= (xPos - mouseX) * .5f; yPos -= (yPos - mouseY) * .5f; } } class Bouncer { float xOld, yOld; float xOld2, yOld2; float initX, initY; float xPos; float yPos; 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, d; float xVel, newXVel; float yVel, newYVel; float totalVel; float xDelta, yDelta, distance; float distMax = 500; int theColor; Bouncer (float xp, float yp, float xv, float yv, int sentColor) { initX = xp; initY = yp; xPos = xp; yPos = yp; xOld = xp; yOld = yp; xOld2 = xp; yOld2 = yp; xVel = xv; yVel = yv; theColor = sentColor; } void reset () { xPos = initX; yPos = initY; xOld = initX; yOld = initY; xOld2 = initX; yOld2 = initY; xVel = 0; yVel = 0; } void move () { yOld2 = yOld; xOld2 = xOld; xOld = xPos; yOld = yPos; if (selected == 0){ enlarge(); } else if (selected == 1){ puddle(); } else if (selected == 2){ spherize(); } else if (selected == 3){ slowmo(); } else if (selected == 4){ ripples(); } else if (selected == 5){ breakApart(); } else if (selected == 6){ breakApart2(); } //borders(); xPos += xVel; yPos += yVel; if (lineToggle.active){ stroke(200,180,150); line(xPos-(xVel/4),yPos-(yVel/4),xPos-(xVel/8),yPos-(yVel/8)); stroke(180,100,85); line(xPos-(xVel/8),yPos-(yVel/8),xPos-(xVel/16),yPos-(yVel/16)); stroke(165,55,0); line(xPos-(xVel/16),yPos-(yVel/16),xPos,yPos); } else { stroke(156,49,0); point(xPos, yPos); } } void puddle(){ distMax = 500; xDelta = f1.xPos - xPos; yDelta = f1.yPos - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (distance > distMax-1){ distance = distMax-1; } if (!click){ xd = xPos - initX; yd = yPos - initY; d = sqrt(sq(xd) + sq(yd)); newXVel = xVel * ((distMax - d)/(distMax + 10)) + (initX - xPos) * (d/(distMax + 10)); newYVel = yVel * ((distMax - d)/(distMax + 10)) + (initY - yPos) * (d/(distMax + 10)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } else { newXVel = xVel * sin(distance/10) + (mouseX - xPos) * sin(distance/10); newYVel = yVel * cos(distance/10) + (mouseY - yPos) * cos(distance/10); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } } void enlarge(){ distMax = 500; xDelta = f1.xPos - xPos; yDelta = f1.yPos - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (distance > distMax-1){ distance = distMax-1; } if (!click){ xd = xPos - initX; yd = yPos - initY; d = sqrt(sq(xd) + sq(yd)); newXVel = xVel * ((distMax - d)/(distMax + 10)) + (initX - xPos) * (d/(distMax + 10)); newYVel = yVel * ((distMax - d)/(distMax + 10)) + (initY - yPos) * (d/(distMax + 10)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } else { newXVel = xVel * (sin((distance)/(distMax/3))) + (mouseX - xPos) * (sin((distance)/(distMax + 0)) - .5f); newYVel = yVel * (cos((distance)/(distMax/3))) + (mouseY - yPos) * (sin((distance)/(distMax + 0)) - .5f); xVel -= (xVel - newXVel) * .1f; yVel -= (yVel - newYVel) * .1f; } } void spherize(){ distMax = 10000; xDelta = f1.xPos - xPos; yDelta = f1.yPos - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (distance > distMax-1){ distance = distMax-1; } if (!click){ xd = xPos - initX; yd = yPos - initY; d = sqrt(sq(xd) + sq(yd)); newXVel = xVel * ((distMax - d)/(distMax + 10)) + (initX - xPos) * (d/(distMax + 10)); newYVel = yVel * ((distMax - d)/(distMax + 10)) + (initY - yPos) * (d/(distMax + 10)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } else { newXVel = xVel * (cos((distMax - distance)/(distMax))) + (mouseX - xPos) * (sin((distance)/(distMax + 500)) -.1f); newYVel = yVel * (cos((distMax - distance)/(distMax))) + (mouseY - yPos) * (sin((distance)/(distMax + 500)) -.1f); xVel -= (xVel - newXVel) * .1f; yVel -= (yVel - newYVel) * .1f; } } void slowmo(){ distMax = 10000; xDelta = f1.xPos - xPos; yDelta = f1.yPos - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (distance > distMax-1){ distance = distMax-1; } if (!click){ xd = xPos - initX; yd = yPos - initY; d = sqrt(sq(xd) + sq(yd)); newXVel = xVel * ((distMax - d)/(distMax + 10)) + (initX - xPos) * (d/(distMax + 10)); newYVel = yVel * ((distMax - d)/(distMax + 10)) + (initY - yPos) * (d/(distMax + 10)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } else { newXVel = xVel * ((distMax - distance)/(distMax + 200)) + (mouseX - xPos) * (distance/(distMax + 200)); newYVel = yVel * ((distMax - distance)/(distMax + 200)) + (mouseY - yPos) * (distance/(distMax + 200)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } } void ripples(){ distMax = 800; xDelta = f1.xPos - xPos; yDelta = f1.yPos - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (distance > distMax-1){ distance = distMax-1; } if (!click){ xd = xPos - initX; yd = yPos - initY; d = sqrt(sq(xd) + sq(yd)); newXVel = xVel * ((distMax - d)/(distMax + 50)) + (initX - xPos) * (d/(distMax + 50)); newYVel = yVel * ((distMax - d)/(distMax + 50)) + (initY - yPos) * (d/(distMax + 50)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } else { newXVel = xVel * 1 + (mouseX - xPos) * sin(distance/2)/50; newYVel = yVel * 1 + (mouseY - yPos) * sin(distance/2)/50; xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } } void breakApart(){ distMax = 500; xDelta = f1.xPos - xPos; yDelta = f1.yPos - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (distance > distMax-1){ distance = distMax-1; } if (!click){ xd = xPos - initX; yd = yPos - initY; d = sqrt(sq(xd) + sq(yd)); newXVel = xVel * ((distMax - d)/(distMax + 10)) + (initX - xPos) * (d/(distMax + 10)); newYVel = yVel * ((distMax - d)/(distMax + 10)) + (initY - yPos) * (d/(distMax + 10)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } else { newXVel = xVel * (cos((distance)/(distMax)) + cos((distMax - distance)/(distMax))) + (mouseX - xPos) * (sin((distance)/(distMax + 0)) - .5f); newYVel = yVel * (sin((distance)/(distMax)) + sin((distMax - distance)/(distMax))) + (mouseY - yPos) * (sin((distance)/(distMax + 0)) - .5f); xVel -= (xVel - newXVel) * .1f; yVel -= (yVel - newYVel) * .1f; } } void breakApart2(){ distMax = 500; xDelta = f1.xPos - xPos; yDelta = f1.yPos - yPos; distance = sqrt(sq(xDelta) + sq(yDelta)); if (distance > distMax-1){ distance = distMax-1; } if (!click){ xd = xPos - initX; yd = yPos - initY; d = sqrt(sq(xd) + sq(yd)); newXVel = xVel * ((distMax - d)/(distMax + 10)) + (initX - xPos) * (d/(distMax + 10)); newYVel = yVel * ((distMax - d)/(distMax + 10)) + (initY - yPos) * (d/(distMax + 10)); xVel -= (xVel - newXVel) * .2f; yVel -= (yVel - newYVel) * .2f; } else { if (distance < random(10)){ if (mouseX > pmouseX){ xd = mouseX - pmouseX; xVel = random(0,xd); } else if (pmouseX > mouseX){ xd = mouseX - pmouseX; xVel = random(xd,0); } if (mouseY > pmouseY){ yd = mouseY - pmouseY; yVel = random(0,yd); } else if (pmouseY > mouseY){ yd = mouseY - pmouseY; yVel = random(yd,0); } } newXVel = xVel * ((distance/distMax)) + (mouseX - xPos) * ((distance/distMax)/5); newYVel = yVel * ((distance/distMax)) + (mouseY - yPos) * ((distance/distMax)/5); xVel -= (xVel - newXVel) * ((distance/distMax)/5); yVel -= (yVel - newYVel) * ((distance/distMax)/5); } } void borders(){ if ((xPos + xVel) < 0){ xPos = 0; //xVel *= -1; } else if ((xPos + xVel) > width){ xPos = width; //xVel *= -1; } if ((yPos + yVel) < 0){ yPos = 0; //yVel *= -1; } else if ((yPos + yVel) > height){ yPos = height; //yVel *= -1; } } } class Button{ boolean active; int xPos; int yPos; int xDelta; int yDelta; int index; boolean mouseClick = false; Button (int xp, int yp, int xd, int yd, boolean temp, int i){ xPos = xp; yPos = yp; xDelta = xd; yDelta = yd; active = temp; index = i; } void render(){ if (mousePressed && !mouseClick){ if (mouseX > xPos-2 && mouseX < xPos + xDelta + 2 && mouseY > yPos-2 && mouseY < yPos + yDelta +2 && active){ active = false; } else if (mouseX > xPos-2 && mouseX < xPos + xDelta + 2 && mouseY > yPos-2 && mouseY < yPos + yDelta + 2&& !active){ if (index < 100){ selected = index; } active = true; } mouseClick = true; } if (!mousePressed){ mouseClick = false; } if (!active){ fill(222,222,197); noStroke(); rect(xPos+2, yPos+2, xDelta-3, 1); } else { fill(149,56,0); stroke(222,222,197); rect(xPos,yPos,xDelta,yDelta); if (index == 100){ // index for lineToggle stroke(222,222,197); line(xPos, yPos + (yDelta/2),xPos + xDelta, yPos + (yDelta/2)); } } if (mouseX > xPos-2 && mouseX < xPos + xDelta + 2 && mouseY > yPos-2 && mouseY < yPos + yDelta + 2&& !active){ fill(222,222,197); stroke(222,222,197); rect(xPos,yPos,xDelta,yDelta); } } } class Slider{ boolean active; int left; int right; int top; int bottom; int xPos; int yPos; int xDelta; int yDelta; int value; int initX, initY; int index; boolean mouseClick = false; Slider (int xp, int yp, int xd, int yd, boolean temp, int i){ xPos = xp + 260; yPos = yp; xDelta = xd; yDelta = yd; initX = xp; initY = yp; left = xp; right = xp + 255 + xDelta/2; bottom = yp - yDelta/2; top = yp + yDelta + yDelta/2; active = temp; index = i; } void render(){ if (mouseY > bottom && mouseX > (left - 25) && mouseX < (right + 25) && mousePressed){ active = true; xPos -= (xPos - (mouseX - 5)) * .4f; if (xPos < left){ xPos = left; } else if (xPos > right){ xPos = right; } } if (!mousePressed && active){ active = false; } if (mouseY > bottom && mouseX > (left - 25) && mouseX < (right + 25)){ fill(149,56,0); stroke(222,222,197); rect(initX - 1,initY-1,255 + xDelta + xDelta/2 + 2,yDelta + 2); } else { fill(222,222,197,50); stroke(149,56,0); rect(initX - 1,initY-1,255 + xDelta + xDelta/2 + 2,yDelta + 2); } if (active){ fill(222,222,197); stroke(222,222,197); rect(xPos + 1,yPos + 1,xDelta - 2,yDelta - 2); } else { fill(149,56,0); stroke(222,222,197); rect(xPos + 1,yPos + 1,xDelta - 2,yDelta - 2); } value = (int)((xPos - initX)); } } }