wonderburg7
9/16/2018 - 12:29 PM

Squares galore using turtle.pde

float turtleX;
float turtleY;
float turtleHeading = 0;
int numberofsquares = 2000;

void setup() {
  size(1000, 1000);
  turtleX = width/2;
  turtleY = height/2;
  background(64);
  strokeWeight(4);
  noLoop();
}

void draw() {
  for (int i = 0; i < numberofsquares; i++) {
  stroke(random(256), random(256), random(256), 255);
  
  rotateTurtle(random(360));
  float length = random(0, 500);
  
  forward(length);
  rotateTurtle(90);
  
  forward(length);
  rotateTurtle(90);
  
  forward(length);
  rotateTurtle(90);
  
  forward(length);
  }
  save("multisquares1.png");
}

void forward(float amount) {
  
  float newX = turtleX + cos(radians(turtleHeading)) * amount;
  float newY = turtleY + sin(radians(turtleHeading)) * amount;

  line(turtleX, turtleY, newX, newY);
  fill(0);
  
  turtleX = newX;
  turtleY = newY;
}

void rotateTurtle(float degrees) {
  turtleHeading += degrees;
}