Simple ArrayIndex problem

Hi!, thanks for the answer. Your example is work fine, but if i want to draw a triangle like in my example, the segment from index 2 to index 0 is miss

ing:

float size = 200;
ArrayList<PVector>positions;
float angle = 120;
PVector a;
PVector b;

void setup() {
  size(1000, 1000);
  positions = new ArrayList<PVector>();

  for (int i = 0; i < 3; i++) {
    float x = size*sin(radians(120)*i);
    float y = size*cos(radians(120)*i);      
    positions.add(new PVector(x, y));
  }
}


void draw() {


  translate(500, 500);
  for (int i = 0; i < positions.size()-1; i++) {
    a = positions.get(i);

    b = positions.get(i+1);

    line(a.x, a.y, b.x, b.y);
    ellipse(a.x, a.y, 10, 10);
  }
}
1 Like