Processing Day 6: Variables Part 2

Today I’ll show an example of another lesson about variables from the tutorial I’ve been watching titled “Interactive Data Visualization with Processing” by Barton Paulson. In this particular example a variable is incremented which makes it move across the screen.

Below you can see the example (figured out you can embed Processing animations into your site code from Very cool! (Refresh your browser to see it again). I am still figuring this out.


// video: modifying variables

int x = 10;
float y = 50;
float z;

void setup() {
size (600,200);

//assign a new value to an existing variable
y = height;

//casting a variable
float randomFloat = random(11); //lower end inclusive (can include 0)
//upper value exclusive, e.g won't go up to 11, only 10
println("randomFloat = " +randomFloat);

int randomInt = int(random(11)); //this gets rid of decimal places from before
println("randomInt =" + randomInt);

int randomDie = int(random(6)) + 1;
println("randomDie = " + randomDie);

z = 3*x + atan(sqrt(y));
println("z = " + z);

void draw() {
ellipse(x, y, 40, 40);

//increment it to make it move
//takes a variable and adds a value you to it every time it runs through a cycle
y*=0.99; //the y value actually decreases, so circle moves up

x = constrain(x, 0, width/2);



Click here to view the actual animation on