annemarie
YaBB Newbies
Offline
Posts: 43
forloop and individual settings ...
Jan 23rd , 2006, 4:46pm
Hi, A beginners question: I am trying to use a for-loop to create multiple shapes that attract or repel differently to the magnetic shape that follows the mouse. Each shape should be attracted with various ranges, and each shape should be repelled into a certain distance, so that it doesn't slide outside the screen area. import processing.opengl.*; float wX; float wY; float delay = 60.0; void setup(){ size(300, 300, OPENGL); fill(200, 0, 100); noStroke(); framerate(30); //smooth(); } void draw(){ background(0); if(mousePressed==true) { // attract float dx = mouseX - wX; if(abs(dx) > 20) { wX = wX + dx/delay; } float dy = mouseY - wY; if(abs(dy) > 20) { // this number should vary for each shape when it is //repeated by the forloop wY = wY + dy/delay; } } else { // repel float dx = mouseX + wX; if(abs(dx) > 20) { wX = wX - dx/delay; // it should only repel untill a certain number that //varies for each shape } float dy = mouseY + wY; if(abs(dy) > 20) { wY = wY - dy*1/delay; } } pushMatrix(); translate(wX, wY); beginShape(POLYGON); curveVertex(200, 200); curveVertex(84, 91); curveVertex(68, 19); curveVertex(21, 17); curveVertex(32, 100); curveVertex(32, 100); endShape(); popMatrix(); // 'magnetic shape' pushMatrix(); translate(mouseX, mouseY); beginShape(POLYGON); curveVertex(200, 200); curveVertex(84, 91); curveVertex(68, 19); curveVertex(21, 17); curveVertex(32, 100); curveVertex(32, 100); endShape(); point(mouseX+50, mouseY+50); popMatrix(); }