Repetitive code

Good morning everyone,
I just started using processing.
I’m drawing a sketch where I’m going to create 30 little balls.
There’s a way to make them appear in sequence without writing 30 times the same line with the ellipse?

Thanks in advance

1 Like




I encourage you to review the resources available here:

Very Nice! Thank you :slight_smile:


you can also work with arrays (lists) and the for loop over the arrays (see tutorial)

for example first array x[], then y[] then speedX[] and speedY[]

so the properties of ONE ball is in the arrays in the same line each.(one ball properties in each array, in the same line)

  • ball 0 in line 0 of all arrays, ball 1 in line 1 of all arrays
for(int i........) {
    ellipse(x[i], y[i], 7,7);
    x[i] = x[i] + speedX[i];
    y[i] = y[i] + speedY[i];
1 Like

I’ll try it today :slight_smile:
Thank you very much :slight_smile:

1 Like