Basic drawing of circles with segments of lines doesn't function - must be really basic


Tthis sketch doesn’t draw circles using segments of lines as it is expected to do. The positions do not evolve and I don’t understand why. It must be as plain as the nose on your face but I can’t see it…


float diameterX, diameterY, startX, startY, endX, endY;
int step;

void setup() {
  size(1000, 1000);
  step = 99;

void draw() {
  if (step > 99) {
    step = 0;
    diameterX = random(width/2)+width/2;
    diameterY = random(height/2)+height/2;
    startX = sin(0)*diameterX/2; // or sin(0) or 0
    startY = cos(0)*diameterY/2;
    println("diameterx: "+diameterX+" / diametery: "+diameterY);  
  endX = sin((step+1)/100 * TWO_PI)*diameterX/2;
  endY = cos((step+1)/100 * TWO_PI)*diameterY/2;
  println("step: "+step+" / startX: "+startX+" / startY: "+startY+" / endX: "+endX+" / endY: "+endY);
  line((int)(startX+width/2), (int)(startY+height/2), (int)(endX+width/2), (int)(endY+height/2));
  startX = endX;
  startY = endY;

Integer division returns an integer.
(step+1)/100 will be zero when step is less than 99.

Make “step” a float instead of an integer. Or multiply by the float TWO_PI before doing the /100.

1 Like

Of course! Thanks a lot @scudly !