Skip to content

Commit

Permalink
fixed bugs | minor API change
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra committed Jun 25, 2019
1 parent 93ee858 commit 5a0ae01
Show file tree
Hide file tree
Showing 21 changed files with 530 additions and 163 deletions.
20 changes: 11 additions & 9 deletions examples/behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@
<script src="../src/Mouse.js"></script>
<script src="../src/Verly.js"></script>
<script>
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;

window.onload = function () {
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;

let verly = new Verly(16);
let verly = new Verly(16, canvas, ctx);

let mouse = new Point(0, 0);
mouse.setForceAcc(-30);
mouse.setRadius(100);


let mBehavior = 2;
window.addEventListener('mousemove', (e) => {
if (e.altKey) {
Expand All @@ -68,8 +70,6 @@
})




let particles = new Entity();
function addParticles(x, y) {
let p = new Point(x, y);
Expand Down Expand Up @@ -97,6 +97,8 @@
}

verly.update();
verly.render();
verly.interact();

// verly.renderPointIndex();

Expand Down
17 changes: 10 additions & 7 deletions examples/behavior2.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
<script src="../src/Mouse.js"></script>
<script src="../src/Verly.js"></script>
<script>
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 600;
canvas.width = width;
canvas.height = height;

window.onload = function () {
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 600;
canvas.width = width;
canvas.height = height;

let verly = new Verly(16);
let verly = new Verly(16, canvas, ctx);

let particle = new Entity();
let p1 = new Point(0, 0);
Expand Down Expand Up @@ -84,6 +84,9 @@
}
}
verly.update();
verly.render();
verly.interact();


p1.addMotor(200, 200, verly.currentFrame, 100, 0.07);
p2.addMotor(350, 350, verly.currentFrame, 100, -0.07);
Expand Down
18 changes: 10 additions & 8 deletions examples/dynamicCustomMesh.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
<script src="../src/Mouse.js"></script>
<script src="../src/Verly.js"></script>
<script>
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;


window.onload = function () {
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;

let verly = new Verly(16);
let verly = new Verly(16, canvas, ctx);

let custom = new Entity(16);

Expand All @@ -72,6 +72,8 @@


verly.update();
verly.render();
verly.interact();
// verly.renderPointIndex();

requestAnimationFrame(animate);
Expand Down
20 changes: 13 additions & 7 deletions examples/ragdoll.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@
<script src="../src/Mouse.js"></script>
<script src="../src/Verly.js"></script>
<script>
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;


window.onload = function () {
let verly = new Verly(8);
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;

let verly = new Verly(8, canvas, ctx);

let rag = verly.createRagdoll(150, 150);
let hexa = verly.createHexagon(200, 100, 16, 30);
let hexa2 = verly.createHexagon(200, 100, 16, 30);
Expand All @@ -56,7 +58,11 @@

function animate() {
ctx.clearRect(0, 0, width, height);

verly.update();
verly.render();
verly.interact();

requestAnimationFrame(animate);
}
animate();
Expand Down
43 changes: 24 additions & 19 deletions examples/rotatingEntity.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Verly.js</title>
<script src="./src/Vector.js"></script>
<script src="../src/Vector.js"></script>

<style>
* {
Expand All @@ -30,29 +30,30 @@

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

<script src="./src/Utils.js"></script>
<script src="./src/Point.js"></script>
<script src="./src/Stick.js"></script>
<script src="./src/Entity.js"></script>
<script src="./src/Mouse.js"></script>
<script src="./src/Verly.js"></script>
<script src="./src/Objects.js"></script>
<script src="../src/Utils.js"></script>
<script src="../src/Point.js"></script>
<script src="../src/Stick.js"></script>
<script src="../src/Entity.js"></script>
<script src="../src/Mouse.js"></script>
<script src="../src/Verly.js"></script>
<script src="../src/Objects.js"></script>
<script>
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 600;
canvas.width = width;
canvas.height = height;

window.onload = function () {
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 600;
canvas.width = width;
canvas.height = height;

let verly = new Verly(16);
let verly = new Verly(16, canvas, ctx);

let b1 = new Box(200, 110, 20, 100);
verly.addEntity(b1._box);
b1.setGravity(new Vector())
verly.addEntity(b1);

for (p of b1._box.points) {
for (p of b1.points) {
let absSize = new Vector(b1.width / 2, b1.height / 2);
let boxcenter = new Vector(b1.x - absSize.x, b1.y - absSize.y);
let rot = degreesToRad(25);
Expand All @@ -61,8 +62,10 @@
}

let b2 = new Box(150, 125, 20, 100);
verly.addEntity(b2._box);
for (p of b2._box.points) {
b2.setGravity(new Vector())
verly.addEntity(b2);

for (p of b2.points) {
let absSize = new Vector(b2.width / 2, b2.height / 2);
let boxcenter = new Vector(b2.x - absSize.x, b2.y - absSize.y);
let rot = degreesToRad(-25);
Expand All @@ -74,6 +77,8 @@
ctx.clearRect(0, 0, width, height);

verly.update();
verly.render();
verly.interact();
// verly.renderPointIndex();

requestAnimationFrame(animate);
Expand Down
16 changes: 9 additions & 7 deletions examples/shadedCloth.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
<script src="../src/Verly.js"></script>

<script>
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;

window.onload = function () {
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
let width = 600;
let height = 500;
canvas.width = width;
canvas.height = height;

let verly = new Verly(16);
let verly = new Verly(16, canvas, ctx);

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

verly.update();
verly.render();
verly.interact();
// verly.renderPointIndex();

requestAnimationFrame(animate);
Expand Down
13 changes: 7 additions & 6 deletions examples/ship/Ship.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

class Ship extends Point {
constructor(x, y, vx, vy, radius) {
constructor(x, y, vx, vy, radius, canvas) {
super(x, y, vx, vy, radius);
this.pos = new Vector(100, height / 2);
this.canvas = canvas;
this.pos = new Vector(100, this.canvas.height / 2);
this.r = 10;
this.heading = 0;
this.rotation = 0;
Expand Down Expand Up @@ -61,17 +62,17 @@ class Ship extends Point {
ctx.restore();
};
edges() {
if (this.pos.x > width + this.r) {
if (this.pos.x > this.canvas.width + this.r) {
this.pos.x = -this.r;
}
else if (this.pos.x < -this.r) {
this.pos.x = width + this.r;
this.pos.x = this.canvas.width + this.r;
}
if (this.pos.y > height + this.r) {
if (this.pos.y > this.canvas.height + this.r) {
this.pos.y = -this.r;
}
else if (this.pos.y < -this.r) {
this.pos.y = height + this.r;
this.pos.y = this.canvas.height + this.r;
}
};
setRotation(a) {
Expand Down
Loading

0 comments on commit 5a0ae01

Please sign in to comment.