1. Introduction, graphics, variables

Course structure, aims, assessment. A brief history and overview of programming languages (slides). Walkthrough of the Processing user interface.

Special characters

… and how to type them on a Finnish Mac keyboard. We’ll need many of these when typing in our programs, since they have special meanings. Finnish translations for the non-obvious ones included:

  • parentheses ( )
  • square brackets (hakasulut) [ ] – alt-8, alt-9
  • braces/curly brackets (aaltosulut) { } – alt-shift-8, alt-shift-9
  • asterisk *
  • slash (kauttaviiva) /
  • pipe (putki) | – alt-7
  • ampersand &
  • equal sign, “is” =
  • colon :
  • semicolon ;
  • comma ,
  • hash (“risuaita”) #
  • tilde (“mato”) ~ – alt-^-space
  • single quote (heittomerkki) – note that this is not the same as accent ´
  • double quote (lainausmerkki)
  • less/greater than < >

Program flow

Statements are executed (“run”) sequentially line by line. The order of the statements is crucial: changing it will result in completely different end results. Comparable to a cake recipe: there’s ingredients (data) and instructions what to do (program code, statements).

Basic graphics with Processing

size, background, point, ellipse, rect, fill etc. See the Processing reference for a complete list of graphical primitives supported by the language – there’s a lot at your disposal. An example sketch: simplegraphics.pde

Variables (muuttujat)

We could consider variables “boxes”, where you can store things. During the following lectures they will be used for several purposes such as counters, for holding status information such as mouse coordinates and for making the code more readable. In Processing every variable has a type, a name, a value and a scope. Before we can use a variable we need to declare (esitellä) it, which looks like this:

int whatever;

The type in this case is int, an integer number (kokonaisluku). The name we can choose freely, except that it can’t overlap with reserved words of the language. The value is set through assignment (sijoitus):

whatever=100;

Finally, the scope is the area where a variable is visible. It can be global (yleinen) or local (paikallinen). More about that later. An example with a variable declaration and use: onevariable.pde

This entry was posted in Processing. Bookmark the permalink.