Created
September 16, 2018 12:19
-
-
Save wonderburg7/219f362eb12b793e5f4701bb71fc3250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float turtleX; | |
float turtleY; | |
float turtleHeading = 0; | |
int numberofshapes = 200; | |
float sides = 3; | |
float angle; | |
float length = 50; | |
void setup() { | |
size(1000, 1000); | |
turtleX = width/2; | |
turtleY = height/2; | |
background(int(random(256)), int(random(256)), int(random(256)), 50); | |
strokeWeight(4); | |
noLoop(); | |
stroke(random(256), random(256), random(256), 255); | |
} | |
void draw() { | |
for (int i = 0; i < numberofshapes; i++) { | |
rotateTurtle(0); | |
float angle = 180/sides; | |
for (int j = 0; j < sides-1; j++) { | |
forward(length); | |
rotateTurtle(angle); | |
} | |
sides++; | |
} | |
save("accidentalspiral1.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; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment