WEEK 1 DAY 1
Eevi Rutanen
2011-2017 BA Visual Communication Design at Aalto ARTS
2012-2014 BSc Bioinformation Technology at Aalto ELEC
2017-2019 MFA Computational Arts at Goldsmiths
2020- Teaching Creative Computation at Aalto ARTS
Artist, designer, teacher
eevi@eevirutanen.com
What’s your name?
What are your pronouns?
Which year / study program are you on?
What does "coding" mean to you? (Experiences, expectations?)
25% theory, 75% practice
Classroom activities
Live-coding exercises
Independent coding
Pair coding exercises
Non-programmatic exercises
Weekly programming assignment
Weekly reading assignment + discussion
Submitted in MyCourses by next Tuesday
COMPUTATION
PROGRAMMING
CODING
The act of using mathematical calculations
The process of writing computer programs
Translating natural language into machine commands
Preheat oven to 200°C.
Remove the plastic wrapping from the pizza.
Place the pizza on an oven rack.
Bake 10-13 minutes.
Serve.
Go to the oven.
Turn the oven on.
Wait until oven is 200°C.
Go to the freezer.
Open the freezer.
Take the pizza out.
Remove the pizza from the box.
Remove the plastic wrapping from the pizza.
Place the pizza on an oven rack.
Go to the oven.
Open the oven.
Put the oven rack into the oven.
Bake 10-13 minutes.
Put the pizza on a plate.
Eat the pizza.
How to prepare a frozen pizza?
Go to the oven.
Turn the oven on.
If the oven has buttons, push the button to turn the oven on.
If the oven has a dial, rotate the dial to turn the oven on.
Wait until the oven is
200°C OR
392°F
ERROR: The pizza is on fire, call 112.
How to prepare a frozen pizza?
Proprietary software
(Photoshop, Illustrator, Figma)
Libraries, frameworks
(Processing, p5.js, OpenFrameworks, Nodebox, React, Ruby on Rails)
High level languages
(FORTRAN, COBOL, BASIC, C, C++,
Java, Python, Ruby, JavaScript, PHP)
Low level languages
(Assembly languages)
Machine code
(010100011…)
CONTROL
EFFORT
Syntax is the “vocabulary” and “grammar” of any programming language
Set of rules on how the code should be written
All programming languages have their own syntax
In most high level languages the syntax is quite similar
Close to natural language
Changing between languages is usually easy
Code editors have automatic syntax highlighting to make reading easier
console.log("Hello");
print("Hello");
print("Hello")
print "Hello";
JavaScript
p5.js
Python
Perl
AUTOMATION
Using computational power to complete tasks that are laborious for humans.
OPTIMISATION
Seeking solutions for complex problems that are beyond human cognition.
IDEATION
Reaching unexpected outcomes by setting into motion an autonomous process
CREATIVE CODING
Western Dream (1957) by Helen Frankenthaler
MIT Media Lab identity (2014) by Pentagram
Abstracting and breaking down problems
Taking ordered steps to solve the problem
Generalising the problem-solving process
Visual communication design is already computational!
Recognising computational elements in your practice
Vocabulary and confidence to discuss computational topics
Making your own tools
New ways of expression
Financial and creative independence
Escaping the black box
Demystifying computation
Empowering yourself!
AI generated poster made with Stable Diffusion. Prompt: "Cool urban music festival visual identity poster"
Draw a simple arrangement of shapes on paper.
Describe the drawing to others as precisely as possible by just describing the formal features:
Basic shapes: Line, circle, rectangle, triangle, arc, etc.
Orientation: Right, left, up, down etc.
Rotation: 45°, 90°, 180° etc.
Relative coordinates: Middle, corner, side, perpendicular, parallel, etc.
Relative sizes: Smaller than, larger than, half the size, etc.
Others should try to replicate the drawing based on the description.
“ DOUBLE QUOTES
‘ SINGLE QUOTE
: COLON
; SEMICOLON
& AMPERSAND
! EXCLAMATION MARK
\ SLASH
= EQUALS SIGN
* ASTERISK
( ROUND BRACKET, PARENTHESIS
[ SQUARE BRACKET
{ CURLY BRACKET
| PIPE
~ TILDE
< SMALLER THAN
> LARGER THAN
LEARN TO TYPE THESE!
+ ADDITION
- SUBTRACTION
* MULTIPLICATION
** EXPONENTIATION
/ DIVISION
(% MODULUS)
2 + 2 = 4
3 - 1 = 2
4 * 4 = 16
3 ** 2 = 9
15 / 5 = 3
7 % 3 = 1
DON'T WORRY, WE ARE NOT HERE TO DO MATH...
JavaScript library for creative coding
Library extends the functionality of JavaScript
Focus on accessibility and experimentation
Focus on (audio)visual and interactive content
Applications made with p5.js are called sketches
Sketches runs in the browser
Sketches are drawn on the HTML canvas
Based on an earlier project called Processing
Create and edit p5.js sketches in the browser
No need to download anything
Requires user registration to save sketches
Easy to share your work!
Eg. embed on a website
Export images, gifs (or video)
Allows upload of external assets (fonts, images)
Organising sketches in collections
p5.js can also be used with a code editor of your choice
X-axis is horizontal
numbers grow left to right
Y-axis is vertical
numbers grow from bottom to top
Coordinates are usually given as (x,y)
Origin (0,0) in the middle
Coordinates are pixels on the canvas
Origin is in the top left corner
X-axis is horizontal
left-right
Y-axis is vertical
top-bottom
(0,0)
x
y
(0,0)
width = 600
height=
400
(300,200)
(width/2, height/2)
(600,0)
(width, 0)
(600,400)
(width, height)
(0,400)
(0, height)
FUNCTION
Functions are instructions that execute specific tasks
Eg. drawing a shape, performing a calculation
The values inserted in the function are called arguments
Changing the values for the arguments changes the result of the function
Programming languages and libraries have predefined functions
Eg. circle function for drawing a circle, round function for rounding up a value
Every new p5 sketch begins with two main functions: setup and draw
These define how / when other functions are executed or called
You can also define your own custom functions
More on week 3
ellipse(x,y,width,height);
ellipse(300,200,50,80);
function name
arguments in brackets
Using the function to draw an ellipse at coordinates x=300, y=200. The width of the ellipse is 50px and height is 80px.
semicolon!
ellipse(x, y, w, h);
line(x1, y1, x2, y2);
rect(x, y, w, h, [rad]);
circle(x, y, d);
square(x, y, s, [rad]);
triangle(x1, y1, x2, y2, x3, y3);
point(x,y);
quad(x1, y1, x2, y2, x3, y3, x4, y4);
arc(x, y, w, h, start, stop);
rect(0,0,200,100);
rectMode(CENTER);
rect(0,0,200,100);
RGB colour model defines all colours as a mix of red, green and blue
In p5 by default, R, G, B and opacity channels can have values 0-255
You can also use HEX values or CSS named colors
Using colorMode() you can also change to HSL or HSB model or change the RGB value range
fill(0,255,0);
green fill
fill(255,255,255);
white fill
fill(255);
white fill
fill(0);
black fill
fill(100);
grey fill
fill(255,0,255);
magenta fill
fill(0,0,255,50);
blue fill with low opacity
fill('red');
fill('#cc00ff');
using CSS named colors
using HEX colour codes
fill(r,g,b,a);
stroke(r,g,b,a);
strokeWeight(px);
background(r,g,b,a);
noFill();
noStroke();
strokeCap(ROUND);
strokeCap(SQUARE);
THESE STATEMENTS AFFECT ALL THE SHAPES THAT FOLLOW!
Statements are always executed in order from top to bottom and inside out
Functions that change drawing state or style (eg. fill, stroke) affect all subsequent functions
Inner statements are executed before outer statements (like in mathematics!)
fill(round(99.5));
Here round() function is executed first, so fill colour will be rounded to 100.
Setup function is executed once when the program starts
Draw function loops continuously until the program stops
Statements end in semicolons ;
Function arguments are inside brackets ()
Blocks (like setup() and draw()) are inside curly brackets {}
Blocks are indented with a tab
JS is not actually sensitive to white spaces
You should format your code in a systematic and legible way!
JS is case-sensitive! Pay attention to camelCase or UPPERCASE in function names and arguments
Double quotes "" or single quotes '' are interchangeable
Comments start with // or go between /* */
Your code might still work with bad formatting but it doesn't make it right!
Console can be also used to display information or messages about the sketch
You can print out text or numbers
print("Setup completed!");
print(mouseX);
Check error messages in console
Double-check your syntax
Check P5.js reference for function usage
Isolate the issue
Backtrack: When did it stop working? What did you add last?
Print intermediate data to console
Comment out blocks of code to find the problem
Ask on MyCourses Code Help Forum
Google! (i.e. Stack Overflow)
Coding is always a communal effort!
It is very common to use code someone else wrote
By default, we are using the p5 library...
If you copy code, ALWAYS credit the sources
Original author and date
Link to source
What the original code does, what did you modify?
If you borrow code, you also have to contribute!
Add, modify, combine different sources
Be explicit about what is yours and what is not
Make sure you understand how the code works
How to calculate coordinates when drawing symmetrical shapes around the center of the canvas?
How can you use the width and height attributes of the canvas?
Eg. draw first shape 100px left from the center, draw a second shape 100px right from the center. How do you formulate these coordinates?
Furthermore: How to make your drawing centered if the size of the canvas changes?
Consider how to build more complex shapes using just primitive shapes
Try using the arc function! What arguments are needed?
Pay attention how to best calculate coordinates using the previous example.
Make a drawing tool!
Try using different shapes or a combination of shapes to draw with the mouse
Make it interactive!
Try animating your drawing using mouseX and mouseY
Animate coordinates, size, colour, stroke...
Figure out how to achieve this trailing effect!
//default p5.js functions
setup(){
//code inside setup runs only once
}
draw(){
//code inside draw runs 60 times per second
}
//printing to console
print("message");
print(myVariable);
createCanvas(w,h); //set drawing area size inside setup
//draw primitive shapes
point(x,y);
line(x1, y1, x2, y2);
ellipse(x, y, w, h);
circle(x, y, d);
rect(x, y, w, h, rad);
square(x, y, s);
triangle(x1, y1, x2, y2, x3, y3);
quad(x1, y1, x2, y2, x3, y3, x4, y4);
//define coordinates for shapes
rectMode(MODE); //mode can be CENTER or CORNER
background(red,green,blue); //set background colour
fill(r,g,b,a); //set fill colour
stroke(r,g,b,a); //set stroke colour
strokeWeight(px); //set stroke thickness
strokeCap(MODE); //set ROUND or SQUARE stroke end
noStroke(); //draw without stroke
noFill(); //draw without fill
mouseX, mouseY //get mouse coordinates
width, height //get canvas dimensions
Daniel Shiffman: The Coding Train
Excellent and engaging video tutorials (using p5.js)
Extensive tutorials on everything JavaScript
Basic JavaScript tutorials for all skill levels
Daniel Shiffman: Nature of Code
A bit more advanced programming topics (using Processing)
Rune Madsen: Programming Design Systems
P5.js exercises for graphic designers
Pick one of the questions in the article. What do you think could be an answer to that question? Post your thoughts on the MyCourses forum (~2-6 sentences is fine).
Reply to someone else's post.
Due next Tuesday!
Answer the starting level questionnaire
Attempt one of the variations 3-6 (or create something else interesting!) and share it on the Week 1 showcase forum
Weekly Reading I (by next Tuesday)