video
p5.Capture object
Stores the live webcam feed so we can read its pixel data and apply distortion to it
let video;
mic
p5.AudioIn object
Represents the microphone input device; we call mic.start() to begin capturing audio
let mic;
amplitude
p5.Amplitude object
Analyzes the microphone input and provides the overall volume level via getLevel()
let amplitude;
videoStarted
boolean
Flag that tracks whether the video has fully loaded and is ready to use; prevents crashes in draw() if video isn't ready
let videoStarted = false;
level
number
Stores the current microphone amplitude (volume) as a value between 0.0 and 1.0; used to control distortion intensity
let level = amplitude.getLevel();
timeFactor
number
A sine-wave oscillation that cycles from -1 to 1 over time; used to add subtle pulsing to the distortion independent of sound
let timeFactor = sin(frameCount * 0.05);
morphCenterX
number
The X coordinate of the center of the distortion effect; set to mouseX to follow the cursor
let morphCenterX = mouseX;
morphCenterY
number
The Y coordinate of the center of the distortion effect; set to mouseY to follow the cursor
let morphCenterY = mouseY;
baseRadius
number
The radius in pixels of the circular area affected by the distortion; controlled by mouse X position
let baseRadius = map(mouseX, 0, width, 50, 300);
morphRadius
number
Currently set equal to baseRadius; controls the size of the distortion circle
let morphRadius = baseRadius;
audioMorphFactor
number
Maps the microphone level (0-1) to a distortion intensity (-0.7 to 0.7); negative values pinch, positive values bulge
let audioMorphFactor = map(level, 0, 1, -0.7, 0.7);
timeMorphFactor
number
A subtle oscillation added to the distortion to make it pulse gently even when silent
let timeMorphFactor = map(timeFactor, -1, 1, -0.1, 0.1);
morphFactor
number
The combined distortion intensity; sum of audioMorphFactor and timeMorphFactor
let morphFactor = audioMorphFactor + timeMorphFactor;
dx
number
The horizontal distance from the current pixel to the morph center
let dx = x - morphCenterX;
dy
number
The vertical distance from the current pixel to the morph center
let dy = y - morphCenterY;
dist
number
The straight-line distance from the current pixel to the morph center, calculated using the Pythagorean theorem
let dist = sqrt(dx * dx + dy * dy);
normalizedDist
number
The distance scaled to 0-1 range within the morphing radius; used to create smooth fading effect
let normalizedDist = dist / morphRadius;
displacement
number
How much to move each pixel away from or toward the morph center; uses sine wave to be strongest at center and fade at edges
let displacement = sin(normalizedDist * PI) * morphFactor * morphRadius;
newDist
number
The new distance from the morph center after applying the displacement
let newDist = dist + displacement;
angle
number
The angle in radians from the morph center to the current pixel; used for polar coordinate conversion
let angle = atan2(dy, dx);
newX
number
The X coordinate in the video to sample from after polar coordinate transformation
let newX = morphCenterX + newDist * cos(angle);
newY
number
The Y coordinate in the video to sample from after polar coordinate transformation
let newY = morphCenterY + newDist * sin(angle);