setup()
setup() runs once at sketch start. Here we initialize the WebGL context, compile shaders, and create UI elements. The audio context is not started here because browsers require a user gesture (like a click) to begin audio playback.
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
// Create UI overlay to trigger audio context
startBtn = createButton('ENTER EXPERIENCE');
startBtn.id('start-btn');
startBtn.mousePressed(initAudio);
// Create instructions text (hidden initially)
instructions = createDiv('MOVE MOUSE / TOUCH TO SHAPE THE METAL & MODULATE THE BEAT');
instructions.id('instructions');
// Create creator credit text
creditText = createDiv('MADE BY CORBUN');
creditText.id('credit');
liquidShader = createShader(vertShader, fragShader);
noStroke();
}
Line-by-line explanation (7 lines)
createCanvas(windowWidth, windowHeight, WEBGL);- Creates a fullscreen WebGL canvas—the WEBGL parameter enables shader rendering instead of the default 2D canvas.
startBtn = createButton('ENTER EXPERIENCE');- Creates an interactive button element that will be centered on screen via CSS styling.
startBtn.mousePressed(initAudio);- Attaches the initAudio() function as a callback—when clicked, it starts the Tone.js audio context and synth.
instructions = createDiv('MOVE MOUSE / TOUCH TO SHAPE THE METAL & MODULATE THE BEAT');- Creates a hidden instructional text element that fades in after audio starts.
creditText = createDiv('MADE BY CORBUN');- Creates a small credit text positioned via CSS in the top-right corner.
liquidShader = createShader(vertShader, fragShader);- Compiles the vertex and fragment shader strings into a GPU program that will render the sphere each frame.
noStroke();- Disables stroke outlines on shapes, so the rectangle drawn in draw() appears as a solid filled quad.