Learning Processing: Chapter 4

CHAPTER 4: Variables

Chapter 4 is the start of 'Lesson 2' focussing on the rest of the basics of programming: variables, conditionals and loops.

A variable is a pointer to a location in the computers memory where a value is stored. This value can vary hence the name. The chapter introduces the different types of variables; int, float, boolean, char, byte, short, long and double. Each should be used in a different circumstance depending on the need, the book explains where to use each one clearly and concisely. Variables can be named, and addressed in a sketch. for example mouseX is an integer storing the mouses X-coordinate - this is a system-wide variable, one already established in processing, these are mainly commonly used variables (e.g. frameCount) and so have been built into the language.

The exercise for using system variables gets you to create a little picture out of basic geometry that will scale itself accordingly when you change the size of the window. I thought that the large square was itself a square and not the bounds of the size therefore my code is somewhat different to the code posted on Shiffmans website as I shall ellaborate on.





Shiffman's Code:



random()
is another function you learn how to use in this chapter. It focusses on using it in variables to create movement (e.g. Zoog the alien moving from side to side). The syntax is as follows random(low value bound,high value bound) - It's pretty easy to start implementing random values into your sketches after learning the basics.