/* David "Boone" Zavik tentacle towers that follow the moving ball. When mouse is pressed the colors change and the ball goes to mouseX and mouseY. Add: -a counter for the amount of times that the tower touches the ball -create a change from this effect -create a distance measure from the tower to ball so that if ball is far away then tower will smoothly, organically fall to the wall -possibly add a growing function to allow the tower to extend further after it is able to touch the ball "X" times -then after it finishes that touch it will restart its count function -add a distance that will change color based off of how far away it is. Possibly randomly -possibly create more motion when the tower is extended waiting for the ball -control the sinusodial wave that occurs as the ball leaves it. -add another keyboard function to create more interactivity and add more complexity to the design -create mouse moving function in order to sling ball Using Reach 3 from example as a jump point; */ //-------TOWER 1 = bottom middle int tower1_numSegments = 5; float[] tower1_x = new float[tower1_numSegments]; float[] tower1_y = new float[tower1_numSegments]; float[] tower1_angle = new float[tower1_numSegments]; float tower1_segLength = 30; //-------TOWER 2 = top middle int tower2_numSegments = 5; float[] tower2_x = new float[tower2_numSegments]; float[] tower2_y = new float[tower2_numSegments]; float[] tower2_angle = new float[tower2_numSegments]; float tower2_segLength = 30; //-------TOWER 3 = bottom left int tower3_numSegments = 10; float[] tower3_x = new float[tower3_numSegments]; float[] tower3_y = new float[tower3_numSegments]; float[] tower3_angle = new float[tower3_numSegments]; float tower3_segLength = 30; //-------TOWER 4 = bottom right int tower4_numSegments = 10; float[] tower4_x = new float[tower4_numSegments]; float[] tower4_y = new float[tower4_numSegments]; float[] tower4_angle = new float[tower4_numSegments]; float tower4_segLength = 30; //-------TOWER 5 = top left int tower5_numSegments = 10; float[] tower5_x = new float[tower5_numSegments]; float[] tower5_y = new float[tower5_numSegments]; float[] tower5_angle = new float[tower5_numSegments]; float tower5_segLength = 30; //-------TOWER 6 = top right int tower6_numSegments = 10; float[] tower6_x = new float[tower6_numSegments]; float[] tower6_y = new float[tower6_numSegments]; float[] tower6_angle = new float[tower6_numSegments]; float tower6_segLength = 30; //-------TOWER 7 = middle left int tower7_numSegments = 8; float[] tower7_x = new float[tower7_numSegments]; float[] tower7_y = new float[tower7_numSegments]; float[] tower7_angle = new float[tower7_numSegments]; float tower7_segLength = 30; //-------TOWER 8 = middle right int tower8_numSegments = 8; float[] tower8_x = new float[tower8_numSegments]; float[] tower8_y = new float[tower8_numSegments]; float[] tower8_angle = new float[tower8_numSegments]; float tower8_segLength = 30; float targetX, targetY; float ballX = random(50, 900); float ballY = random(50, 400); int ballXDirection = 1; int ballYDirection = -1; PImage ball; // THIS IS THE FLY IMAGE float distanceX = 0; float distanceY = 0; float distanceAngle = 0; /////////////////////////////////////////////////////// /***********************************************************************_VOID SETUP_*/ ////////////////////////////////////////////////////// void setup() { size(1000, 500); smooth(); ball = loadImage("fly.jpg"); //TOWER 1 tower1_x[tower1_x.length-1] = width/2; // Set reach tower position X tower1_y[tower1_y.length-1] = height; // Set reach tower position Y //TOWER 2 tower2_x[tower2_x.length-1] = width/2; tower2_y[tower2_y.length-1] = 0; //TOWER 3 tower3_x[tower3_x.length-1] = 0; tower3_y[tower3_y.length-1] = height; //TOWER 4 tower4_x[tower4_x.length-1] = width; tower4_y[tower4_y.length-1] = height; //TOWER 5 tower5_x[tower5_x.length-1] = 0; tower5_y[tower5_y.length-1] = 0; //TOWER 6 tower6_x[tower6_x.length-1] = width; tower6_y[tower6_y.length-1] = 0; //TOWER 7 tower7_x[tower7_x.length-1] = 0; tower7_y[tower7_y.length-1] = height/2; //TOWER 8 tower8_x[tower8_x.length-1] = width; tower8_y[tower8_y.length-1] = height/2; } /////////////////////////////////////////////////////// /************************************************************************_VOID DRAW_*/ ////////////////////////////////////////////////////// void draw() { background(255); image(ball, ballX, ballY, 70, 70); //rect(0, 330, 50, 50); ballX = ballX + 1.0 * ballXDirection; ballY = ballY + 0.8 * ballYDirection; ///////////////////////////////////////////////////////////////// BALL "IF" CONDITIONS if(ballX > width-70 || ballX < 0) { ballXDirection *= -1; } if(ballY > height-70 || ballY < 0) { ballYDirection *= -1; } /////////////////////////////////////////////////////////////////////IF mousePRESSED if (mousePressed == true) { //ballX = mouseX + 35; //ballY = mouseY + 35; filter(INVERT); //fill(0, 0, 255, 100); stroke(255, 0, 0); ////////////////////////////////////////////////////////////mousePressed ball Shake for(int i=0; i<8; i++) { ballX = (mouseX - 35) + random(1, 5); ballY = (mouseY - 35) + random(1, 5); } } if( mousePressed == false) { ballX = ballX + 1.0 * ballXDirection; ballY = ballY + 0.8 * ballYDirection; //fill(200, 255, 255, 100); stroke(220, 55, 150); } //ellipse(ballX, ballY, 80, 20); ////////////////////////////////////////////////////////////////////////// TOWER 1 reachSegment(1, 0, ballX, ballY); //MAKE SURE TO DEFINE numSEGMENTS for(int i=1; i=1; i--) { positionSegment(1, i, i-1); } for(int i=0; i=1; i--) { positionSegment(2, i, i-1); } for(int i=0; i=1; i--) { positionSegment(3, i, i-1); } for(int i=0; i=1; i--) { positionSegment(4, i, i-1); } for(int i=0; i=1; i--) { positionSegment(5, i, i-1); } for(int i=0; i=1; i--) { positionSegment(6, i, i-1); } for(int i=0; i=1; i--) { positionSegment(7, i, i-1); } for(int i=0; i=1; i--) { positionSegment(8, i, i-1); } for(int i=0; i= 700) { tower1_angle[i] = 0; } if( yin <= 200 ) { tower1_angle[i] = 0; } } } if( towerNum == 2) { float dx = xin - tower2_x[i] + 35; float dy = yin - tower2_y[i] + 35; tower2_angle[i] = atan2(dy, dx); targetX = xin - cos(tower2_angle[i]) * tower2_segLength; targetY = yin - sin(tower2_angle[i]) * tower2_segLength; distanceX = targetX - ballX; distanceY = targetY - ballY; distanceAngle = tower2_angle[i]; //println(yin); if( mousePressed == false) { if( xin <= 280 || xin >= 700) { tower2_angle[i] = 0; } if( yin >= 220 ) { tower2_angle[i] = 0; } } } if( towerNum == 3) { float dx = xin - tower3_x[i] + 35; float dy = yin - tower3_y[i] + 35; tower3_angle[i] = atan2(dy, dx); targetX = xin - cos(tower3_angle[i]) * tower3_segLength; targetY = yin - sin(tower3_angle[i]) * tower3_segLength; distanceX = targetX - ballX; distanceY = targetY - ballY; distanceAngle = tower3_angle[i]; //println(yin); if( mousePressed == false) { if( xin >= 380) { tower3_angle[i] = 0; } if( yin <= 200 ) { tower3_angle[i] = 0; } } } if( towerNum == 4) { float dx = xin - tower4_x[i] + 35; float dy = yin - tower4_y[i] + 35; tower4_angle[i] = atan2(dy, dx); targetX = xin - cos(tower4_angle[i]) * tower4_segLength; targetY = yin - sin(tower4_angle[i]) * tower4_segLength; distanceX = targetX - ballX; distanceY = targetY - ballY; distanceAngle = tower4_angle[i]; //println(xin); if( mousePressed == false) { if( xin <= 520) { tower4_angle[i] = 3.13; } if( yin <= 200 ) { tower4_angle[i] = 3.13; } } } if( towerNum == 5) { float dx = xin - tower5_x[i] + 35; float dy = yin - tower5_y[i] + 35; tower5_angle[i] = atan2(dy, dx); targetX = xin - cos(tower5_angle[i]) * tower5_segLength; targetY = yin - sin(tower5_angle[i]) * tower5_segLength; distanceX = targetX - ballX; distanceY = targetY - ballY; distanceAngle = tower5_angle[i]; //println(yin); if( mousePressed == false) { if( xin >= 380) { tower5_angle[i] = 1.57; } if( yin >= 320 ) { tower5_angle[i] = 1.57; } } } if( towerNum == 6) { float dx = xin - tower6_x[i] + 35; float dy = yin - tower6_y[i] + 35; tower6_angle[i] = atan2(dy, dx); targetX = xin - cos(tower6_angle[i]) * tower6_segLength; targetY = yin - sin(tower6_angle[i]) * tower6_segLength; distanceX = targetX - ballX; distanceY = targetY - ballY; distanceAngle = tower6_angle[i]; //println(yin); if( mousePressed == false) { if( xin <= 520 ) { tower6_angle[i] = 1.57; } if( yin >= 220 ) { tower6_angle[i] = 1.57; } } } if( towerNum == 7) { float dx = xin - tower7_x[i] + 35; float dy = yin - tower7_y[i] + 35; tower7_angle[i] = atan2(dy, dx); targetX = xin - cos(tower7_angle[i]) * tower7_segLength; targetY = yin - sin(tower7_angle[i]) * tower7_segLength; distanceX = targetX - ballX; distanceY = targetY - ballY; distanceAngle = tower7_angle[i]; //println(yin); if( mousePressed == false) { if( xin >= 380) { tower7_angle[i] = 1.57; } } } if( towerNum == 8) { float dx = xin - tower8_x[i] + 35; float dy = yin - tower8_y[i] + 35; tower8_angle[i] = atan2(dy, dx); targetX = xin - cos(tower8_angle[i]) * tower8_segLength; targetY = yin - sin(tower8_angle[i]) * tower8_segLength; distanceX = targetX - ballX; distanceY = targetY - ballY; distanceAngle = tower8_angle[i]; //println(yin); if( mousePressed == false) { if( xin <= 520) { tower8_angle[i] = 1.57; } } } else { towerNum = 0; i = 0; xin = 0; yin = 0; } } //////////////////////////////////////////////////////////////////////////_____segment void segment(int towerNum, float x, float y, float a, float sw) { if( towerNum == 1) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower1_segLength, 0); popMatrix(); } if( towerNum == 2) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower2_segLength, 0); popMatrix(); } if( towerNum == 3) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower3_segLength, 0); popMatrix(); } if( towerNum == 4) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower4_segLength, 0); popMatrix(); } if( towerNum == 5) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower5_segLength, 0); popMatrix(); } if( towerNum == 6) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower6_segLength, 0); popMatrix(); } if( towerNum == 7) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower7_segLength, 0); popMatrix(); } if( towerNum == 8) { strokeWeight(30); pushMatrix(); translate(x, y); rotate(a); line(0, 0, tower8_segLength, 0); popMatrix(); } else { towerNum = 0; x = 0; y = 0; a = 0; sw = 0; } }