In this tutorial we'll take a look at how to do arithmetics and how to get the results of your code.
setup() and draw()
In processing there are two main types of functions that tell the computer how to run the code. The setup() function tells the computer to run once and draw() tells it to loop forever. You don't have to use these, but we won't be looking at other alternatives in this tutorial.
The syntax is: "void setup() {...}" and
"void draw() {...}". Scroll down to see examples. Will take a closer look on what functions are and how to define your own function in a later tutorial.
Arithmetics
The symbols used for arithmetics in processing are very much like the ones we use normally.
+ is addition
- is subtraction
* is multiplication
/ is division
% is modulo
= or == means equal to (== is used for conditions)
< means less than
> means greater than
!= means unequal to
If we want to add 1 to a number we can write "++" behind it, and we can do the same subtracting 1 if we write "--". If you want to add a different value you can write "+= value". You can do the same with subtraction, multiplication and division by replacing + with -, * and / respectively.
Showing results
The commands print(...) and println(...) will display any variable inside of the parenthesis in the console. The number will appear in the bottom left corner. The print() tells the computer to display the variable. The println() tells the computer to display the variable and go to next line. Using the print will display the numbers right next to each other without any spacing between, so I mostly use println().
Example

As an example I've made a program that makes the fibonacci sequence. It is very important that f1 and f2 are defined outside of the draw() because if we don't do that the program will set both f1 and f2 equal to 1 each loop.

I also used the delay() where the number inside the parenthesis is the amount of milliseconds I want the program to wait for.
to end every line (except the empty ones and the ones with curly brackets) with ";". That tells the computer that it's the end of the command and it should go to the next command.
In the next tutorial we will take a look at if, for and while statements, and depending on the length of the post maybe a little more.
Later broskis
-Bearrito

Comments (5)
10 props :3