The golden ratio illustrated
youtube.com/watch?v=sj8sg8qnjog
Log in to post a comment.
let r = .7; //min=.5, max=4, step=.1 let margin = .2; //min=0, max=1, step=.1 let maxR = 90; //min=20, max=150, step=10 let growf = 1.6; //min=0, max=20, step=.5 let maxSR = 7; //min=1, max=20, step=.5 let opacity = .8; //min=.1, max=1, step=.1 let fillCircles = 1; //min=0, max=1, step=1 Canvas.setpenopacity(.5); const turtle = new Turtle(); turtle.setheading(90); var gr = (1+Math.sqrt(5)) / 2; var grRot = (gr - 1) * 2 * Math.PI; var circles = []; var rotation = 0; function drawCircle(x, y, r) { for(var i = (fillCircles == 1? 0: r); i <= r; i+=.2) { turtle.jump(x + i, y); turtle.circle(i); } circles.push([x, y, r]); } function hasIntersections(x, y, r) { for(var i = 0; i < circles.length; i++) { if(Math.pow(x - circles[i][0], 2) + Math.pow(y - circles[i][1], 2) < Math.pow(r + circles[i][2] + margin, 2)) { return true; } } return false; } function walk(i) { rotation += grRot; for(var testR = 0; testR < maxR; testR += .1) { var x = testR * Math.cos(rotation); var y = testR * Math.sin(rotation); var useR = Math.min(maxSR, r + (growf * testR / 100)) if(!hasIntersections(x, y, useR, circles)) { drawCircle(x, y, useR); return true; } } return false; }