Skip to content

Instantly share code, notes, and snippets.

@georgesb
Last active May 3, 2020 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgesb/69c2f1c619a2fc47727c85daabb19079 to your computer and use it in GitHub Desktop.
Save georgesb/69c2f1c619a2fc47727c85daabb19079 to your computer and use it in GitHub Desktop.
Golden Spiral
<script src="https://cdn.jsdelivr.net/npm/p5"></script>
<script src="script.js"></script>
function setup() {
let x, y;
let fibonacci = [1, 1, 2, 3, 5, 8, 13, 21];
createCanvas(650, 450);
translate(40, 40);
for (let i = 7; i >= 0; i--) {
x = fibonacci[i] * 17;
y = x;
stroke('red');
rect(0, 0, x, y);
push();
translate(x, 0);
stroke('black');
arc(0, 0, x * 2, y * 2, radians(90), radians(180));
pop();
translate(x, y);
rotate(radians(270));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment