Task 3 of 4
How do you plot y = f(x) when no thread can draw a line? Flip the
question: every pixel decides for itself whether it lies on the curve. Thread
(x, y) evaluates the function at its own x, measures the vertical distance to
that height, and paints amber if the distance is under 2 pixels — background otherwise.
This per-pixel "how far am I from the shape?" question is one of the great tricks of computer graphics. Today it draws a sine wave; the same idea, pushed further, draws the fractals of Escape-Time Fractals and the ray-marched scenes of Ray-Marched Metaballs.
y = 64 + 40 · sin(2πx / 128) as a thin amber curve on the dark background.64 + 40 * Math.sin(x * 2 * Math.PI / 128)Math.abs(this.thread.y - curveY) < 2The distance test and both colors are already written. Only
curveY is wrong: it's a constant, so you get a flat line instead of a
wave.
const curveY = 64 + 40 * Math.sin(x * 2 * Math.PI / 128);
Math.sin and Math.PI both work inside kernels.
f(x) per fragment, exactly
as here.
This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.