ā Specifying pixel coordinates.
ā Basic shapes: point, line, rectangle, ellipse.
ā Color: grayscale, āRGB.ā
ā Color transparency.
1.1 Graph Paper
This book will teach you how to program in the context of computational media, and it will use the development environment Processing (http://www.processing.org) as the basis for all discussion and examples. But before any of this becomes relevant or interesting, we must first channel our eighth grade selves, pull out a piece of graph paper, and draw a line. The shortest distance between two points is a good old fashioned line, and this is where we begin, with two points on that graph paper.
Figure 1.1 shows a line between point A (1,0) and point B (4,5). If you wanted to direct a friend of yours to draw that same line, you would give them a shout and say ādraw a line from the point one-zero to the point four-five, please.ā Well, for the moment, imagine your friend was a computer and you wanted to instruct this digital pal to display that same line on its screen. The same command applies (only this time you can skip the pleasantries and you will be required to employ a precise formatting). Here, the instruction will look like this:
Congratulations, you have written your first line of computer code! We will get to the precise formatting of the above later, but for now, even without knowing too much, it should make a fair amount of sense. We are providing a command (which we will refer to as a āfunctionā) for the machine to follow entitled āline.ā In addition, we are specifying some arguments for how that line should be drawn, from pointA (0,1) to point B (4,5). If you think of that line of code as a sentence, the function is a verb and the arguments are the objects of the sentence. The code sentence also ends with a semicolon instead of a period.
The key here is to realize that the computer screen is nothing more than a fancier piece of graph paper. Each pixel of the screen is a coordinateātwo numbers, an āxā (horizontal) and a āyā (vertical)āthat determine the location of a point in space. And it is our job to specify what shapes and colors should appear at these pixel coordinates.
Nevertheless, there is a catch here. The graph paper from eighth grade (āCartesian coordinate systemā) placed (0,0) in the center with the y-axis pointing up and the x-axis pointing to the right (in the positive direction, negative down and to the left). The coordinate system for pixels in a computer window, however, is reversed along the y-axis. (0,0) can be found at the top left with the positive direction to the right horizontally and down vertically. See Figure 1.3.
Exercise 1-1: Looking at how we wrote the instruction for line āline(1,0,4,5);ā how would you guess you would write an instruction to draw a rectangle? A circle? A triangle? Write out the instructions in English and then translate it into ācode.ā English:_________________________________________________________________
Code:_________________________________________________________________
English:_________________________________________________________________
Code:___________________________________...