A work in progress
// Based on the Youtube The Amazing Heptadecagon (17-gon) - Numberphile
// youtu.be/87uo2tprsl8
Log in to post a comment.
// You can find the Turtle API reference here: https://turtletoy.net/syntax // Based on the Youtube The Amazing Heptadecagon (17-gon) - Numberphile // https://youtu.be/87uo2TPrsl8 // Released under the MIT licence // https://mit-license.org/ // you can use this for commercial gain if you like eg you can sell artworks with this image. Canvas.setpenopacity(1); // a simple way to save the current location // of the turtle so we can jump back to a specific position var xPos = []; var yPos = []; // Global code will be evaluated once. const turtle = new Turtle(); turtle.pendown(); const step = 20; //min=0 max=25 step=1 const scale = 80; // //min=0 max=150 step=1 const angle = 45; //min=0 max=360 step=1 const start = 0; //min=0 max=360 step=1 const extent = 7; //min=0 max=36 step=1 const X = 0; //min=-365 max=365 step=1 const Y = 0; //min=-360 max=365 step=1 const A = 0; //min=-100 max=100 step=1 const B = 0; //min=-100 max=100 step=1 const R = 0; //min=0 max=300 step=1 const guidelines = 1; //min=0 max=1 step=1 (No, Yes) const nudge = 0.26; //min=0 max=5 step=0.01 // outer circle if(guidelines == 1){ centeredCircle(0,0, scale,360) } // diameter // https://youtu.be/87uo2TPrsl8?t=252 if(step>=1 && guidelines == 1){ turtle.jump(-scale,0); turtle.pendown(); turtle.setheading(0); turtle.forward(scale *2) } //Perpendicular bisector of the diameter. // https://youtu.be/87uo2TPrsl8?t=263 if(step >= 2 && guidelines == 1){ // lower x drawArc(127, 41, 7, -90 , 0); drawArc(127, 132, 7, 90 , 0); } if(step >= 3 && guidelines == 1){ // upper x drawArc(127, 312, 7, -90 , 0); drawArc(127, 221, 7, 90 , 0); } if(step >= 4 && guidelines == 1){ //Perpendicular bisector of the diameter. turtle.jump(0,98); turtle.pendown(); turtle.setheading(-90); turtle.goto(0,-98) } // divide the lower 1/2 of the bisector into 1/4's // https://youtu.be/87uo2TPrsl8?t=278 if(step >= 5 && guidelines == 1){ turtle.jump(0,scale * 0.25); turtle.setheading(0); turtle.forward(5); turtle.pendown(); turtle.back(10); } if(step >= 6 && guidelines == 1){ turtle.jump(0,scale* 0.5); turtle.setheading(0); turtle.forward(5); turtle.pendown(); turtle.back(10); } if(step >= 7 && guidelines == 1){ turtle.jump(0,scale* 0.75); turtle.setheading(0); turtle.forward(5); turtle.pendown(); turtle.back(10); } // Line from edge of circle through first 1/4 mark on lower bisector // https://youtu.be/87uo2TPrsl8?t=305 if(step >= 8 && guidelines == 1){ turtle.jump(scale,0); turtle.pendown(); turtle.goto(0,scale * 0.25); turtle.setheading(166); turtle.forward(scale * 0.75); } // https://youtu.be/87uo2TPrsl8?t=310 // Arc with radius 1/8 scale if(step >= 9 && guidelines == 1){ drawArc(scale * 0.5, 346, 0, 0 , scale * 0.25); // save starting position for later reference (location 0) xPos.push(turtle.x()); yPos.push(turtle.y()); drawArc(scale * 0.5, 346, 180, 0 , scale * 0.25); } // Draw lins inside 180 degree arc if(step >= 10 && guidelines == 1){ // save the current turtle position for use in step 14 // save starting position for later reference (location 1) xPos.push(turtle.x()); yPos.push(turtle.y()); turtle.goto(0,scale * 0.75); } // Draw lins inside 180 degree arc if(step >= 11 && guidelines == 1){ turtle.goto(0,scale * 0.75); turtle.goto(xPos[0], yPos[0]); } // Draw and store as [2] & [3] the 1/2 and 3/4 ticks on right line inside 180 degree arc // calculate the distance between xPos[0],yPos[0] and (0,scale* 0.75); if(step >= 12 && guidelines == 1){ var distance = Math.sqrt((Math.pow(xPos[0] - 0,2))+(Math.pow(yPos[0] - scale* 0.75,2))); // Use drawArc to find the location of the tick mark // save location and then jump to that location and // draw the tick drawArc(distance * 0.5, 128, 0, xPos[0],yPos[0]); xPos.push(turtle.x()); // xPos[2] yPos.push(turtle.y()); // yPos[2] drawArc(distance * 0.75, 128, 0, xPos[0],yPos[0]); xPos.push(turtle.x()); // xPos[3] yPos.push(turtle.y()); // yPos[3] // draw the tick marks turtle.jump(xPos[2],yPos[2]); turtle.setheading(39); turtle.penup; turtle.forward(4); // consider scaling this tick size turtle.pendown; turtle.back(8) } if(step >= 13 && guidelines == 1){ // draw the tick marks turtle.jump(xPos[3],yPos[3]); turtle.setheading(39); turtle.penup; turtle.forward(4); turtle.pendown; turtle.back(8) } // Draw and store as [4] & [5] the 1/2 and 3/4 ticks on left line inside 180 degree arc // calculate the distance between xPos[1],yPos[1] and (0,scale* 0.75); if(step >= 14 && guidelines == 1){ var distance = pointDistance(xPos[1],yPos[1],0,scale* 0.75); // Use drawArc to find the location of the tick mark // save location and then jump to that location and // draw the tick drawArc(distance * 0.5, 38, 0, xPos[1],yPos[1]); xPos.push(turtle.x()); // xPos[4] yPos.push(turtle.y()); // yPos[4] drawArc(distance * 0.75, 38, 0, xPos[1],yPos[1]); xPos.push(turtle.x()); // xPos[5] yPos.push(turtle.y()); // yPos[5] // draw the tick marks turtle.jump(xPos[4],yPos[4]); turtle.setheading(39 + 90); turtle.penup; turtle.forward(4); // consider scaling this tick size turtle.pendown; turtle.back(8) } if(step >= 15 && guidelines == 1){ // draw the tick marks turtle.jump(xPos[5],yPos[5]); turtle.setheading(39 + 90); turtle.penup; turtle.forward(4); // consider scaling this tick size turtle.pendown; turtle.back(8) } // https://youtu.be/87uo2TPrsl8?t=381 if(step >= 16 && guidelines == 1){ turtle.jump(xPos[3],yPos[3]); turtle.goto(0,scale * 0.25); turtle.setheading(70.46 + 180); // https://www.omnicalculator.com/math/right-triangle-side-angle turtle.forward(scale * 0.4); // consider scaling this size // dist2 = pointDistance(xPos[3],yPos[3],0,scale* 0.25); // console.log("dist2:"); // console.log(dist2); } if(step >= 17 && guidelines == 1){ // draw tick save position turtle.jump(-7.098,0); xPos.push(turtle.x()); // xPos[6] yPos.push(turtle.y()); // yPos[6] turtle.setheading(90); turtle.penup; turtle.forward(4); // consider scaling this tick size turtle.pendown; turtle.back(8) } if(step >= 18 && guidelines == 1){ turtle.jump(xPos[5],yPos[5]); turtle.goto(0,scale * 0.25); turtle.goto(0,scale * 0.25); turtle.setheading(16.68 + 90 + 180); // https://www.omnicalculator.com/math/right-triangle-side-angle turtle.forward(scale * 0.26); // consider scaling this size xPos.push(turtle.x()); // xPos[7] yPos.push(turtle.y()); // yPos[7] // centeredCircle(xPos[7],yPos[7], 2,360) } // https://youtu.be/87uo2TPrsl8?t=403 if(step >= 19 && guidelines == 1){ turtle.jump(40-7.098,0); // half the distance between the outer curcumfrance and the point xPos[6],yPos[6] xPos.push(turtle.x()); // xPos[8] yPos.push(turtle.y()); // yPos[8] turtle.setheading(90); turtle.penup; turtle.pendown; turtle.forward(2); // consider scaling this tick size turtle.back(4) drawArc( 40 + (7.098 /2), 180, 180, 40 - (7.098 /2),0); } // https://youtu.be/87uo2TPrsl8?t=436 if(step >= 20 && guidelines == 1){ console.log("xPos[7]:"); console.log(xPos[7]); console.log("xPos[8]:"); console.log(xPos[8]); drawArc(5.97, 180, 180, 0,0); // https://www.varsitytutors.com/intermediate_geometry-help/how-to-find-the-length-of-a-chord // Chord length using perpendicular distance from the center = 2 × √(r2 − d2). // https://www.cuemath.com/geometry/Chords-of-a-circle/ } if(step >= 21 && guidelines == 1){ centeredCircle(xPos[8],yPos[8], 2,360); } if(step >= 22 && guidelines == 1){ centeredCircle(0,0, 2,360); } if(step >= 23 && guidelines == 1){ centeredCircle(0,0, 2,360); // origin // https://www.varsitytutors.com/intermediate_geometry-help/how-to-find-the-length-of-a-chord // Chord length using perpendicular distance from the center = 2 × √(r2 − d2). // https://www.cuemath.com/geometry/Chords-of-a-circle/ let d = pointDistance(0, 0, xPos[8], 0); let d2 = xPos[8] * xPos[8]; let r = 40 + (7.098 /2); let r2 = r * r; let chordLength = 2 * Math.sqrt(r2 - d2); centeredCircle(0,-chordLength/2, 2,360); centeredCircle(xPos[8],-r, 2,360) // radius centeredCircle(xPos[8]-r,0, 2,360) // radius centeredCircle(xPos[8]+r,0, 2,360) // radius console.log("d:"); console.log(d); console.log("xPos[8]:"); console.log(xPos[8]); } // ------------------------------------------------------------------- function centeredCircle(x,y, radius,ext) { turtle.setheading(0); turtle.jump(x,y-radius); turtle.circle(radius, ext); } // from Rotated Arcs by nftbiker // https://turtletoy.net/turtle/4f7a575cbf function drawArc(radius, startAngle, endAngle, X, Y) { let start_angle = startAngle; let draw_angle = endAngle; let start = { x: Math.cos(start_angle*Math.PI/180)*radius, y: Math.sin(start_angle*Math.PI/180)*radius } turtle.jump(start.x + X, start.y + Y) for (i=start_angle; i<=start_angle+draw_angle; i+=1) { let x = Math.cos(i*Math.PI/180)*radius let y = Math.sin(i*Math.PI/180)*radius turtle.goto(x + X, y + Y) } } function pointDistance(x1, y1, x2, y2) { return Math.hypot(x1 - x2, y1 - y2); }