Processing

Processing is a Java-like language that was created for visual designers and graphical artists. You can run it from your desktop but there are a number of webpages where you can create and save Processing sketches. We went to Sketchpad.cc, where they even let you look at what other programmers are making using Processing! Here's the output from an example file on sketchpad.cc:

Syntax

We learned to use variables, loops and conditionals in Processing. It's different from Python, and it's more like Java!


For example, this is how I made a function to draw a smiley face. I put all the code in curly brackets and called "smiley()" in the main loop:


House

We used rectangles and triangles to make a house:


Conditionals

We used conditionals ("if" statements) to make a ball bounce around the screen:


This is the output of the bouncing ball program:

Advanced Programming

Classes

On Wednesday we learned how and why to use classes. We looked at the one bouncing ball in yesterday's "bouncing ball" code and asked how we could add more balls to the screen. To get 10 balls on the screen, obviously it would take 10 times as many lines of code, with all the x-positions, y-positions and so on. All those variables would be hard to keep track of! There's a better way: classes.

There's a type of programming called "Object-Oriented Programming" or "OOP" that makes it easy to organize all the code in a family of objects the way functions made it easy to organize the code of a bunch of commands.

For example, we wanted to create a bunch of balls with different positions, velocities, even sizes and colors. So we made a Ball class this way:


Then we could create a "new Ball" by declaring all those parameters. We ended up just doing it randomly:


Now we could have 10 balls bouncing around or 1,000 just by changing one number in the code.