We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
I am spending some time exploring how to use the Ani library for simple animation. One exercise I am doing is to move the different circles on the screen at different speed when the user scroll the mouse.
Below is the code I have. but for some reason nothing happens when I scroll the mouse. Can someone help please?
Thanks, Frank
import de.looksgood.ani.*;
import de.looksgood.ani.easing.*;
int num = 20;
int[] x = new int[num];
int[] y = new int[num];
int[] r = new int[num];
int dist = 0;
void setup() {
size(600, 900);
background(50);
noStroke();
fill(190);
for(int i = 0; i < num; i++) {
x[i] = int(random(40, 560));
y[i] = int(random(0, 900));
r[i] = int(random(15, 50));
println("( " + x[i] + ", " + y[i] + ", " + r[i] + " )");
ellipse(x[i], y[i], r[i]*2, r[i]*2);
}
Ani.init(this);
}
void draw() {
background(50);
for(int i = 0; i < num; i++) {
ellipse(x[i], y[i], r[i]*2, r[i]*2);
}
}
void mouseWheel(MouseEvent event) {
float e = event.getAmount();
//println(e);
for(int i = 0; i < num; i++) {
int dist = int(random(1, 20) * e);
Ani.to(this, 1.5, "y[i]", y[i] + dist);
}
}
Answers
Anybody could help?
Hi Frank,
it seems to work when you make a class for your balls:
I suppose Ani may have trouble accessing objects inside arrays? I'm not sure though.
hope this helps! ak
I took the time to study this Ani library today. Here's my tweaked version based on my discoveries: o->
And now another mix based on PVector[] & Ani[] arrays instead of Ball[]: >:/
AFAIK currently, the String parameter must be a field name from the Object parameter. (~~)
However, a Java's array object only got a
public
length field! [..]Hi akiersky and GoToLoop, thank you for your reply. I didn't realize that the new forum does not have email notification as more and didn't realized your reply until today.
Yes, Ak, your version totally works. And I am studying GoToLoop's tweaks too. Thank you so much for your time to help!
-Frank