...
Let's take the Example 1 and expand it to use events:
Code Block |
---|
int length1 = 0; int length2 = 0; void setup() { size(300, 300); // define window size smoothbackground(0); // define background colour stroke(255, 255, 255); } // define line colour } void draw() { background(0); length1 strokeWeight(1)= mouseX; length2 = mouseY; line(100, 10, 100,150 length1); // draw a line line(150, 10, 150,200 length2); line(200, 10, 200, 250); fill(0, 0, 0); // fill colour strokeWeight(5); // line thickness ellipse(100,150 length1, 50, 50); // draw an ellipse ellipse(150,200 length2, 50, 50); // draw an ellipse noFill(); // turn off fill ellipse(200, 250, 50, 50); // draw an ellipse } |
In this program we use two special functions:
- void setup ()
- void draw ()
These functions accept no parameters so the space between the brackets is left blank, and they have no return value so the 'void' keyword is used . The function names are reserved names that Processing knows, Processing calls these (this will make more sense when we look at writing our functions). Processing calls the setup functions as soon as the corresponding event occurs.program starts, and the draw function every time the screen refreshes. We will use these two functions for all of our future processing sketches.
Exercise 3:
Take your results to form exercise 2, and modify it so it animates across the screen.
...