home/ modules/ first-sketches-p5-processing-core

First sketches: the p5.js/Processing drawing core

  • learner can structure a sketch with setup/draw, coordinate system, and primitive shapes with fill/stroke state
  • learner can drive repetition and branching with variables, for-loops, and if-else conditionals
  • learner can specify colour in RGB and map values between ranges to parameterise a drawing

Build an animated generative composition from scratch that loops shapes across a coordinate grid, uses variables and conditionals to vary them, and colours them via map()-driven RGB — running smoothly in the draw loop.

This module is where visuals for a live set stop being someone else’s demo and become something you can build on a blank canvas. In an audio-visual live-coding rig, p5.js or Processing is typically the projection layer: a sketch running fullscreen next to your sound engine, redrawing sixty times a second, its parameters ready to be wired to amplitude or MIDI later. Before any of that reactivity is possible, you need the drawing core — and that is the whole task here: an animated generative composition that fills the screen, varies itself, and never freezes the frame loop.

The arc starts fully supported. First exercises are static: place primitives on the canvas using the top-left-origin coordinate system, styling them with fill/stroke state (“Processing separates fill, stroke, and strokeWeight into independent state settings” is your JIT pointer when a shape inherits the wrong colour). Then motion enters via the two lifecycle functions — “setup() runs once and draw() runs every frame” — and a single variable nudged each frame. From there, scaffolding drops away: a for-loop turns one shape into a grid, conditionals make cells diverge, and “p5.js map() rescales a value from one numeric range into another” converts loop counters into RGB channels.

The required atoms gate the capstone directly: without setup/draw there is no animation, without loops no grid, without map() no parameterised colour. Supporting atoms enrich rather than gate — the frame-loop procedure atom deepens the same setup/draw material with frameRate() and trail effects, variable scope explains the classic frozen-animation bug, HSB colour modes and custom functions point toward cleaner, more expressive sketches, and the abstraction principle frames why one call can draw so much.

Atoms in this module

Required — these gate the capstone

setup() runs once and draw() runs every frame, forming the animation loop
Concept L1 Foundations H
The Processing/p5.js canvas places the origin at the top-left with y increasing downward
Concept L1 Foundations H
Processing provides point, line, rect, ellipse, and bezier as core drawing primitives
Fact L1 Foundations H
Processing separates fill, stroke, and strokeWeight into independent state settings
Concept L1 Foundations H
Processing requires explicit data types — int, float, and boolean serve different numeric purposes
Concept L1 Foundations H
A for loop repeats a code block under init, test, and update, turning one drawing procedure into a whole pattern
Concept L1 Foundations H
Processing's if-else structures let programs branch based on relational expressions
Concept L1 Foundations H
Processing specifies colour as additive RGB values (0–255 per channel) with an optional alpha channel
Concept L1 Foundations H
p5.js map() rescales a value from one numeric range into another
Concept L1 Foundations H

Supporting — enrichment, not gating

Processing's setup() runs once and draw() repeats each frame to create animation
Procedure L2 First instrument H
Abstraction hides implementation details so programmers focus on what code does, not how
Concept L1 Foundations H
Where a variable is declared determines its scope: outside functions is global, inside is local
Concept L1 Foundations H
p5.js accepts colors as a grayscale number, an RGB triple, or a CSS color-name string
Concept L1 Foundations H
Processing maintains drawing style state until explicitly changed
Concept L2 First instrument H
Custom functions in Processing encapsulate reusable code blocks with parameters and return values
Concept L2 First instrument H