Processing

"Processing is an open source programming language and environment for people who want to program images, animation, and interactions."

basic self learning notes

• int - integer. they can be signed (neg and positive) or unsigned (all positive) values. unsigned values can hold larger values than signed values because the unsigned values have to have an extra bit in front to store whether the number is positive or negative.
• float - floating point numbers which have decimal place - used to approximate analog and continuous values
• char - character or letters. but note that although you CAN add them, a+b wont equal ab or c or what you probly expect.
• boolean - true/false values. in c++ its bool. true and false thusly are reserved words.
• string - sequence of characters
• byte - datatype for bytes (8 bits of information storing numerical values) info that cant be stored by other strings or other numbers
• long - very large non-floating point numbers.
• arrays:
int[] numbers = new int;
numbers = 122;
numbers = 29;
numbers = 10
// the name of the array is numbers. the square brackets is what indicates its an ARRAY

int arr[] = {1,2,3};
int arr = {1,2,3};
// both these are fine, array does not need number length assigned
• casting: to convert integer to float (decimal number). you cannot just make k (3) into 3.0 by making it float j = k. type cannot be just changed like that. cos 5 is not the same as 5.0, totally..... you can cast a char to a integer and back again. the only thing you cant cast is an array.
int k = 3;
float j = (float)k;
// float is now 3.0 instead of 3
• basic operators (again!)
+= adds value on the right of the value
int height = 5;
height += 1; // now its 6
height += 20 // now its 26

-= subtracts value
int width = 20;
height -= 1; // now its 19
height -= 10 // now its 9

++ -- add minus
int size = 2;
size++; // now its 3
size--; // now its 2

== equals
!= not equal to
> greater than
< less than
>= greater than or equal to
<= lesser than or equal to
&& and
|| either statement

• conditionals (for, if, while)
if (condition){
result if true
} else {
the other result if false
}

for (i=0; i < 10; i++) {    // first one initialises counter, second one continues until false, third one passes the loop
print(char(i)+", ");   // this prints 1, 2, 3, 4, 5, 6, 7, 8, 9,
}

while(trueOrFalse{
//do something each time if its true
}

while (i<10){
print ("hello "+i);
i++; // if there is no increment it will be infinite looop
}

for (int i=0; i<10; i++){
if (i % 2 == 0){
continue;
}
print(i + " is not divisible by 2 \n");
}

this will print:
1 is not divisible by 2
3 is not divisible by 2
5 is not divisible by 2
7 is not divisible by 2
9 is not divisible by 2
• break in conditionals
break is for breaking loops

int[] intArr = {1, 2, 3, 4, 5, 6, 12, 34, 199}
int counter = 0;
while(counter < intArr.length){
if(intArr[counter] == 5 {
print("found the number 5 in the array");
break;
}
counter++;
}
// code continues here after break
print(counter); //
• functions
int moneyReceived(int x){    // int is what it returns, the name is moneyReceived, the parameters are int x
myBank += money;      // this is what the function does
return myBank;
}