Problem while I learning Arrray

This Is Working Version of What I learn.

float[] x = new float[5];

void setup() {
  size(1080,720);
  noStroke();
}

void draw() {
  background(0);
  x[0] += 0.5; 
  x[1] += 0.5;
  x[2] += 0.5;
  x[3] += 0.5;
  x[4] += 0.5;
  arc(x[0], 20, 20, 20, 0.52, 5.76);
  arc(x[1], 40, 20, 20, 0.52, 5.76);
  arc(x[2], 60, 20, 20, 0.52, 5.76);
  arc(x[3], 80, 20, 20, 0.52, 5.76);
  arc(x[4], 100, 20, 20, 0.52, 5.76);
}

It’s not working version of What I learn

float[] x = {-10,10,35,18,30};
//[{
//NO new float{}
  
void setup() {
  size(1080,720);
  noStroke();
}

void draw() {
  background(0);
  x[-10] += 0.5; //??
  x[10] += 0.5;
  x[35] += 0.5;
  x[18] += 0.5;
  x[30] += 0.5;
  arc(x[-10], 20, 20, 20, 0.52, 5.76); //??
  arc(x[10], 40, 20, 20, 0.52, 5.76);
  arc(x[35], 60, 20, 20, 0.52, 5.76);
  arc(x[18], 80, 20, 20, 0.52, 5.76);
  arc(x[30], 100, 20, 20, 0.52, 5.76);
}

I was realize working version of my code doesn’t showing what I want excatly.
I was excepting bit spread arcs. but, processing shows message that my code have
problem with [-10]…

How can I fix it??

You are using the values instead of the arrays’ indices :wink:

  x[0] += 0.5; //??
  x[1] += 0.5;
  x[2] += 0.5;
  x[3] += 0.5;
  x[4] += 0.5;
  arc(x[0], 20, 20, 20, 0.52, 5.76); //??
  arc(x[1], 40, 20, 20, 0.52, 5.76);
  arc(x[2], 60, 20, 20, 0.52, 5.76);
  arc(x[3], 80, 20, 20, 0.52, 5.76);
  arc(x[4], 100, 20, 20, 0.52, 5.76);
2 Likes
static final float SPD = .5;
static final int PACMEN = 5, FPS = 60, DIM = 20;
final float[] x = new float[PACMEN];

void setup() {
  size(1200, 120);
  frameRate(FPS);
  noStroke();
}

void draw() {
  background(0);

  for (int i = 0; i < PACMEN; ++i)
    arc(x[i] += SPD, i*DIM + DIM, DIM, DIM, .52, 5.76);
}
3 Likes

Thanks a lot @cumulus! I didn’t know how easy and simple to solve this!

Thanks @GotoLoop! this is really amazing too!! thanks!