Draw n Chords
Optimised pen path
to reduce pen up travel
But this breaks the angle changing.
See: Chords (variation)
For version with angle changing.
Log in to post a comment.
// Forked from "Chords" by rupertxrussell // https://turtletoy.net/turtle/7883f5ff09 // https://turtletoy.net/turtle/867faa2dad // You can find the Turtle API reference here: https://turtletoy.net/syntax // 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); // 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/ const numLines = 160; // min=0 max=160 step=1 const angle=0; // min=0 max=360 step=1 const turtle = new Turtle(); let d = 0; let d2 = d * d; let r = 80; let r2 = r * r; let chordLength; for(let n=0; n < numLines; n = n + 1){ d = n -80; d2 = d * d; chordLength = 2 * Math.sqrt(r2 - d2); turtle.seth(angle); // this is broken at the moment if(isEven(n)){ turtle.jump(-chordLength /2,-80 + n); turtle.forward(chordLength); // draw line left to right } else { turtle.jump(chordLength /2,-80 + n); turtle.back(chordLength); // draw line right to left } } function isEven(number) { return number % 2 === 0; }