...
Code Block |
---|
int length1 = 150; int length2 = 200; size(300,300); // define window size background(0); // define background colour stroke(255,255,255); // define line colour line(100,10,100,length1); // draw a line line(150,10,150,length2); line(200,10,200,250); fill(0,0,0); // fill colour strokeWeight(5); // line thickness ellipse(100,length1,50,50); // draw an ellipse ellipse(150,length2,50,50); // draw an ellipse noFill(); // turn off fill ellipse(200,250,50,50); // draw an ellipse |
Operators
An operator is a symbol that tells Processing to perform a simple task, like for arithmetic and logic.
+ Addition
/ Devision
- Subtraction
* Multiplacation
These you already know but there are some very useful arithmetic operators you may not have seen in the following example .
Code Block |
---|
int x1 = 10;
x1++; // increment value by one
x1--; // decrement value by one
x1 += 2; // Add assign, this is the same as writing x1 = x1+4;
x1 -= 2; // Subtract assign, this is the same as writing x1 = x1-4;
x1 /= 2; // Divide assign (less common), this is the same as writing x1 = x1/2; |
Exercise 2:
Take your results form exercise 1 and modify your code to use variables. Create a variable X and variable Y that can be used to position your graphic on the screen.