We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › mouse sensitive wave
Page Index Toggle Pages: 1
mouse sensitive wave (Read 375 times)
mouse sensitive wave
Dec 22nd, 2007, 6:20pm
 
Hey there,
i'm bloody new to processing (or programming in general...) ... so i'd be deeply grateful for every hint & kind of help.
My problem is the following: There is a damn high number of little dots i have to animate (depending on mouse movement...), the following excerpt describes every dots y-position. Is there something to get all these lines into one?(i.e. some kind of function describing the first4 lines) (Sorry for asking dumb questions....)

void draw() {
 background(0);
 
 posY1 = posY1 + (mouseY/3-posY1)*speed;
 posY2 = posY2 + (posY1-posY2)*speed;
 posY3 = posY3 + (posY2-posY3)*speed;
 posY4 = posY4 + (posY3-posY4)*speed;

(...) up to posY25 ...

   ellipse(20, posY1, 1, 1);
   ellipse(30, posY2, 1, 1);
   ellipse(40, posY3, 1, 1);
   ellipse(50, posY4, 1, 1);

(...) up to ellipse 25 ...

Thanks for your answers.

Re: mouse sensitive wave
Reply #1 - Dec 22nd, 2007, 7:56pm
 
hi, here are some tips :

- instead of using 25 different variables, you should use arrays :
http://processing.org/reference/Array.html

- instead of repeating the same instruction over and over, use for loops :
http://processing.org/reference/for.html

- finally, instead of writing a = a + x, you can write a += x;

try this :

Code:
float pos[] = new float[25];
pos[0] += (mouseY/3 - pos[0])*speed;
for (int i = 1; i <= 25; i++) {
pos[i] += (pos[i-1] - pos[i])*speed;
}

for (int i = 1; i <= 25; i++) {
ellipse(10 + 10*i, pos[i], 1, 1);
}
Page Index Toggle Pages: 1