SineSurf
This system places a series of lines along an invisible sine wave. As the wave flows across the screen, the lines shrink as they reach the peaks and grow as they cross the center. At the same time, each line is slightly tilted compared to the one before it, creating a "twisting" effect that makes a flat 2D wave look like a 3D ribbon spinning in space.
Log in to post a comment.
// 1. Frequency: Number of full wave cycles across the screen
const frequency = 2; // min=0.5, max=10, step=0.1
// 2. Successive Angle Offset: Rotation per line
const angleOffset = 2; // min=0, max=20, step=0.1
// 3. Line Count: Total number of lines to draw
const lineCount = 100; // min=10, max=400, step=1
const turtle = new Turtle();
const amplitude = 40; // Height of the wave
const maxLength = 230; // Max length of the lines
function walk(i) {
// Determine progress from 0.0 to 1.0
const ratio = i / (lineCount - 1);
// Map X from -100 (left) to 100 (right)
const x = ratio * 200 - 100;
// Calculate Sine based on ratio and frequency
// (ratio * 2 * PI) = 1 full cycle. Multiplying by frequency repeats it.
const waveValue = Math.sin(ratio * frequency * Math.PI * 2);
const y = waveValue * amplitude;
// Inverse length: Longest at y=0, shortest at peaks
const currentLength = maxLength * (1 - Math.abs(waveValue));
// Position the turtle at the wave locus
turtle.penup();
turtle.goto(x, y);
// Set heading: Vertical (90) + cumulative twist
turtle.seth(90 + (i * angleOffset));
// Draw the line centered on the point
turtle.pendown();
turtle.forward(currentLength / 2);
turtle.backward(currentLength);
// Return true to keep walking until we hit lineCount
return i < lineCount - 1;
}