We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How do I write this with an array?
//circle
int circleSize = 1;
void setup()
{
size(420, 420);
ellipseMode(CENTER);
}
void draw()
{
circleSize +=1;
background(0);
stroke(250);
fill(0);
// I want to write only one of these lines below, instead of having to write all of those, and get the same result.
ellipse(width/2, height/2, circleSize, circleSize);
ellipse(width/2, height/2, circleSize/2, circleSize/2);
ellipse(width/2, height/2, circleSize/3, circleSize/3);
ellipse(width/2, height/2, circleSize/4, circleSize/4);
ellipse(width/2, height/2, circleSize/5, circleSize/5);
ellipse(width/2, height/2, circleSize/6, circleSize/6);
ellipse(width/2, height/2, circleSize/7, circleSize/7);
ellipse(width/2, height/2, circleSize/8, circleSize/8);
ellipse(width/2, height/2, circleSize/9, circleSize/9);
ellipse(width/2, height/2, circleSize/10, circleSize/10);
ellipse(width/2, height/2, circleSize/11, circleSize/11);
ellipse(width/2, height/2, circleSize/12, circleSize/12);
ellipse(width/2, height/2, circleSize/13, circleSize/13);
ellipse(width/2, height/2, circleSize/14, circleSize/14);
ellipse(width/2, height/2, circleSize/15, circleSize/15);
ellipse(width/2, height/2, circleSize/16, circleSize/16);
ellipse(width/2, height/2, circleSize/17, circleSize/17);
ellipse(width/2, height/2, circleSize/18, circleSize/18);
ellipse(width/2, height/2, circleSize/19, circleSize/19);
ellipse(width/2, height/2, circleSize/20, circleSize/20);
ellipse(width/2, height/2, circleSize/21, circleSize/21);
ellipse(width/2, height/2, circleSize/22, circleSize/22);
ellipse(width/2, height/2, circleSize/23, circleSize/23);
ellipse(width/2, height/2, circleSize/24, circleSize/24);
ellipse(width/2, height/2, circleSize/25, circleSize/25);
ellipse(width/2, height/2, circleSize/26, circleSize/26);
ellipse(width/2, height/2, circleSize/27, circleSize/27);
ellipse(width/2, height/2, circleSize/28, circleSize/28);
ellipse(width/2, height/2, circleSize/29, circleSize/29);
ellipse(width/2, height/2, circleSize/30, circleSize/30);
ellipse(width/2, height/2, circleSize/31, circleSize/31);
}
Answers
You dont need array. Use for loop instead
Thanks!
hello,
small additional remark:
you could use an array but with the use of OOP (object oriented programming - see tutorial on www.processing.org ), if you know it.
It would require a class Ellipse that could store the position and size and color of the Ellipse and a method to draw it.
the Array would the be of type of that class Ellipse
Each slot in the array would hold one object based on that class Ellipse. Each object would contain several properties for one ellipse (position and size and color).
You would fill the array with all ellipses in setup() and display it in draw(). Also use a for-loop to loop over the array.
Greetings, Chrisir
like here....
one for-loop in setup() to define, one for-loop in draw() to display