preload()
preload() runs before setup() and is the place to load files like fonts, images, and sounds that your sketch needs to be ready before drawing starts. If you do not preload fonts, p5.js will use the default browser font, which may not render Hebrew correctly.
function preload() {
// Cargar una fuente que soporte hebreo desde Fontsource CDN
// Convertir "Rubik" a slug: "rubik"
// URL para el archivo hebreo 400 normal:
// CORRECCIÓN: El archivo rubik-hebrew-400-normal.woff no existe en Fontsource para Rubik.
// La variante 'latin' de Rubik incluye los caracteres hebreos.
hebrewFont = loadFont('https://unpkg.com/@fontsource/rubik@latest/files/rubik-latin-400-normal.woff');
}
Line-by-line explanation (1 lines)
🔧 Subcomponents:
hebrewFont = loadFont('https://unpkg.com/@fontsource/rubik@latest/files/rubik-latin-400-normal.woff');
Fetches a Rubik font from a CDN that includes Hebrew glyphs so text renders correctly
hebrewFont = loadFont('https://unpkg.com/@fontsource/rubik@latest/files/rubik-latin-400-normal.woff');- Loads a font file from the internet before the sketch runs. This font supports both Hebrew and Latin characters, stored in the hebrewFont variable for later use.