Professional Documents
Culture Documents
Creative Coding Workshop For Beginners
Creative Coding Workshop For Beginners
#JFOBMEF"SUFT.FEJBMFT
0DUUI
Workshop Content
‣ Shape and Code
‣ Introduction of Processing
‣ Trying to draw simple forms with Processing
Shape and Code
Shape and Code
‣ The meaning to use code for creation
‣ Historical works of coding of creating shapes
Shape and Code
‣ The advantage of programming for creation
(…){
…
…
… }
About colour
About colour
‣ How to define a color?
‣ Additive primaries v.s. Subtractive primaries
‣ Processing uses Additive primaries (Red, Green, Blue)
Additive Subtractive
About colour
‣ A mechanism of computer screen
‣ Zoom into the screen
‣ Two-dimensional grid of points → pixel
‣ Each pixels consits with Red Green Blue (RGB)
About colour
‣ The computer screen is like huge excel table consits of pixels
‣ e.g. Screen resolution of 1024 x 768
‣ The huge table 1024 row, 768 lines
‣ Each cells holds R, G, B, A values
R
G
B
A
Coordinate System
Coordinate System
‣ Coordinate System
‣ Pair of numbers uniquely determine the position of a point
(0, 0) (100, 0)
(0, 100)
Trying to draw simple forms
Trying to draw simple forms
‣ At first, define a canvas size
‣ size():defines a window size to draw
size(<width>, <height>);
size(320, 240);
Trying to draw simple forms
‣ point() : draws a point to the screen
point(<x-coordinate>, <y-coordinate>);
point(100, 120);
Trying to draw simple forms
Trying to draw simple forms
‣ line() : draws a line to the screen
‣ e.g.
line(10,10,200,180);
Trying to draw simple forms
Trying to draw simple forms
‣ rect() : draws a rectangle to the screen
‣ e.g.
rect(10,10,200,180);
Trying to draw simple forms
Trying to draw simple forms
‣ ellipse() : draws an ellipse (oval) to the screen
‣ e.g.
ellipse(10,10,200,180);
Trying to draw simple forms
Trying to draw simple forms
‣ Let s draw simple forms!
size(800, 600); // define a screen size
Additive Subtractive
Specify colours
‣ There are three attribute of colours
‣ background colour - background()
//fill color
fill(128, 64, 32); //RGB
//stroke color
stroke(128, 64, 32); //RGB
Specify colours
‣ e.g. 2
size(640, 480);
background(31);
stroke(255, 255, 31);
fill(31, 127, 255, 127); // 50% transparency
point(200, 200);
line(80,40,600,400);
rect(300,200,200,180);
ellipse(450,200,200,100);
Specify colours
‣ adding alpha values
Specify colours
‣ draw in different colours
size(640, 480);
background(31);
stroke(255, 255, 31);
point(200, 200);
line(80,40,600,400);
noFill();
ellipse(200,200,400,400);
ellipse(100,200,200,200);
ellipse(300,200,200,200);
ellipse(200,100,200,200);
ellipse(200,300,200,200);
Quiz 2
‣ draw the shapes in below
‣ the screen size is 400 x 400 pixel
Quiz 2
‣ Answer
size(400, 400);
fill(255);
rect(40, 40, 320, 320);
fill(0);
rect(40, 40, 160, 160);
rect(200, 200, 160, 160);
Quiz 3
‣ Draw this shape using the shapes before we created
Quiz 3
‣ answer (example)
size(400, 400);
fill(255);
rect(40, 40, 320, 320);
fill(0);
rect(40, 40, 160, 160);
rect(200, 200, 160, 160);
fill(255);
ellipse(120, 120, 160, 160);
ellipse(280, 280, 160, 160);
fill(0);
ellipse(280, 120, 160, 160);
ellipse(120, 280, 160, 160);
Variables
Variables
‣ Quiz:
‣ Draw a half size of square within the square
ver
Variables
‣ Answer
size(400,400);
rect(100,100,200,200);
rect(100,100,100,100);
Variables
‣ Add a half of the square into the square
Variables
‣ Answer
size(400,400);
rect(100,100,200,200);
rect(100,100,100,100);
rect(100,100,50,50);
Variables
‣ Is there more smart way to calculate the size of square?
‣ If we can record the size of the square, it is more convenient
7BSJBCMF
Variables
‣ Data type - identifying one of various types of data
‣ Popular data types in Processing
‣ int:integer value (-1, 0, 1, 2, 3....)
‣ float:real number (-0.01, 3.14, 21.314)
‣ boolean:having two values (true, false)
‣ char:character (a, b, c, d...)
‣ color:color value
int hoo;
hoo = 0;
hoo = hoo + 1;
Variables
‣ Improve the code before using variable calculation
size(400, 400);
float rectSize = 200;
…
Variables
‣ You can draw the nest of rectangles
変数
‣ e.g.
size(800, 600);
background(0);
noStroke();
fill(0, 127, 255, 100);
float x, y, diameter;
x=width/2;
y=height/2;
diameter=height;
....
Iteration
‣ Can we define repeated sections at once?
‣ → For loop
int i;
int i;
float x, y, diameter;
x = width / 2;
y = height / 2;
diameter = height;
float diameter;
diameter = width/1.8;
translate(width/2, height/2);
rotate(PI/4);
for (int i = 0; i < 256; i++) {
ellipse(diameter / -2, 0, diameter, diameter);
ellipse(diameter / 2, 0, diameter, diameter);
diameter = diameter / 1.05;
rotate(PI / 24.0);
}
Iteration
HSB Color System
HSB Color System
‣ There is another colour system expect RGB
‣ e.g.
‣ hue: 360 degree
‣ saturation: 100 graduation
‣ brightness: 100 graduation
‣ Randomness
‣ Randomness is the lack of pattern or predictability in events
Randomness
‣ random() : generate randomness in Processing
random(100);
random(100, 1000);
Randomness
‣ draws shapes with random colours
int i;
size(800, 600);
colorMode(HSB, 360, 100, 100);
noStroke();
size(300,300);
colorMode(HSB, 360, 100, 100);
noStroke();
size(300,300);
colorMode(HSB, 360, 100, 100);
noStroke();
size(800, 600);
background(0);
colorMode(HSB, 360, 100, 100, 100);
noStroke();
size(800, 600);
background(0);
colorMode(HSB, 360, 100, 100, 100);
rectMode(CENTER);
noStroke();