Skip to content

Commit 5a0ae01

Browse files
committed
fixed bugs | minor API change
1 parent 93ee858 commit 5a0ae01

File tree

21 files changed

+530
-163
lines changed

21 files changed

+530
-163
lines changed

examples/behavior.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,22 @@
3737
<script src="../src/Mouse.js"></script>
3838
<script src="../src/Verly.js"></script>
3939
<script>
40-
let canvas = document.getElementById('c');
41-
let ctx = canvas.getContext('2d');
42-
let width = 600;
43-
let height = 500;
44-
canvas.width = width;
45-
canvas.height = height;
4640

4741
window.onload = function () {
42+
let canvas = document.getElementById('c');
43+
let ctx = canvas.getContext('2d');
44+
let width = 600;
45+
let height = 500;
46+
canvas.width = width;
47+
canvas.height = height;
4848

49-
let verly = new Verly(16);
49+
let verly = new Verly(16, canvas, ctx);
5050

5151
let mouse = new Point(0, 0);
5252
mouse.setForceAcc(-30);
5353
mouse.setRadius(100);
54+
55+
5456
let mBehavior = 2;
5557
window.addEventListener('mousemove', (e) => {
5658
if (e.altKey) {
@@ -68,8 +70,6 @@
6870
})
6971

7072

71-
72-
7373
let particles = new Entity();
7474
function addParticles(x, y) {
7575
let p = new Point(x, y);
@@ -97,6 +97,8 @@
9797
}
9898

9999
verly.update();
100+
verly.render();
101+
verly.interact();
100102

101103
// verly.renderPointIndex();
102104

examples/behavior2.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
<script src="../src/Mouse.js"></script>
3838
<script src="../src/Verly.js"></script>
3939
<script>
40-
let canvas = document.getElementById('c');
41-
let ctx = canvas.getContext('2d');
42-
let width = 600;
43-
let height = 600;
44-
canvas.width = width;
45-
canvas.height = height;
4640

4741
window.onload = function () {
42+
let canvas = document.getElementById('c');
43+
let ctx = canvas.getContext('2d');
44+
let width = 600;
45+
let height = 600;
46+
canvas.width = width;
47+
canvas.height = height;
4848

49-
let verly = new Verly(16);
49+
let verly = new Verly(16, canvas, ctx);
5050

5151
let particle = new Entity();
5252
let p1 = new Point(0, 0);
@@ -84,6 +84,9 @@
8484
}
8585
}
8686
verly.update();
87+
verly.render();
88+
verly.interact();
89+
8790

8891
p1.addMotor(200, 200, verly.currentFrame, 100, 0.07);
8992
p2.addMotor(350, 350, verly.currentFrame, 100, -0.07);

examples/dynamicCustomMesh.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@
3636
<script src="../src/Mouse.js"></script>
3737
<script src="../src/Verly.js"></script>
3838
<script>
39-
let canvas = document.getElementById('c');
40-
let ctx = canvas.getContext('2d');
41-
let width = 600;
42-
let height = 500;
43-
canvas.width = width;
44-
canvas.height = height;
45-
39+
4640
window.onload = function () {
41+
let canvas = document.getElementById('c');
42+
let ctx = canvas.getContext('2d');
43+
let width = 600;
44+
let height = 500;
45+
canvas.width = width;
46+
canvas.height = height;
4747

48-
let verly = new Verly(16);
48+
let verly = new Verly(16, canvas, ctx);
4949

5050
let custom = new Entity(16);
5151

@@ -72,6 +72,8 @@
7272

7373

7474
verly.update();
75+
verly.render();
76+
verly.interact();
7577
// verly.renderPointIndex();
7678

7779
requestAnimationFrame(animate);

examples/ragdoll.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@
3636
<script src="../src/Mouse.js"></script>
3737
<script src="../src/Verly.js"></script>
3838
<script>
39-
let canvas = document.getElementById('c');
40-
let ctx = canvas.getContext('2d');
41-
let width = 600;
42-
let height = 500;
43-
canvas.width = width;
44-
canvas.height = height;
4539

4640

4741
window.onload = function () {
48-
let verly = new Verly(8);
42+
let canvas = document.getElementById('c');
43+
let ctx = canvas.getContext('2d');
44+
let width = 600;
45+
let height = 500;
46+
canvas.width = width;
47+
canvas.height = height;
48+
49+
let verly = new Verly(8, canvas, ctx);
50+
4951
let rag = verly.createRagdoll(150, 150);
5052
let hexa = verly.createHexagon(200, 100, 16, 30);
5153
let hexa2 = verly.createHexagon(200, 100, 16, 30);
@@ -56,7 +58,11 @@
5658

5759
function animate() {
5860
ctx.clearRect(0, 0, width, height);
61+
5962
verly.update();
63+
verly.render();
64+
verly.interact();
65+
6066
requestAnimationFrame(animate);
6167
}
6268
animate();

examples/rotatingEntity.html

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
88
<title>Verly.js</title>
9-
<script src="./src/Vector.js"></script>
9+
<script src="../src/Vector.js"></script>
1010

1111
<style>
1212
* {
@@ -30,29 +30,30 @@
3030

3131
<canvas id="c"></canvas>
3232

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>
4040
<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;
4741

4842
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;
4949

50-
let verly = new Verly(16);
50+
let verly = new Verly(16, canvas, ctx);
5151

5252
let b1 = new Box(200, 110, 20, 100);
53-
verly.addEntity(b1._box);
53+
b1.setGravity(new Vector())
54+
verly.addEntity(b1);
5455

55-
for (p of b1._box.points) {
56+
for (p of b1.points) {
5657
let absSize = new Vector(b1.width / 2, b1.height / 2);
5758
let boxcenter = new Vector(b1.x - absSize.x, b1.y - absSize.y);
5859
let rot = degreesToRad(25);
@@ -61,8 +62,10 @@
6162
}
6263

6364
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) {
6669
let absSize = new Vector(b2.width / 2, b2.height / 2);
6770
let boxcenter = new Vector(b2.x - absSize.x, b2.y - absSize.y);
6871
let rot = degreesToRad(-25);
@@ -74,6 +77,8 @@
7477
ctx.clearRect(0, 0, width, height);
7578

7679
verly.update();
80+
verly.render();
81+
verly.interact();
7782
// verly.renderPointIndex();
7883

7984
requestAnimationFrame(animate);

examples/shadedCloth.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@
3838
<script src="../src/Verly.js"></script>
3939

4040
<script>
41-
let canvas = document.getElementById('c');
42-
let ctx = canvas.getContext('2d');
43-
let width = 600;
44-
let height = 500;
45-
canvas.width = width;
46-
canvas.height = height;
4741

4842
window.onload = function () {
43+
let canvas = document.getElementById('c');
44+
let ctx = canvas.getContext('2d');
45+
let width = 600;
46+
let height = 500;
47+
canvas.width = width;
48+
canvas.height = height;
4949

50-
let verly = new Verly(16);
50+
let verly = new Verly(16, canvas, ctx);
5151

5252
class Cloth extends Entity {
5353
constructor(posx, posy, w, h, segments, pinOffset) {
@@ -104,6 +104,8 @@
104104
ctx.clearRect(0, 0, width, height);
105105

106106
verly.update();
107+
verly.render();
108+
verly.interact();
107109
// verly.renderPointIndex();
108110

109111
requestAnimationFrame(animate);

examples/ship/Ship.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
class Ship extends Point {
3-
constructor(x, y, vx, vy, radius) {
3+
constructor(x, y, vx, vy, radius, canvas) {
44
super(x, y, vx, vy, radius);
5-
this.pos = new Vector(100, height / 2);
5+
this.canvas = canvas;
6+
this.pos = new Vector(100, this.canvas.height / 2);
67
this.r = 10;
78
this.heading = 0;
89
this.rotation = 0;
@@ -61,17 +62,17 @@ class Ship extends Point {
6162
ctx.restore();
6263
};
6364
edges() {
64-
if (this.pos.x > width + this.r) {
65+
if (this.pos.x > this.canvas.width + this.r) {
6566
this.pos.x = -this.r;
6667
}
6768
else if (this.pos.x < -this.r) {
68-
this.pos.x = width + this.r;
69+
this.pos.x = this.canvas.width + this.r;
6970
}
70-
if (this.pos.y > height + this.r) {
71+
if (this.pos.y > this.canvas.height + this.r) {
7172
this.pos.y = -this.r;
7273
}
7374
else if (this.pos.y < -this.r) {
74-
this.pos.y = height + this.r;
75+
this.pos.y = this.canvas.height + this.r;
7576
}
7677
};
7778
setRotation(a) {

0 commit comments

Comments
 (0)