setup()
setup() runs once at the start and is where you initialize the canvas, load assets, and set up initial game state. The color palette defined here controls the visual 'temperature' feedback throughout the game.
function setup() {
createCanvas(windowWidth, windowHeight);
buildStaticLevel();
pathAnalyzer = new PathAnalyzer(platforms);
resetGame();
// Color palette
bgCool = color(4, 6, 18);
bgHot = color(120, 10, 40);
glitchCold = color(0, 255, 200);
glitchHot = color(255, 40, 120);
playerCold = color(60, 200, 255);
playerHot = color(255, 255, 255);
uiCold = color(220);
uiHot = color(255, 220, 70);
laserCold = color(120, 200, 255);
laserHot = color(255, 80, 80);
sawCold = color(230);
sawHot = color(255, 200, 120);
textFont('monospace');
textSize(14);
}
Line-by-line explanation (9 lines)
🔧 Subcomponents:
bgCool = color(4, 6, 18);
Establishes the cold/hot color pairs used throughout the sketch to interpolate visuals based on aiConfidence
createCanvas(windowWidth, windowHeight);- Creates a full-screen canvas that fills the browser window
buildStaticLevel();- Calls the level-building function to populate the platforms and static hazards arrays
pathAnalyzer = new PathAnalyzer(platforms);- Creates the AI object that will track your paths and generate obstacles based on learned routes
resetGame();- Initializes the player, clears the current run's recorded path, and generates the first set of hazards
bgCool = color(4, 6, 18);- Deep dark blue—the background color when AI confidence is zero (you're unpredictable)
bgHot = color(120, 10, 40);- Deep burgundy—the background color when AI confidence is one (you're following the learned path perfectly)
playerCold = color(60, 200, 255);- Cyan color for the player when confidence is low
playerHot = color(255, 255, 255);- White color for the player when confidence is high, creating a glowing effect
textFont('monospace');- Sets the UI text to monospace, reinforcing the digital glitch-art aesthetic