setup()
setup() runs once when the sketch starts. It initializes the canvas, sets up text properties, and creates the initial streams. The monospace font is crucial for maintaining neat vertical columns.
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:
createCanvas(windowWidth, windowHeight)- Creates a canvas that fills the entire browser window, making the effect fullscreen
frameRate(60)- Sets the animation to run at 60 frames per second for smooth motion
background(0)- Fills the canvas with pure black (0 in grayscale), the classic Matrix background
textFont('monospace')- Sets the font to monospace so all characters have equal width, creating neat columns
recalcSymbolSize()- Calls a helper function to calculate an appropriate character size based on screen width
textSize(symbolSize)- Applies the calculated character size to all text that will be drawn
textAlign(LEFT, TOP)- Aligns text so the y-coordinate represents the top of each character, making positioning easier
initStreams()- Creates all the vertical character streams that will cascade down the screen