processing workshop 6, 7, 8, 9 JULY 11:00 - 18:00
IKA - akademie of fine arts 2 floor
Built with Processing
/**
* a_single_soul is a quick simulation of a single human running around
* @author: Processing Workshop @ IKA 09 ika/akbild.ac.at
* @version: 1.0
*/
MENSCH M; // Define a variable M of the class MENSCH
void setup() { // setup define the basic layout of your sketch
size(300,300); // set Size of the Window to 300/300
frameRate(12); // frameRate try's to call draw function 12 times / second
M = new MENSCH(); // initialize variable M with calling the MENSCH() constructor
}
void draw() { // use this function to draw elements to the screen
background(255); // set the background to white
M.Update(); // call the Update() Method of the Class MENSCH
M.Render(); // call the Render() Method of the Class MENSCH
}
/**
* MENSCH is a class for www.processing.org
* MENSCH will simulate a human running around
* @author: Processing Workshop @ IKA 09 ika/akbild.ac.at
* @version: 1.0
*/
class MENSCH {
PVector PVPos, PVDir; // PVPos = current Position, PVDir = current Motion
float Size; // Size = personal Space of each Human
final float MaxSpeed = 3.0; // MaxSpeed = 3.0 m/s
MENSCH() {
this.Size = random(2,5); // define a personal space between 2 and 5 Meters
this.PVPos = new PVector( random(width),random(height) ); // position MENSCH somewhere into the Window
this.PVDir = new PVector( random(-1,1),random(-1,1) ); // create a random Motion
}
/** call to move the Person
*/
void Update() {
this.PVPos.add(this.PVDir); // adds the current Motion to the Position
this.PVDir.add( new PVector( random(-.1,.1),random(-.1,.1) ) ); // changes the current Motion a little bit
this.PVDir.limit(MaxSpeed); // limits the speed of the current Motion
if (this.PVPos.x > width) { // if a MENSCH walks out of the screen at the bottom
this.PVPos.x -= width; // it comes back at the top
}
else if (this.PVPos.x < 0) { // top ==> bottom
this.PVPos.x += width;
}
if (this.PVPos.y > height) { // right ==> left
this.PVPos.y -= height;
}
else if (this.PVPos.y < 0) { // left ==> right
this.PVPos.y += height;
}
}
/** call to display the human on the screen
*/
void Render() {
pushStyle();
strokeWeight(2);
ellipse(this.PVPos.x,this.PVPos.y,this.Size,this.Size);
strokeWeight(0);
stroke(247,5,167);
line(this.PVPos.x,this.PVPos.y,this.PVPos.x+this.PVDir.x*20,this.PVPos.y+this.PVDir.y*20);
popStyle();
}
}