High School level (years 9-10 in Australia, ages 14-16) introduction to programming course, based on the language Processing, includes class material, exercises, examples, and tests. Exercises for Class 2.
1. Introduction to programming: Class 2 Exercises
• Processing “Exhibition” examples
– A few more
• http://processing.org/exhibition/works/starnursery/index_link.html (Needs
Quicktime) Software for the R.E.M. video Animal (youtube, screenshot next
slide)
• http://processing.org/exhibition/works/yellowtail/index_link.html
All the material for the Programming Elective will be put into sub-directories as follows:
Exercises
Lessons (powerpoint presentations)
Textbook (a PDF copy of the textbook)
Students (save your programs here for sharing and reusing)
For the rest of the exercises you need to open the text book (a PDF file) from the Textbook directory.
You’ll also need to have this document open (or printed) and the Processing environment and editor
running to try the examples with.
Have a go at all the exercises below.
PAGE 9
Example 2-1: Draw an Ellipse
In the editor, type the following:
ellipse(50, 50, 80, 80);
This line of code means “draw an ellipse, with the center 50 pixels over
from the left and 50 pixels down from the top, with a width and height of
80 pixels.” Click the Run button.
• PAGE 10 Ex 2.2
– Add 2 variables for white (255) and black (0).
– Where do mouseX and mouseY come from?
2. – You can make special variables called CONSTANTS than can only be assigned to once
and never change their value
• final int WHITE = 255;
• final int BLACK = 0;
• final int GREY = WHITE/2;
• Try changing their value after first assignment...?
• E.g. WHITE = BLACK; // ???
• PAGE 14 top, right-click on orange text in editor and get help!
• Chapter 3 Draw
– X and y coordinates
– Functions and parameters
• Page 16 Ex 3.1
– size()
• Page 16 Ex 3.2
– point()
– Use the height and width system variables if you like
• Basic shapes
– Do up to Ex 3.7
• Drawing order Page 22 Ex 3.9-3.13
– Processing programs executed in order
– Shapes drawn later are drawn over the top of earlier shapes
• Colour (Page 26)
– Gray scales (white = 255, black = 0)
– Ex 3.14, Ex 3.15
– Page 28 Ex 3.16 Colour (RGB) Additive colour model see next slide
• What’s the difference between fill(255) and fill(255, 255, 255)?
– Try the colour selector
3. • What’s pure red? Pure green? Pure blue? How do you get orange? Yellow?
Purple?
• color is a Type in Processing (remember it was invented by Americans so
NOT COLOUR)
• color orange = color(255, 132, 0);
• fill(orange);
• Try making some fruit and vegetable color variables and displaying them all
on the screen – in a bowl? (see below).
• E.g. Orange, tomato, apple, watermelon, grape, banana, pear, etc.
– Ex 3.17 transparency
Can you draw a bowl? Hint: P. 20 arc() function