le_wuus
YaBB Newbies
Offline
Posts: 19
which for loop for my visual ?
Jun 3rd , 2008, 10:36pm
Hello! and Thanks for your help. I´ve wrote very simple codes which I want to combine with eachother. The first draws an ellipse that floats from the left end of the screen to the right one. Always on the height of the mouse cursor. The gradient tail is just a kind of cheating-visual. You can disable this if you run background within draw. ((Which is at the moment just a comment) //-------------------------------------------------------- float myVariable = 25f; // 1.000045345 float myPosX = 0.6f; void setup() { size(400,200); background(0); frameRate(30); } void draw() { //background(0); myPosX = myPosX + 1f; if(myPosX > 400) { myPosX = 0; } noStroke(); fill(0,myVariable); rect(0,0,400,200); fill(255,255,255); ellipse(myPosX,mouseY,10,10); } //----------------------------------------------------- The second is like a tool for showing that 2 objects are in Proximiti. In this case if the cursor is in the near of the point a line gets drawn between them. //---------------------------------------------------------- void setup (){ size (800,800); noCursor(); } void draw (){ background(0); int pointX = 200; int pointY = 200; fill(255); ellipse (pointX,pointY,10,10); //point in the middle if ((mouseX>pointX-200 & mouseX<pointX+200) && (mouseY>pointY-200 & mouseY<pointY+200)) { stroke(255); line(mouseX,mouseY,pointX,pointY); } noStroke(); fill(255); ellipse(mouseX,mouseY,30,30); } //---------------------------------------------------------- I want to combine theese two codes like that: If my cursor is in proximity to the point (like in the second code) an ellipse floats from the point to the cursor,instead of linking them by a line. So what´s the line in the second code shall be a floating ellipse from object(point) to the cursor. So i have no idea how to do this. First I thought about trying it with an for loop that grows the X and Y coordinates of the floating ellipse untill they reach the coordinates of my cursor... But I´m not sure how to write this in a good way... If anyone (especially PhiLo) has any suggestions I would be very thankfull.