setup()
setup() runs once when the sketch starts. Use it to initialize your canvas, load data, and prepare global objects. Everything here happens before the draw loop begins.
function setup() {
let canvas = createCanvas(min(windowWidth - 40, 1200), 400);
canvas.parent('canvas-container');
station = new WeatherStation();
gui = new GUI();
textFont('Roboto');
}
Line-by-line explanation (5 lines)
🔧 Subcomponents:
let canvas = createCanvas(min(windowWidth - 40, 1200), 400);
Creates a canvas that is 1200px wide max, but shrinks on small screens to fit in the viewport with 40px padding
station = new WeatherStation();
gui = new GUI();
Creates global instances of the two main classes that manage data and UI
let canvas = createCanvas(min(windowWidth - 40, 1200), 400);- Creates a p5.js canvas that is at most 1200 pixels wide but shrinks on small screens. The height is always 400 pixels. The min() function picks whichever is smaller.
canvas.parent('canvas-container');- Tells p5.js to place the canvas inside the HTML element with id 'canvas-container' instead of at the top of the page
station = new WeatherStation();- Creates a new WeatherStation object that will manage all sensor data, history arrays, and graphing logic
gui = new GUI();- Creates a new GUI object that builds all the buttons, dropdowns, sensor cards, and statistics panels
textFont('Roboto');- Sets the font for all text drawn by p5.js to 'Roboto', which matches the Google Font loaded in HTML