Will Price Posts About

Learning Processing: Chapter 3

Chapter 3: 'Interaction'

Chapter 3 covers the 'flow' of a program; what setup() and draw() do and how to use them, mouse interaction, dynamic sketches and finally handling events (mouse clicks and key presses).

I've learnt that setup() is run only once when the sketch is run, it sets the 'initialization code' as Shiffman puts it. After setup(), draw() is run, this runs, then loops back to the start of the code:

void setup() {
//setup code
}

void draw() {
//code which loops
}

The { } host a 'block of code' allowing one to manage code as an individual part of a program.

MOUSE FUNCTIONS:
mouseX - the current mouse x-coordinate
mouseY - the current mouse y-coordinate
pmouseX - the mouse x-coordinate in the previous run through draw()
pmouseY - the mouse y-coordinate in the previous run through draw()
void mousePressed() - function that runs code when a mouse button is pressed
void keyPressed() - function that runs code when a key on the keyboard is pressed


I feel I have a good understanding of all the above, I am starting to realise how one goes about programming and how hard it will be in future implementing features, it shall definitely improve my logic, something I have been looking forward to doing, it's not very often we get stretched in school!

This chapter completes 'Lesson 1' which covers the beginning of learning to program in processing. The end of lesson project is to create a dynamic sketch by interaction of the mouse and a static drawing. I have drawn a few things and added dynamics to them, currently I can't figure out how to export programs that actually display in webpages out, once I figure that out, they will be posted here.