setup()
setup() runs once when the sketch starts. Use it to create your canvas, initialize variables, set up colors, and call any functions that prepare your scene. Everything here happens before draw() ever runs.
function setup() {
pixelDensity(2);
createCanvas(windowWidth, windowHeight);
petalColor1 = color(255, 200, 0);
petalColor2 = color(255, 170, 0);
centerColor1 = color(120, 60, 10);
centerColor2 = color(180, 100, 30);
stemColor = color(50, 160, 50);
leafColor = color(70, 180, 70);
backgroundColor = color(220, 255, 220);
targetTimestamp = Date.now() - (128 * 24 * 60 * 60 * 1000) - (10 * 60 * 60 * 1000);
generateSunflowers();
textAlign(CENTER, CENTER);
textSize(width * 0.035);
fill(0);
textFont('Arial');
}
Line-by-line explanation (7 lines)
🔧 Subcomponents:
petalColor1 = color(255, 200, 0);
Sets up all the colors used throughout the sketch for petals, stems, leaves, and background in one place
targetTimestamp = Date.now() - (128 * 24 * 60 * 60 * 1000) - (10 * 60 * 60 * 1000);
Calculates the relationship start time by subtracting days and hours from the current moment in milliseconds
textSize(width * 0.035);
Makes the timer text responsive by scaling it relative to window width instead of using a fixed pixel size
pixelDensity(2);- Doubles the pixel density for higher resolution on devices with high DPI screens like phones and modern monitors
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window, using the window's current width and height in pixels
petalColor1 = color(255, 200, 0);- Creates a bright yellow color (255 red, 200 green, 0 blue in RGB) and stores it for drawing flower petals
targetTimestamp = Date.now() - (128 * 24 * 60 * 60 * 1000) - (10 * 60 * 60 * 1000);- Gets the current time in milliseconds, then subtracts 128 days (converted to milliseconds) and 10 hours to set the relationship start point
generateSunflowers();- Calls the helper function to create 50 Sunflower objects with random positions and sizes, filling the array
textAlign(CENTER, CENTER);- Centers all future text both horizontally and vertically around the coordinates you give it
textSize(width * 0.035);- Sets the text size to 3.5% of the window width, so it scales responsively when the window resizes