I am trying to draw a lot of drops falling across the screen, from diferents heights. I can draw a loop with many drops and I can animate one drop, but I can not mix both could you please help me?
// state
float circleY = random(-100,0);
float circleX = random(width);
void setup() {
size(500, 500);
background(0);
}
void draw() {
noStroke();
for (int i=0; i<500; i+=50){
// draw current frame based on state
ellipse(circleX, circleY, 50, 50);
// modify state
circleY = circleY + 1;
}
}
thank you so much! I think that array for multiple drops is working, but array for colors is not, because it is only using brown. Could you please help me with that? And could you please tell me how increase speed of animation? In addition, do you know why the right corner is empty? Thanks!
I understand one array has 25 elements and the other just 6, so I guess that is the problem. But this array with colors is just something new for me, so I don’t know how to improve it. Sorry for the persistence with this, do you have any specific tutorial for that?
Yeah! Now I have 4 colours, as I wanted. But actually I wanted many purples, many pinks, many blues and many greens, so my final code has intervals on colours. How could I get that?
float[] circleY = new float[55];
color[] cols = {
color( random(102,153),random(0,102),255 ), color(random(204,255),random(0,204),255),
color(random(0,102),random(0,255),255), color(random(0,204), random(153,255),0)
};
int k=0;
void setup() {
size(500,500);
background(0);
for (int i = 0; i < circleY.length; i++) {
circleY[i] = random(-500,0);
}
}
void draw() {
noStroke();
for (int i = 0; i < circleY.length; i++) {
float circleX = width * i / circleY.length;
ellipse(circleX, circleY[i], 25, 25);
fill(cols[i%4]);
circleY[i]++;
if (circleY[i] > height) {
circleY[i] = 0;
}
}
}
Instead of using a predefined set of colors you can make a longer array and fill it with random colors in setup
(Then don’t use % anymore)
Advanced idea
additionally you can use the set you are having in your old version and choose a random color from it and then change this using random (add a value) or lerpColor