What is programming?

What is programming?
Maybe it helps you, to think about what programming is.

When writing a program you do a task, e.g. a game.

You break down the problem in small steps that you can handle. So you think of sub-task to accomplish the entire task. Each sub-task can be thought of as a paragraph in a text.

Your program in fact is a text to tell the computer what to do.

This text is written in simple english.

The crucial point is to tell the machine precisely and systematically what to do and where to start, what to do next etc.; it's mostly not so much about maths but about clear structured way from task to task to achieve the main task.

So think of you have a small brother or a robot or a servant and you have to tell him what to do. But he only does what you tell him and exactly how you tell him to.

So when writing the program, think of the task, think of the necessary steps / sub-task and make a plan. Follow the plan step by step and after each step test if that steps works. Sometimes you need to change the plan, but always have a plan.

To do the steps, please use the vocabularly of the programming language and the things you can do in the language (e.g. read a key, read mouse, have a loop or a condition, paint something on the screen).

When you are stuck, ask here or do some research in the tutorials or in the reference to broaden your vocabularly and the things you can do.

http://processing.org/reference/

Book online
You may also read online and for free

http://natureofcode.com/

Anyway.

The structure of a program
The structure of a program in processing (a "sketch") consists of

Procedure or sub-routine is just another word for a function.
 * setup a function that only runs once
 * draw a function that runs on and on
 * in-build functions that run when an event occurs, e.g. the mouse gets pressed or a key gets pressed
 * your own functions and classes that you can define

Variables
What are variables?

Imagine you want to let the user enter his name and you want to write "Hello, Julia" - thats great, you can use or but when she enters her name you don't know the name when writing the program - so when she enters the name, you have to store it and use it when giving it out.

That's what a variable is for.

Also when you want to do something 5 times, you need to count - also a variable is used to store your counting.

Think of a variable as a box with a lable: The lable is the name of the variable (what you see in your code: userName). The content is what it currently signifys: e.g. Julia. Also only certain type (String or int...) can fit into the box.

You can convert between different types of variables (see conversion in the reference).

As you can see when you store a name or a number that are different types, so you also need different types of vars (String and int...).

When you look in the reference

http://processing.org/reference/

you'll see in section primitives and Composite the types there are.

Fundamentals of mouse
When working with mouse you basically read where the mouse is and whether a button is pressed. There are functions automatically triggered when something like this happens (the function mousePressed is called automaticall when a mouse button is pressed).

See section mouse in the reference.

drawing
There is a coordinate system on the screen, 0,0 is upper left corner. When you paint, you use it. Two colors are in use: one for fill, one for outline.

See section 2D Primitives in the reference please.

conditions
Imagine you have a quiz and the user enters an answer. Now you need to check, whether it was right or wrong and give the message accordingly. That's what conditions are for: certain blocks / lines of code are executed when the condition applies, others if not so. The easiest is if...else..... Remember a block of code is marked by {  } In the reference please read (and try) the given examples of Relational Operators and Conditionals and Logical Operators.

Loops
Loops are also interesting.

They do a thing a few times. Over and over again. Read Iteration in the reference. The most important part is draw in processing which loops automatically in itself allowing for animation etc.

Look at for-loop etc. in the reference.

Relational operators
Relational operators can compare two values.
 * Equality
 * Inequality
 * Less Than
 * Greater Than
 * Less Or Equal Than
 * Greater Or Equal Than

Logical Operators
Logical operators can connect two boolean values. Hope this helps.
 * Logical And  -> processing.org/reference/logicalAND.html
 * Logical Or  -> processing.org/reference/logicalOR.html
 * Logical Not  -> processing.org/reference/logicalNOT.html