preload()
preload() is special in p5.js—it runs BEFORE setup(), allowing you to load fonts, images, and sounds that setup() and draw() will need. This sketch loads fonts from the internet (Fontsource CDN) instead of keeping them locally, which makes the sketch smaller.
function preload() {
// Load Fonts from Fontsource CDN
// Montserrat Bold for main text and countdown
montserratBold = loadFont('https://unpkg.com/@fontsource/montserrat@latest/files/montserrat-latin-700-normal.woff');
// Roboto Regular for ticker tape
robotoRegular = loadFont('https://unpkg.com/@fontsource/roboto@latest/files/roboto-latin-400-normal.woff');
ballIcons = [
// 0: Blue Ghost lunar lander silhouette
(size) => {
fill(silver);
noStroke();
triangle(-size * 0.4, size * 0.2, size * 0.4, size * 0.2, 0, -size * 0.4);
ellipse(0, size * 0.1, size * 0.6, size * 0.3);
rectMode(CENTER);
rect(0, size * 0.4, size * 0.2, size * 0.2);
},
// ... (7 more icon functions)
];
bitcoinIcon = (size) => {
fill(gold);
noStroke();
rectMode(CENTER);
rect(0, 0, size, size);
fill(0);
textAlign(CENTER, CENTER);
textFont(montserratBold);
textSize(size * 0.8);
text('₿', 0, 0);
};
musicNoteIcon = (size) => {
fill(255);
noStroke();
ellipse(0, size * 0.2, size * 0.5, size * 0.3);
rectMode(CENTER);
rect(size * 0.15, -size * 0.05, size * 0.1, size * 0.5);
line(size * 0.15, -size * 0.3, size * 0.4, -size * 0.3);
};
countdownIcons = [
// 10 icon functions (same as ball icons)
];
fireworksSynth = new Tone.PolySynth(Tone.Synth, {
oscillator: { type: "square" },
envelope: { attack: 0.05, decay: 0.2, sustain: 0.1, release: 0.5 },
volume: -10
}).toDestination();
countdownBeep = new Tone.Synth({
oscillator: { type: "sine" },
envelope: { attack: 0.01, decay: 0.1, sustain: 0.0, release: 0.1 },
volume: -10
}).toDestination();
}
Line-by-line explanation (5 lines)
🔧 Subcomponents:
montserratBold = loadFont('https://unpkg.com/@fontsource/montserrat@latest/files/montserrat-latin-700-normal.woff');
Imports external fonts from a content delivery network so text displays in a specific typeface
ballIcons = [ ... ];
Defines eight drawing functions that create iconic symbols representing 2025 moments to be displayed on the ball
fireworksSynth = new Tone.PolySynth(Tone.Synth, { ... }).toDestination();
Creates a multi-voice synthesizer that plays chords when fireworks explode
montserratBold = loadFont('https://unpkg.com/@fontsource/montserrat@latest/files/montserrat-latin-700-normal.woff');- Loads a bold font file from the internet. p5.js will use this font whenever you call textFont(montserratBold).
ballIcons = [ ... ];- Creates an array of 8 drawing functions. Each function takes a size parameter and draws one of the 2025 icons using p5.js shapes.
bitcoinIcon = (size) => { fill(gold); ... text('₿', 0, 0); };- Defines a small function that draws a gold square with a Bitcoin symbol (₿) inside—used by particles that fall from the ball.
countdownIcons = [ ... ];- Creates an array of 10 drawing functions (one for each countdown number 10 down to 1) that flash above the countdown display.
fireworksSynth = new Tone.PolySynth(Tone.Synth, { ... }).toDestination();- Initializes a Tone.js synthesizer with a square wave that plays rapid chords when fireworks explode, creating a celebratory sound.