Punctuation
The most important punctuation you will master in Processing are the braces that enclose a block of statements { } and the semi-colon that terminates each statement ;. You will make many errors learning how to place these properly and remembering to do so. A common complaint is that they don't seem necessary. However, computers, as mentioned above, are not able to just "get what you mean."
Braces {}: These enclose any group of statements that need to be treated as a unit. The most common way you will use them is to replicate the way Scratch blocks "enveloped" other blocks. For example, the if statement in Scratch has a slot that contains the statements that are to be executed if, and only if, the conditional statement is true.
Braces {}: These enclose any group of statements that need to be treated as a unit. The most common way you will use them is to replicate the way Scratch blocks "enveloped" other blocks. For example, the if statement in Scratch has a slot that contains the statements that are to be executed if, and only if, the conditional statement is true.
Drawing
Mouse Interation
Note that there is no 'circle' function. Of course, a circle is just a special form of an ellipse, much in the same way that a square is a special form of a rectangle. 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."
All of your Processing applications to this point have followed this format. The interpreter starts at the top of the source and executes each function or command in sequence as it moves down the list of instructions.
However, most basic programs in Processing follow a slightly more complex model, and this provides the framework for dynamic programs. In order to animate objects on the screen, we need to redraw the screen quickly while re-orienting the objects as they move (much as in film—as discussed earlier).
Processing provides this framework through the setup() and draw()functions. Up to now, you have used Processing functions to draw ellipses and rectangles or change colors. Processing includes these pre-written functions, and you, as the programmer, determine when and where they are used.
In this assignment, you will do something completely different. In fact, you and Processing will switch roles in a way. Processing will execute the setup() and draw() functions automatically to start the program and constantly redraw the screen. You will define what each of these functions actually does when Processing uses them.
All of your Processing applications to this point have followed this format. The interpreter starts at the top of the source and executes each function or command in sequence as it moves down the list of instructions.
However, most basic programs in Processing follow a slightly more complex model, and this provides the framework for dynamic programs. In order to animate objects on the screen, we need to redraw the screen quickly while re-orienting the objects as they move (much as in film—as discussed earlier).
Processing provides this framework through the setup() and draw()functions. Up to now, you have used Processing functions to draw ellipses and rectangles or change colors. Processing includes these pre-written functions, and you, as the programmer, determine when and where they are used.
In this assignment, you will do something completely different. In fact, you and Processing will switch roles in a way. Processing will execute the setup() and draw() functions automatically to start the program and constantly redraw the screen. You will define what each of these functions actually does when Processing uses them.
Keyboard Interation
Processing is not restricted to mouse movement for input and output. In this activity, you will extend your figure from Animate Your Figure (Links to an external site.) to incorporate keyboard button presses as well. In order to do so, you will use a variety of pre-built variables for keyboard input similar to the mousePressed variable.
As usual, you should read and reference the Processing Documentation (Links to an external site.) in order to understand the use of these constructs. However, here is a brief outline of how the keyboard input system in Processing works.
As usual, you should read and reference the Processing Documentation (Links to an external site.) in order to understand the use of these constructs. However, here is a brief outline of how the keyboard input system in Processing works.