home/ atoms/ sine-wave-visual-curve

Mapping sin(angle) to canvas y-coordinates draws a smooth periodic wave

The sine function oscillates between -1 and +1 as angle progresses. To draw a visible sine wave in Processing: iterate x across the canvas, convert a counter to radians, compute y = centerY + sin(radians(angle)) * amplitude, and connect successive points with line(). The amplitude scales the peak-to-trough height in pixels; the rate at which angle advances controls the frequency (how many cycles cross the canvas). A useful variant is sin^3: pow(sin(rad), 3) preserves the wave’s zero-crossings but sharpens the peaks, giving the curve a characteristic ‘squared’ feel. Combining a sine envelope with noise (NoiseSine) produces a wave that breathes unevenly across the canvas.

Examples

ch3_3_2_1_SineCurve.pde: y = height/2 + (sin(rad) * 40). ch3_3_2_2_CubeSine.pde: y = height/2 + (pow(sin(rad), 3) * 30). ch3_3_2_3_NoiseSine.pde: y = height/2 + (pow(sin(rad), 3) * noise(rad*2) * 30).

Assessment

Predict the visual difference between a plain sine wave and a sin^3 wave of the same amplitude. Then explain what the noise multiplier in NoiseSine does to the wave’s envelope.

“y = height/2 + (sin(rad) * 40);”
corpus · generative-art-code-examples-josephfiola-genart-processing-p · chunk 27
“y = height/2 + (pow(sin(rad), 3) * 30);”
corpus · generative-art-code-examples-josephfiola-genart-processing-p · chunk 28
“y = height/2 + (pow(sin(rad), 3) * noise(rad*2) * 30);”
corpus · generative-art-code-examples-josephfiola-genart-processing-p · chunk 29