Why the array doesn't work?

Hello everybody, I'm new in Processing world andin the forum.

I'm doing some exercizes on Array and Loop. In this example I want to draw 5 circles on along the same _y _direction and with a distance (150) between each other on the _x _axis. I used the _for _loop to inizialize, I don't understand why the array doesn't work, there is just one circle, the first(0).

Could you tell me what's wrong with the code?

 //array vuoto di 4
 Cerchio[] cr =new Cerchio[4];

  void setup () {

  size(750, 500);

   //createtheobject and populate it in the array
  float dist;
  float dim=100;
  float y=350;

  for (int i=0; i<cr.length; i++) {
   cr[i]=new Cerchio(150,250, dim);

void draw() {

  //iterate throught th
 for (int i=0; i<cr.length; i++) {


class Cerchio {
 float x;
 float y;
 float dim;

 Cerchio(float _x, float _y, float _dim) {


 void display() {

  for (int i=0; i<cr.length; i++) {
    fill(255, 255);
    ellipse(x, y, dim, dim);


  • edited June 2015 Answer ✓

    In lines 17-18 you're creating all the circles with the same x and y values, so they're all displaying in the same spot. In lines 13-15 you have variables dist and y, but you're not doing anything with them.

  • Perfect, thank you!

Sign In or Register to comment.