Shaded sine curve, with variable density.
Log in to post a comment.
const width = 200; // min=100, max=200, step=1 const height = 60; // min=10, max=100, step=1 const step = .75; // min=0.1, max=3, step=0.05 const maxLengthRatio = 0.9; // min=0.01, max=1, step=.01 const maxLength = maxLengthRatio * height; Canvas.setpenopacity(1); const turtle = new Turtle(); turtle.penup(); let x = -(width / 2); turtle.left(90); // The walk function will be called until it returns false. function walk(i) { turtle.penup(); turtle.goto(x, 0); let length = height * Math.sin((width - x) / 10); let absLength = Math.abs(length); if (absLength > maxLength) { if (length > 0) { turtle.forward(length - maxLength); turtle.pendown(); turtle.forward(maxLength); } else { turtle.forward(-(absLength - maxLength)); turtle.pendown(); turtle.forward(-maxLength); } } else { turtle.pendown(); turtle.forward(length); } x += step; return x < width / 2; }