...
A variable is a placeholder for a value. Variables are also stored in the programming for a memory location that is filled with a value. Variables need to be defined with a data-type, to define its storage space requirements. The name of the variable must start with a letter, but can it may contain numbers in within the wordname. In processing, variable names are case-sensitive.
...
Code Block |
---|
// variable Declaration int x1 = 15; // an integer i.e a whole number float valF = 0.323; // a floating point number i.e a numbers with a decimal point boolean bFlag = false; // a true or false value i.e a single bit value String message = "hallo 1"; // a collection of characters char character = 'g'; // a sigle character. Note the different quotation marks String msg1 = new String("hallo 2"); println(x1); println(valF); println(bFlag); println(message); println(character); println(msg1); |
We can also makes make copies or combine variables.
...
An operator is a symbol that tells Processing the computer to perform a simple task, like for arithmetic and logic. particular arithmetic or logic operation. Some of the most common operators are:
+ Addition
/ Devision
- Subtraction
...
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+2; x1 -= 2; // Subtract assign, this is the same as writing x1 = x1-2; x1 /= 2; // Divide assign (less common), this is the same as writing x1 = x1/2; |
Exercise 2:
Take your results form from 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.