Advanced Programming


Back to Index

Processing

A visual language, Processing is based on Java's syntax.

Day 1Day 2

A Smiley

Pre-Classes Exploration

A first, basic exercise; I did it mostly on my own, learning about different shape attributes (every shape needed coordinates, dimensions, starting and ending points for the arc and line)Before we started on classes, I made a few mostly based on the example code from the documentation. Each object collides relative to its edges, and can have different starting positions, sizes, and directional momentum.

Class: an "object" that reacts and functions depending on what functions it was defined to do by the programmer.

A House

Bouncing Balls

An independent exercise in using different shapes again. After I made this, I tried to implement texture before I found that the editor couldn't support the texture function.Instead of manually specifying each ball, loops and lists organize them and spare the programmer. Java and Processing list syntax is a little weird; it's predetermined how long each list should be and what classes they contain. The balls are supposed to be randomly colored; I proofread the part where the color is chosen, and the syntax is the same as Mr. Farrell's example, so the error is buried somewhere.
Example texture code from the documentation:


With texture function:


Without texture function (normal vertex-determined shape under P2D graphics):
Loop syntax:

After specifying that it's a 'for' loop, the arguments inside include the definition of i as a variable with the value of zero, the statement telling that the loop should stop after looping each entry in the 'balls' list, and how much the variable should increase for each loop (++ means add 1).

Class syntax:

In this, the first line defines the name as a class, the next couple determine variables required and function usage, and from there on is free reign for the programmer to program.

Bouncing Ball

Using velocity to determine movement, the ball can slow down and speed up as gravity acts. Every loop tick, the ball's velocity changes its position before being drawn; there's also small statements testing for whether the ball is on the edge, so it can bounce back with its reflected velocity.