0% found this document useful (0 votes)
9 views19 pages

Week 02

The document outlines the curriculum for Week 2 of the SM2715 Creative Coding course, focusing on the basics of programming including data types, control statements, and arrays. It includes a review of concepts from the previous week, introduces structured programming with setup and draw functions, and discusses mouse events. Additionally, it features multiple-choice questions for self-assessment on programming concepts.

Uploaded by

7020ohiawneuy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views19 pages

Week 02

The document outlines the curriculum for Week 2 of the SM2715 Creative Coding course, focusing on the basics of programming including data types, control statements, and arrays. It includes a review of concepts from the previous week, introduces structured programming with setup and draw functions, and discusses mouse events. Additionally, it features multiple-choice questions for self-assessment on programming concepts.

Uploaded by

7020ohiawneuy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

SM2715 Creative Coding

Week 2
(more) Basics of Programming

Dr. Manfred Lau


Review of Last Week
• Data Types: int, float, boolean, char, color
• Control Statements: "if else” statements, "for” loop, "while” loop
• Colors: Grayscale, RGB
• Transparency value
fill(162,200);
or fill(255,255,0,50);
Weekly Schedule
Week 01 Introduction, Assessments
Basics of Processing/Programming
Week 02 (more) Basics of Programming
Week 03 Functions and Classes
Week 04 Image Processing
give Assignment 1 (30%)
Week 05 Image Processing
Week 06 Video Processing
Week 07 Consultation for Assignment 1
Array (a set of elements)
Multiple-Choice Question
The code on the right creates an
array that has elements with
which of the follow indices?

(a) 0 1
(b) 0 2 -These Multiple-Choice Questions
are not assessed. They are just quick
(c) 1 2
questions to test your own understanding.
(d) 0 1 2
(e) None of the above
Array
• Useful for storing multiple values
• Compare between these two examples to store values
and compute their average:
Array
• Example to draw the array values
STRUCTURE AND FLOW OF PROGRAM
- void setup(): called first and called one time. Usually
we put the functions to initialize the settings there.
For example, size(), background(), fill(), etc.
- void draw(): continuously run the lines in this
function until the program is stopped, or noLoop() is
called.
UNSTRUCTURED PROGRAM
- Does not contain setup() and draw()
functions
- "Static" only: no motions and no user
interaction
EXAMPLE 1 WHERE TO PUT BACKGROUND()?
Compare these two:
EXERCISE 1

Write a structured program that:


- gives a display window of
dimension 600x300
- has a changing background
color: starts at black color,
then slowly change from black
to white
MOUSE EVENTS
These are keywords, with special colors.
- mouseX, mouseY
- cursor(), noCursor()
- pmouseX, pmouseY
MOUSE EVENTS
- mouseMoved(), mouseDragged()
- mousePressed(), mouseReleased(), mouseClicked()
- mousePressed returns true or false
- mouseButton returns LEFT, CENTER, or RIGHT
EXAMPLE 2
translate() function (0,0) X-axis

Y-axis
(0,0) X-axis

Y-axis
Multiple-Choice Question

What values of (tx,ty) will draw


the image on the bottom right?

(a) (0,0)
(b) (50,50)
(c) (250,250)
(d) (350,350)
(e) (450,450)
Multiple-Choice Question
How many values are there in the
variable “array2D” after running
the code on the right?

(a) 9
(b) 10
(c) 81
(d) 100
(e) 200
Multiple-Choice Question
How many times is the factorial
function actually called in the
code on the right?

(a) 0
(b) 1
(c) 3
(d) 5
(e) 10
Class (a group of related variables, and
functions to compute something with them)

You might also like