-
Notifications
You must be signed in to change notification settings - Fork 0
/
Umbrella.pde
61 lines (52 loc) · 1.55 KB
/
Umbrella.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Umbrella {
float x, y;
Body body;
BodyDef bd;
float[] randColor;
Umbrella(float[] randColor){
this.randColor = randColor;
bd = new BodyDef(); //build body
bd.type = BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld(mouseX, mouseY));
body = box2d.createBody(bd);
PolygonShape ps = new PolygonShape(); // build shape
float box2dW = box2d.scalarPixelsToWorld(80/2); //5/2
float box2dH = box2d.scalarPixelsToWorld(80/2);
ps.setAsBox(box2dW, box2dH);
body.setLinearVelocity(new Vec2(0, (random(-10, -1))));
body.setAngularVelocity(random(-1.5, 1.5));
CircleShape cs = new CircleShape();
cs.m_radius = box2d.scalarPixelsToWorld(40);
//body.createFixture(cs, 1);
FixtureDef fd = new FixtureDef();
fd.shape = ps;
fd.density = 1;
fd.friction = 0.3;
fd.restitution = .8;
body.createFixture(fd);
}
void display(){
colorMode(HSB);
Vec2 pos = box2d.getBodyPixelCoord(body);
float a = body.getAngle();
pushMatrix();
translate(pos.x, pos.y);
rotate(-a);
fill(randColor[0], randColor[1], randColor[2]);
arc(0, 0, 100, 80, PI, 2*PI);
rect(-5, 0, 5, 35);
noFill();
// stroke(#54dfe8);
stroke(randColor[0], randColor[1], 200);
strokeWeight(5);
arc(-13, 33, 20, 20, 0, PI);
noStroke();
fill(randColor[0], randColor[1], 200);
triangle(4, -38, -6, -38, -1, -48);
noStroke();
noFill();
popMatrix();
noStroke();
noFill();
}
}