setup()
setup() runs once when the sketch starts. It's the right place to configure the canvas, fonts, and any one-time calculations before the animation loop begins.
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
background(0);
// Choose a monospaced look for nice columns
textFont('monospace');
recalcSymbolSize();
textSize(symbolSize);
textAlign(LEFT, TOP); // so y is the top of each glyph
initStreams();
}
Line-by-line explanation (8 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that exactly matches the current browser window size, so the rain fills the whole screen.
frameRate(60);- Requests that draw() runs 60 times per second, giving smooth, fast-falling motion.
background(0);- Paints the canvas fully black once at startup so there's no leftover white canvas before the first frame.
textFont('monospace');- Switches to a monospace font so every character takes up the same width, keeping columns perfectly aligned.
recalcSymbolSize();- Calls the helper function that figures out an appropriate character size based on the screen's width.
textSize(symbolSize);- Applies that calculated size to all text drawn from now on.
textAlign(LEFT, TOP);- Tells p5 to treat the x,y you give text() as the top-left corner of the glyph, which makes stacking characters vertically simple and predictable.
initStreams();- Builds the full array of Stream objects, one per column, so the rain is ready to animate.