Lecture 2 (3 Feb)
You can jump to any slide with the menu to the (bottom) left.
Did you miss a slide or want to revisit? Open the narration tab while studying to get an explanation of difficult slides.

text(), ellipse(), and rect()x, y) and the size / contents+, -, *, and /.+ can also add strings together

Class Assignment
Create your own interactive Mondrian painting! In groups of 1-3, make a p5js sketch that draws rectangles (or other shapes) based on the mouse position. Be creative with colours and shapes!
text() call50 pixels vertically aparttext() calls and calculate the y position each timelet to create a variable named interestingNumber that contains the number 42interestingNumber in our code instead of having to write 42 every timelet once, when we first create the variableinterestingNumber = 100; reassigns the variable to now contain 100interestingNumber++; increases the variable by 1interestingNumber--; decreases the variable by 1interestingNumber += 5; increases the variable by 5interestingNumber -= 2; decreases the variable by 2interestingNumber *= 3; multiplies the variable by 3interestingNumber /= 4; divides the variable by 4'' or ""int()float()round(), floor(), and ceil() can round, round down, and round up floats to integers, respectivelytrue or falsetrue and false are system keywords, similar to e.g. mouseX and widthverticalPosition to 100 at the startverticalPosition by 50true or false (boolean)== (equal to)!= (not equal to)< (less than)> (greater than)<= (less than or equal to)>= (greater than or equal to)mouseX is smaller than 200.( ){ }mouseX < 200 -> redmouseY < 200 -> draw ellipse&& (and): both conditions must be true|| (or): at least one condition must be truefor (initialization; condition; update) { // code to repeat }
i from 1 to 5draw() are not accessible in setup()i is contained within the loopi elsewhere without conflict[], with values separated by commas ,colours is an array containing three strings: ‘red’, ‘green’, and ‘blue’0arrayName[0], the second element is arrayName[1], and so onmyArray.length gives the number of elements in the arraymyArray.push(value) adds a new value to the end of the arraymyArray.pop() removes the last value from the arraymyArray.sort() sorts the array elementsmyArray.reverse() reverses the order of the array elementsClass Assignment: Patterns!
In a group of 1-3, start by drawing some patterns on paper or a whiteboard (e.g. https://www.tldraw.com)
Then, implement these patterns in p5js using loops and arrays where appropriate.
Can you make them interactive using mouseX and mouseY?

Creative Programming 2026 Lecture 2 - Ties Robroek - IT University of Copenhagen