preload()
preload() is called once before setup() and is the right place to load fonts, images, and other files from the internet. It ensures everything is ready before your sketch begins drawing.
function preload() {
uiFont = loadFont(
'https://cdn.jsdelivr.net/fontsource/fonts/roboto@latest/latin-400-normal.woff'
);
}
Line-by-line explanation (1 lines)
uiFont = loadFont('https://cdn.jsdelivr.net/fontsource/fonts/roboto@latest/latin-400-normal.woff');- Loads a font file from a CDN (content delivery network) and stores it in the uiFont variable so it can be used for text later. preload() guarantees this finishes before setup() runs.