Jupyter at Bryn Mawr College

Public notebooks: /services/public/dblank / CS110 Intro to Computing / 2017-Spring / Notes
In [19]:
class Person {
int x, y;
float angle;

Person(int x, int y) {
this.x = x;
this.y = y;
this.angle = ranom;
}
void move() {
this.angle = this.angle + .1; // these are in radians
}

void draw() {
ellipse(this.x, this.y, 50, 50);
rect(this.x - 25, this.y + 25, 50, 100);
// left arm:
quad(this.x - 25 - 10, this.y + 25,
this.x - 25, this.y + 25,
this.x - 25, this.y + 25 + 40,
this.x - 25 - 10, this.y + 25 + 40);

// right arm, draw relative to origin:
float x1 = 0;
float y1 = 0;
float x2 = 10;
float y2 = 0;
float x3 = 10;
float y3 = 40;
float x4 = 0;
float y4 = 40;

pushMatrix();
translate(this.x + 25, this.y + 25); // move to where you want it
rotate(angle);                       // rotate it
x2, y2,
x3, y3,
x4, y4);
popMatrix();
}
}

Person[] people = new Person[5];

void setup() {
int i = 0;
while (i < 5) {
people[i] = new Person(int(random(500)), 100);
i = i + 1; // i++
}
size(500, 300);
}

void draw() {
background(128);
for (int i=0; i < 5; i++) {
people[i].draw();
}
text("Click to move arm", 10, 20);
}

void mousePressed() {
for (int i=0; i < 5; i++) {
people[i].move();
}
}

Sketch #19: