setup()
setup() runs once at the start. Here we initialize the canvas, compile shaders, and create UI elements. WebGL shaders run on the GPU for fast, complex visual effects.
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
// Create UI overlay to trigger audio context
startBtn = createButton('ENTER EXPERIENCE');
startBtn.id('start-btn');
startBtn.mousePressed(initAudio);
liquidShader = createShader(vertShader, fragShader);
noStroke();
}
๐ง Subcomponents:
createCanvas(windowWidth, windowHeight, WEBGL);
Creates a full-window WebGL canvas that enables GPU-accelerated shader rendering
startBtn = createButton('ENTER EXPERIENCE');
Creates a button to start the audio context (required by browsers for sound)
liquidShader = createShader(vertShader, fragShader);
Compiles the vertex and fragment shaders into a GPU program
Line by Line:
createCanvas(windowWidth, windowHeight, WEBGL);- Creates a full-window WebGL canvas. WEBGL enables GPU shader rendering instead of 2D canvas drawing
startBtn = createButton('ENTER EXPERIENCE');- Creates an interactive button that users click to start the audio (browsers require user interaction to play sound)
startBtn.id('start-btn');- Assigns an HTML ID to the button so CSS styling can target it
startBtn.mousePressed(initAudio);- Connects the button's click event to the initAudio function, triggering audio setup when clicked
liquidShader = createShader(vertShader, fragShader);- Compiles the vertex shader and fragment shader into a shader program stored in liquidShader
noStroke();- Disables stroke outlines on shapes, so only fills are drawn