Notes:
Name your sketches using your name, the assignment number, and the question number, exactly as in this
example: LastnameFirstnameA1Q1.
Your programs must run upon download to receive any marks.
Submit one PDE file for each question.
Assignments must follow the programming standards document published on the course website on UMLearn.
After the due date and time assignments may be submitted but will lose 2% of marks per hour late or portion
thereof.
You may submit a question multiple times, but only the most recent version will be marked.
These assignments are your chance to learn the material for the exams. Code your assignments independently.
We use software to compare all submitted assignments to each other, and pursue academic dishonestly
vigorously.
Q1: Static character
Write a non-active Processing program (containing
no setup() or draw() functions) which will draw a
cartoon character on the canvas. You can draw any
character you like. Be creative. The rules for the
character are:
It must contain at least 6 shapes (lines,
ellipses, rectangles, or other shapes).
It must contain at least one line, at least one
ellipse or circle, and at least one square,
rectangle, triangle, or quadrilateral (quad).
It must contain a mouth that can open or
close if you change a constant (see Question
2). You can use any shape (or collection of shapes) you want for this.
The mouth and eyes must contain at least two parts each, e.g., in the example the mouth
has two elipses representing the mouth and a tongue (what about teeth?), and the eyes
have extra circles forming an iris and a pupil in each eye.
It should contain several different colours.
You should use a standard 500 x 500 canvas.
Your character must be capable of being drawn in any size, and in any position in the canvas.
This must be controlled by exactly three constants at the top of your program.
There must be one constant that controls the size of the character. It can be given any
appropriate name (such as HEAD_WIDTH or BUGS_HEIGHT), and control the size in
any suitable way. All other sizes must be calculated automatically from this one, so that
the entire character draws correctly no matter what value this constant is given. HINT:
use ratios to define element sizes, e.g., an eye may be 20% of the head width. HINT2:
Use float not int (the float type is covered at the start of Week 4).
ASSIGNMENT 1: Cartoons and Sketches
DEPARTMENT AND COURSE NUMBER: COMP 1010
2
There must be exactly two constants that control the position of the character, one for the
x direction and one for the y direction. The x constant should control where the centre
(left to right) of the character is. The y constant should control the position of the lowest
point of the character.
Give values to these three constants that make the character roughly half the width, and
half the height, of the canvas.
The marker will run your program and change these three constants, and nothing else,
and the character should draw correctly in any position and at any size.
o If the constants are too big or too small, some of the character might not fit in the
canvas. That’s OK.
o If the size is too small, the character might be distorted slightly if only int values
are used. That’s OK, too. But it should not be excessively distorted.
The three constants should be at the top of your program, and be clearly marked.
You should use other constants in your program, as appropriate. For example, if some x or y
coordinate, or size, is used many times, it should be calculated only once, and stored in a
constant. It’s OK to use simple things like MICKEY_HEIGHT/2, for example (if you have
something that’s always half the height of the character) without defining a constant.
Q2: Animated Character
Convert your program from Question 1 into an Active Processing program, with the mouse
controlling both the size of the eyes and how much the mouth is open.
Make the following changes and additions to your Question 1 program.
1. Save a copy of your original Question 1 program. You must hand in the original static
version, as well as this modified active version.
2. Create a setup() function, a draw() function, a
drawCharacter() function, and an animateCharacter()
function.
a. The setup() function should contain only the
size command.
b. The draw() function should contain only three
lines: calls to background, animateCharacter(),
and drawCharacter(). Nothing else.
c. All the rest of your code from Question 1
should be placed in the drawCharacter()
function.
d. Your program should run at this point before you go ahead. You will have to
make some changes as you work on part 3.
3. In your animateCharacter() function:
ASSIGNMENT 1: Cartoons and Sketches
DEPARTMENT AND COURSE NUMBER: COMP 1010
3
a. Set the eye size to be mouseX/5
b. Set the mouth size to be mouseY/5
c. Re-calculate all variables that depend on the
above changes to enable the mouth and eyes to
work properly. Remember to change the
appropriate constants into variables for this.
HINT: Do the eyes first, as this is easier. Make
sure all components scale properly, as shown
in the examples.
A sample program showing the correct behaviour of a
character is available in the file DemoA1Q2.zip. (This is a Windows version only. Use the
University’s open computer labs to view it if necessary.)
Q3: Etch‐a‐Sketch
Write an active Processing program that will make a point
(the “stylus”) move around the canvas, controlled by the
mouse, leaving a trail behind it. The mouse will control the
speed and direction of the stylus, as follows:
The value of mouseX should control the speed of the
stylus in the X direction. When the mouse is in the
exact centre of the canvas (from left to right), the
stylus should not move at all in the X direction. When
the mouse is at the left or right edge of the canvas, the
stylus should move at a high speed toward the left or
right. Use a constant to control this high speed, and
give it some reasonable value. The stylus’ speed
should increase and decrease smoothly when the mouse is between the center and edge of
the canvas.
Similarly, the value of mouseY will control the speed of the stylus in the y direction.
Draw a line from the previous stylus location to the new one, so that you have a
continuous trail.
The stylus should never disappear from the canvas. Whenever it reaches an edge of the canvas, it
should stop going in that direction. (This is the behaviour of the classic toy.)
Write your program in a similar way to Question 2, using a few global variables and constants,
and setup(), draw(), drawLine(), and moveStylus() functions.
This program will be quite short, if you do it correctly.
A sample program showing the expected behaviour is available as DemoA1Q3.zip.
ASSIGNMENT 1: Cartoons and Sketches
DEPARTMENT AND COURSE NUMBER: COMP 1010
4
Assignment 1 Marking Guide
Q1: Static Characters
Program execution (5)
o Program runs as handed in, and draws a character (1)
o Changing one constant moves it in the X direction (1)
o Changing one constant moves it in the Y direction (1)
o Changing one constant changes its size (1)
o Changing multiple constants at once has the correct effect (1)
Check code (2)
o Constants are used and named correctly (1)
o All other programming standards are followed (1)
Q2: Active Characters
Program execution (3)
o mouseX correctly controls eye size (1)
o mouseY correctly controls the mouth size (1)
o mouth and eyes have multiple components that scale correctly (1)
Check code (3)
o Specified four functions used correctly (1)
o animateCharacter() function uses reasonable code (1)
o All other programming standards followed (1)
Q3: Etch a Sketch
Program execution (4)
o Stylus moves at some constant speed for a stationary mouse (1)
o mouseX controls X speed and mouseY controls Y speed (1)
o Stylus caps properly to all four boundaries (1)
o Line (not series of dots) drawn behind stylus (1)
Check code (4)
o Reasonable state variables and global constants (1)
o Specified four functions used (may be more) (1)
o Reasonable code in moveStylus() (1)
o All other programming standards followed (1)
Grade: /21