I want to give some guidance for beginners.
Mostly links to resources.
Other members, please feel free to contribute.
Thank you!
Best, Chrisir
What is programming?
Whenever you use a computer, a program is run by the computer, be it a game or a word processor. This program defines for the computer what to do with the input of the user (click a mouse on a button, enter textâŚ). A program is a operating instruction for the computer. So you go beyond using a computer to programming a computer. A user can later use a program that youâve written.
A computer program in processing is called a sketch. The commands and structures (if this do thatâŚ) must be precise, like a dumb friend you have to tell him exactly what to do.
Now you can program your own word processor or create art, either a fixed piece of art (house) or something thatâs generative (it looks slightly different every time you run it because itâs controlled by random and algorithms) or with animation (movement) or make a game.
Programming can be a great hobby. Imagine a Workshop in your basement with a work bench where you make a marble track or a steam engine as a Hobbyist. Similar you can make fancy programs and create textual or graphical worlds and machines. Be creative!
But similar to a steam engine you need to follow certain rules:
- A steam engine consists of different parts, so does your sketch. Each part has its own task but they work together.
- You need a plan to build a sketch. The plan might be rough or unfinished yet but you need some kind of planning ahead.
- Instead of building the engine at once you want to build it piece by piece. Similar with a sketch: Break your problem down into steps and program it step by step. Try also to put your code in sections / functions to make the steps visible in your code (modularizaton).
- Instead of finishing the entire steam engine before running it the first time, you want to test the single parts that you build. Similarly, always try to have a running sketch, simple at first but then getting more complex. When you run it often, you can test while you work and make sure everything is working. Running after a long long period of time will confront you with lots of errors. Running often youâll find whatâs causing the error: The part you changed the most recently.
- You want to keep the engine nice and shiny and so in your code from time to time you gotta do some house cleaning: Delete rests from old approaches, rename variables and functions in a better way (expressing more clearly their function), insert and check commentsâŚ
Hints:
- Start small. Save often, even with a new name for the sketch (ballGame1, ballGame2âŚ).
- Donât start with building a cathedral. Start with a shed.
- Use ctrl-t to auto-format your code.
Read more:
and: https://github.com/Kango/Processing-snippets/wiki/programming-and-functions
What are variables?
If you want to display a ball at screen position 310, 200, thatâs fine. But if you want to move the ball, it gets hard. You need to add something to 310 and display the ball at 320,200 in the next scene. And then at 330,200. This ainât possible with fixed numbers. Instead you need variables like ballX,ballY and use them for displaying the ball. They contain the value 310,200 but in a loop (draw() loops in itself automatically) you can add your speed to the position: ballX = ballX + 10;
What are functions?
See: https://github.com/Kango/Processing-snippets/wiki/programming-and-functions
What is object oriented programming?
See https://github.com/Kango/Processing-snippets/wiki/Object-Oriented-Programming
See https://github.com/Kango/Processing-snippets/wiki/Variables,-Arrays-and-object-oriented-programming
Typical Problems for beginners
-
How to make a ball fly I outlined above.
-
The command fill() must be before the command the fill color is applying to (rect() or ellipse() etc.)
-
Often I see people use a mouse input but the text they want to display flashes only briefly. To avoid that set a variable
mouseHasBeenClicked
to true and evaluate the variable using if. Before setup sayboolean mouseHasBeenClicked = false;
. -
Normally a line ends with â;â. This is not true for
if
-clause! This expression wonât work:
if(mouseHasBeenClicked); // wrong semciolon ; !
text("Hello", 20,20);
instead consider:
if(mouseHasBeenClicked) // no semciolon ; !
text("Hello", 20,20);
- Difference between mousePressed and mousePressed(). The first without the () is a variable (boolean), the 2nd a function, marked by the (). When you want to draw with the mouse continuously, use mousePressed as a variable since it registers multiple clicks. When you want a single click event use the function
mousePressed()
. It gets called automatically by the way.
See: https://forum.processing.org/two/discussion/8093/frequently-asked-questions
Error Messages
There are different kind of error types and messages. When asking about an error in the forum, state the error message, the line number and show your code.
Often processing just knows something is wrong but states a wrong error. E.g. missing â)â when no â)â is missing. Start by reading the passage closely and check for missing ;
at the end of line or missing variable types in function parameters etc.
Collision
For Collision see: http://www.jeffreythompson.org/collision-detection/table_of_contents.php
More code at: https://processing.org/examples/circlecollision.html
Advanced topics
Read more
See tutorials here: https://www.processing.org/tutorials/
Examples: https://www.processing.org/examples/
Books: https://www.processing.org/books/ - especially Nature of Code
Handbook: https://www.processing.org/handbook/