|
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
7 | 7 | <meta http-equiv="X-UA-Compatible" content="ie=edge"> |
8 | 8 | <title>Verly.js</title> |
9 | | - <script src="./src/Vector.js"></script> |
| 9 | + <script src="../src/Vector.js"></script> |
10 | 10 |
|
11 | 11 | <style> |
12 | 12 | * { |
|
30 | 30 |
|
31 | 31 | <canvas id="c"></canvas> |
32 | 32 |
|
33 | | - <script src="./src/Utils.js"></script> |
34 | | - <script src="./src/Point.js"></script> |
35 | | - <script src="./src/Stick.js"></script> |
36 | | - <script src="./src/Entity.js"></script> |
37 | | - <script src="./src/Mouse.js"></script> |
38 | | - <script src="./src/Verly.js"></script> |
39 | | - <script src="./src/Objects.js"></script> |
| 33 | + <script src="../src/Utils.js"></script> |
| 34 | + <script src="../src/Point.js"></script> |
| 35 | + <script src="../src/Stick.js"></script> |
| 36 | + <script src="../src/Entity.js"></script> |
| 37 | + <script src="../src/Mouse.js"></script> |
| 38 | + <script src="../src/Verly.js"></script> |
| 39 | + <script src="../src/Objects.js"></script> |
40 | 40 | <script> |
41 | | - let canvas = document.getElementById('c'); |
42 | | - let ctx = canvas.getContext('2d'); |
43 | | - let width = 600; |
44 | | - let height = 600; |
45 | | - canvas.width = width; |
46 | | - canvas.height = height; |
47 | 41 |
|
48 | 42 | window.onload = function () { |
| 43 | + let canvas = document.getElementById('c'); |
| 44 | + let ctx = canvas.getContext('2d'); |
| 45 | + let width = 600; |
| 46 | + let height = 600; |
| 47 | + canvas.width = width; |
| 48 | + canvas.height = height; |
49 | 49 |
|
50 | | - let verly = new Verly(16); |
| 50 | + let verly = new Verly(16, canvas, ctx); |
51 | 51 |
|
52 | 52 | let b1 = new Box(200, 110, 20, 100); |
53 | | - verly.addEntity(b1._box); |
| 53 | + b1.setGravity(new Vector()) |
| 54 | + verly.addEntity(b1); |
54 | 55 |
|
55 | | - for (p of b1._box.points) { |
| 56 | + for (p of b1.points) { |
56 | 57 | let absSize = new Vector(b1.width / 2, b1.height / 2); |
57 | 58 | let boxcenter = new Vector(b1.x - absSize.x, b1.y - absSize.y); |
58 | 59 | let rot = degreesToRad(25); |
|
61 | 62 | } |
62 | 63 |
|
63 | 64 | let b2 = new Box(150, 125, 20, 100); |
64 | | - verly.addEntity(b2._box); |
65 | | - for (p of b2._box.points) { |
| 65 | + b2.setGravity(new Vector()) |
| 66 | + verly.addEntity(b2); |
| 67 | + |
| 68 | + for (p of b2.points) { |
66 | 69 | let absSize = new Vector(b2.width / 2, b2.height / 2); |
67 | 70 | let boxcenter = new Vector(b2.x - absSize.x, b2.y - absSize.y); |
68 | 71 | let rot = degreesToRad(-25); |
|
74 | 77 | ctx.clearRect(0, 0, width, height); |
75 | 78 |
|
76 | 79 | verly.update(); |
| 80 | + verly.render(); |
| 81 | + verly.interact(); |
77 | 82 | // verly.renderPointIndex(); |
78 | 83 |
|
79 | 84 | requestAnimationFrame(animate); |
|
0 commit comments