-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox.js
46 lines (42 loc) · 929 Bytes
/
box.js
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
// Daniel Shiffman
// http://codingtra.in
// http://patreon.com/codingtrain
// Code for: https://youtu.be/urR596FsU68
function Box(x, y, w, h) {
var options = {
friction: 0.8,
frictionAir: 0.05,
restitution: 0.2,
mass: 3
}
this.body = Bodies.rectangle(x, y, w, h, options);
this.w = w;
this.h = h;
World.add(world, this.body);
this.show = function() {
var pos = this.body.position;
var angle = this.body.angle;
push();
translate(pos.x, pos.y);
rotate(angle);
rectMode(CENTER);
strokeWeight(1);
stroke(255);
fill(127);
rect(0, 0, this.w, this.h);
pop();
}
this.display = function() {
var pos = this.body.position;
var angle = this.body.angle;
push();
translate(pos.x + width / 4,pos.y );
rotate(angle);
rectMode(CENTER);
strokeWeight(1);
stroke(255);
fill(127);
rect(0, 0, this.w, this.h);
pop();
}
}