Learning Processing 6

While this workshop wasn’t particularly helpful for my interactive project I can understand the merits of it. Using gravity is something that is very common in games and displays. The foundations of manipulating pixels to a “force” can then be transferred to several things including motion display as I intend to do on my project. Manipulating pixels is a huge part of installations and doing this in a way such as force with variants having an effect on the object/pixel that change depending on other aspects such as location and other forces.

processing6-1 processing6-2

Code:

PVector pos, vel, grav, force, centre, mouse;

void setup(){

size(800,800);

pos = new PVector(50,50);

vel = new PVector(10.8,0.6);

grav = new PVector(0,0.5);

force = new PVector();

centre = new PVector(0.5*width, 0.5*height);

strokeWeight(4);

}

void draw(){

background(255);

mouse = new PVector(mouseX, mouseY);

force.set(grav);

force.add(forceFromMouse());

vel.add(force);

vel.mult(0.99);

pos.add(vel);

bounce();

strokeWeight(8);

point(pos.x,pos.y);

strokeWeight(1);

line(mouseX,mouseY,pos.x,pos.y);

}

void bounce(){

if (pos.x > width) {

pos.x = width;

vel.x = -vel.x;

}  else if (pos.x < 0) {

vel.x = -vel.x;

pos.x = 0;

}

if (pos.y > height) {

pos.y = height;

vel.y = -vel.y;

} else if(pos.y < 0) {

pos.y = 0;

vel.y = -vel.y;

}

}

PVector forceFromMouse(){

strokeWeight(1);

mouse.sub(pos);

mouse.mult(0.01);

return mouse.get();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s