
Step 01: The Processing Setup
import processing.pdf.*;
boolean recording;
PGraphicsPDF pdf;
//Declare//
// Square Brackets is an array or collection//
Boxie [] boxieCollection = new Boxie [120];
void setup() {
background(#000000);
size(1024, 600);
smooth();
pdf = (PGraphicsPDF)
createGraphics(width, height, PDF, "bounxerz.pdf");
//Initalize//
for(int i = 0; i < boxieCollection.length; i++){
boxieCollection[i] = new Boxie(random(0, width),
random(0, height));
}
}
void draw() {
//Display FUNCTION called in Class//
for (int i=0; i < boxieCollection.length; i++){
boxieCollection[i].run();
fill(255-i*20, 255, i*20, 50);
}
}
void keyPressed() {
if (key == 'r') {
if (recording) {
endRecord();
println("Recording stopped.");
recording = false;
} else {
beginRecord(pdf);
println("Recording started.");
recording = true;
}
} else if (key == 'q') {
if (recording) {
endRecord();
}
exit();
}
}
Bear in mind, that the code above allows you the ability to export your composition into a PDF. “R” is to record then you press “Q” to quit the process.
Step 02: The Class
class Boxie {
//GLOBAL VARIABLES: Speed, Location//
float x = 0;
float y = 10;
float speedX = 1;
float speedY = 2;
float gravity = 0.01;
//CONSTRUCTOR: How you build the class;
what does the class need to work - call variables//
Boxie(float _x, float _y){
x = _x;
y = _y;
}
//FUNCTIONS: How to break down complex behavior;
call separately//
void run(){
display();
move();
bounce();
gravity();
}
void bounce(){
if(x > width){
speedX = speedX *-2;
}
if(x < 0){
speedX = speedX *-1;
}
if(y > height){
speedY = speedY *-2;
}
if(y < 0){
speedY = speedY *-1;
}
}
void gravity() {
speedY = speedY - gravity;
}
void move() {
x += speedX;
y += speedY;
}
void display(){
rect(x, y, 15, 15);
}
}
The above code defines things such as: Gravity, X / Y boundaries, etc.
This is my first foray into procedural art. I watched MANY tutorials and read MANY pages in several books on using code to create art. While procedural art has been around for a long time, it hasn’t always been so popular. Most people know or have heard of “fractals.” I plan on opening up my source code to the public soon. As I have learned from other artists who have made their code open, I wish to do likewise. I feel that there is a type of freedom in sharing the “secrets” for creating such complex and beautiful compositions.