Lecture 02 GettingStarted (Moodle)
Lecture 02 GettingStarted (Moodle)
Computing
Lecture 2Getting Started with
Processing
What you’ll learn today?
Draw a What
rectangle languages
does
繪一個矩形 computer
understand?
矩形を描画する
How to tell computers to do some
operations?
. Computers understand computer
languages / programming languages
. languages designed to communicate
instructions to computers
.
Writing Managin
webpage g data
s
Different programming languages
Writing
Writing
webpage
applicatio
ns
s
Different programming languages
.
We use a programming language called Python
with Processing
.
. rectangle
.
. Where to draw?
.
(5,
(0, 0)
4)
(8,
6)
Let’s try to locate some points
(3, 3)
(8, 2)
(4, 7)
How to draw a shape?
. Where to draw?
. Top-left corner at (2, 1)
.
Filename
Line number
Message:
the computer may talk to you
here
Text
output
here
Work Flow / Program Flow of
Processing
. Think about your dinner
1. Buy the food
5. Full
Work Flow / Program Flow of
Processing
. Every Processing program follows this work flow
1. Set window size
Setup
2. Other setup (Preparati
on)
5. Stop
Program Flow of Processingsetup() and
draw()
. Different programming languages
have different grammar / syntax /
rules to follow
Gramma
r of the
Processi
ng
Let’s try
this
together!
!
Program Flow of Processingsetup() and
draw()
. Put different types of instructions
to different sections / functions
1. Set window size
2. Other setup
3. Draw background
size
. Remember to put instructions with
2. Other setup
indentation(4 spaces)
. Indentation is used to distinguish
blocks of code
3. Draw
background
4. Draw
somethinge.g.
draw a rectangle
Program Flow of Processingsetup() and
draw()
. Processing starts in setup(), the
instructions there will be done for
ONE time
1. Set window .
3. Draw
background
4. Draw
somethinge.g.
draw a rectangle
Program Flow of Processingsetup() and
draw()
. Now, let’s try the size function.
.
4. Draw
somethinge.g.
draw a rectangle Note: a function call is like a
command for Processing to execute.
Program Flow of Processingsetup() and
draw()
. Now, let’s try the background
function.
.
3. Draw
background
. Try the following two sets of
numbers. Any difference???
4. Draw . background(500, 500, 500)
somethinge.g. . background(255, 255, 255)
draw a rectangle
Program Flow of Processingsetup() and
draw()
. Now, let’s try the rect function.
.
.
background(Amount ,
Amount Amount,
of Red of of Blue
) Green
background(200, 100, .
5
background(200, 100, 0
0) 0
rect(50, 100, 250,
150)
5
0
0
Program Flow of ProcessingHow setup()
and draw() work?
background(200, 100,
2
0)
a
rect(50, 100, 250,
150)
Program Flow of ProcessingHow setup()
and draw() work?
background(200, 100, 2
0) a
rect(50, 100, 250,
150) 2
b
Program Flow of ProcessingHow setup()
and draw() work?
background(200, 100,
2
0)
a
rect(50, 100, 250,
150)
Program Flow of ProcessingHow setup()
and draw() work?
background(200, 100, 2
0) a
rect(50, 100, 250,
150) 2
b
Program Flow of ProcessingHow setup()
and draw() work?
background(200, 100,
0)
rect(50, 100, 250,
150)
background(200, 100,
0) 2 Instructions put inside
a draw() will be repeated
rect(50, 100, 250,
150) 2 AGAIN, AGAIN, and AGAIN,
b …
Grammar / Syntax of the
Processing language
rect(50,100,250,150) . parenthesis ( )
. Put all the information inside
Grammar / Syntax of the
Processing language
rect(50,100,250,150) . parenthesis ( )
. Put all the information inside
.
. commas ,
. To separate information
Grammar / Syntax of the
Processing language
rect(50,100,250,150) . parenthesis ( )
. Put all the information inside
.
. commas ,
. To separate information
.
. indentation
. To put instructions in blocks
Complicat
ed
Need
many
instructio
ns
HOW TO DRAW A ROBOT?
Use image instead of drawing
4 steps to use an image
1. Prepare an image
. Inside the sketch folder,
create a new folder and
name it as “data”
. Prepare an image and put it
inside the “data” folder
Make sure the “data” folder is at the
same level with the program file
4 steps to use an image
8.
1.
Submit on BU Moodle
Why don’t we draw
with Paint or
Photoshop? Why we use
Processing?
INTERACTIVE DRAWINGS
Making drawings move
Why the robot is not moving?
. The robot image is displayed at
a fixed position every time
draw() repeats
Repeat
2
Repeat
3
Let’s try making the robot follow
mouse
. This is to display the robot
image at the mouse’s position
.
Repeat 1
Mouse’s
50 100 position is (50,
100)
How does the robot follow mouse?
. The robot image is displayed at
a the current mouse’s position
every time draw() repeats
Repeat 2
Mouse’s
250 250 position is
(250, 250)
How does the robot follow mouse?
. The robot image is displayed at
a the current mouse’s position
every time draw() repeats
Repeat 3
Mouse’s
450 200 position is
(450, 200)
Class Exercise 2
.
We use a pair of (x, y) coordinates to (7,
locate a point in Processing 3)
.
.
Program Flow of Processing
.
Starts in setup(), the instructions there is done
for ONE time
.
Then goes to draw(), the instructions there will
REPEAT AGAIN, AGAIN, and AGAIN until the
sketch window is closed
.
.
Grammar of the Processing language
.
Mind the spelling
.
Put all the information inside parenthesis ( )
.
Use commas , to separate information
.
Use indentation to put instructions into blocks
.
.
mouseX and mouseY are keywords
indicating the horizontal and vertical
positions of the mouse cursor
Summary4 steps to use an image
4. Display the
image
at position (x, y),
with size (width,
height)
References