-
Notifications
You must be signed in to change notification settings - Fork 0
/
Untitled_1.html
57 lines (49 loc) · 1.36 KB
/
Untitled_1.html
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
<!DOCTYPE html>
<html>
<head>
<title>Untitled_1</title>
<meta charset="utf-8">
<style>
body {
background-color: #323232;
}
canvas {
position: absolute;
left: 50%;
top:50%;
transform: translate(-50%, -50%);
background-color: white;
}
</style>
</head>
<body>
<script src="./lib/playground.js"></script>
<script type="text/javascript">
var scene = new Scene(800, 600);
document.body.appendChild(scene.canvas);
window.onload = function() {
init();
render();
}
function init() {
scene.physicsWorld.gravity = new Vector(0, 200);
}
function render() {
let grey = Math.floor(Math.random()*(128+64));
let color = 'rgb(' + grey + ', ' + grey + ', ' + grey + ')';
let shape = Math.random()>0.5?new Rectangle(Math.random() * 10+10, Math.random() * 10+10):new Circle(Math.random()*5+5)
let box = new ShapeNode(shape, color);
box.position.x = Math.random() * scene.width;
box.position.y = 0;
box.setPhysicsBody(new PhysicsBody(box.shape));
box.angle = Math.random()*Math.PI*2
let impulse = (new Vector((Math.random()-0.5), 0)).multiplyScalar(2000*(Math.random()+3));
let position = new Vector((Math.random()-0.5)*20, (Math.random()-0.5)*20);
box.physicsBody.applyImpulse(impulse, position);
scene.addChild(box);
scene.update();
window.requestAnimationFrame(render);
}
</script>
</body>
</html>