Programming for Visual Artists
ARTS-A0701 – Digital Art 1
2024 - Lecture 1
Today
- p5.js intro
- Shapes, coordinates and colors
- Assignment 1
p5.js editor
Sign up
(if you really don't want to work with a browser editor follow this guide: https://p5js.org/get-started/)
p5.js intro
Let's create an save our first sketch
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
if (mouseIsPressed) {
ellipse(mouseX, mouseY, 50, 50);
}
}
function setup() {
}
function draw() {
}
Code here between { and } is executed once in the geginning
Code here between { and } is executed over and over again
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
}
Call a function 'createCanvas' with the parameters 400 and 400. First parameter sets width and secon sets height.
Call a function 'background' with the parameter 220. A single parameter sets a grey value between 0 (black) and 255 (white)
JS is case sensitive. createcanvas is different than createCanvas
Each statement should end in a semicolon ;
function setup() {
//This is a comment
//Computer skips all comments
//Sometimes is't good to write notes in your code
createCanvas(400, 400);
}
function draw() {
background(220);
}
function setup() {
}
This defines a function called setup that takes zero parameters
p5.js calls the setup function once in the beginning of execution
Now we're only missing variables, conditional statements, loops, arrays and classes and we're done!
Shapes, coordinates and colors
Coordinates and shapes
Colors
Assignment 1
- Use basic shape primitives to draw a face. The aim is to get familiar with the p5 shape primitives, coordinate system and colors so don't be too critical of your creation.
- Submit a link to your p5 sketch on MyCourses.
Optional reading
Other resources
- Code! Programming for Beginners with p5.js: https://www.youtube.com/watch?v=yPWkPOfnGsw&list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA&t=0s
- p5.js Web Editor:
https://www.youtube.com/watch?v=MXs1cOlidWs&list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA&t=0s - Shapes & drawing:
https://www.youtube.com/watch?v=c3TeLi6Ns1E&list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA&t=0s
Programming for Visual Artists, lecture 1
By otso_havanto
Programming for Visual Artists, lecture 1
- 731