Skip to content

Instantly share code, notes, and snippets.

@CSchoel
Created January 27, 2015 13:14
Show Gist options
  • Save CSchoel/0acae8596585a9b2d689 to your computer and use it in GitHub Desktop.
Save CSchoel/0acae8596585a9b2d689 to your computer and use it in GitHub Desktop.
A walking stick figure
//Autor: Christopher Schölzel
class StickFigure {
float v; //Bewegungsgeschwindigkeit
float x; //x-Koordinate
public StickFigure(float x, float v) {
this.x = x;
this.v = v;
}
void walk() {
if (x > width-100) v = -1;
if (x < 100) v = 1;
x += v;
}
void display() {
int dirX = v >= 0 ? 1 : -1; //Richtung in die Strichmännchen gedreht ist
fill(255);
stroke(0);
ellipse(x,60,60,60); //Kopf
ellipse(x+10*dirX,50,10,10); //Auge
fill(0);
ellipse(x+10*dirX,50,4,4); //Pupille
triangle(x+15*dirX,70,x+20*dirX,83,x+28*dirX,70); //Mund
line(x,90,x,200); //Körper
line(x,120,x+50*dirX,130); //Arm 1
line(x,120,x+53*dirX,120); //Arm 2
pushMatrix();
translate(x,200);
rotate(0.3*sin(x/10.0)); //Beinrotation abhängig von x-Position
line(0,0,25,80); //Bein 1
popMatrix();
pushMatrix();
translate(x,200);
rotate(0.3*sin(-x/10.0)); //Beinrotation abhängig von x-Position
line(0,0,-25,80); //Bein 2
popMatrix();
}
}
StickFigure daMan;
void setup() {
size(400,300);
daMan = new StickFigure(width/2.0,1);
}
void draw() {
background(255);
daMan.walk();
daMan.display();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment