Skip to content

Commit fa78a6e

Browse files
committed
Initial Commit
0 parents  commit fa78a6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+21962
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/node_modules
2+
/dist
3+
/docs
4+
/examples
5+
package-lock.json
6+
jsdoc.json
7+
webpack.config.js
8+
.gitignore

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Heax Js
2+
3+
> Verlet physics engine written in javascript.
4+
5+
## Installation
6+
7+
- From npm
8+
9+
```bash
10+
npm install heax
11+
```
12+
13+
- From cdn
14+
15+
```html
16+
<script src="https://cdn.jsdelivr.net/gh/coderosh/heaxjs/dist/bundle.js"></script>
17+
```
18+
19+
## Usage
20+
21+
1. Import Classes
22+
23+
```js
24+
// if you are using npm
25+
import Heax, { Vector, Composite } from "heax";
26+
27+
// if you are using cdn link
28+
const { Heax, Vector, Composite } = window;
29+
```
30+
31+
2. Create a heax instance and pass canvas element to it
32+
33+
```js
34+
const heax = new Heax(document.querySelector("canvas"));
35+
```
36+
37+
3. Create different shapes
38+
39+
```js
40+
// create a box
41+
const box = heax.box(10, 40, 100, 200);
42+
43+
// create a cloth
44+
const cloth = heax.cloth(new Vector(50, 0), 250, 250, 9, 2);
45+
46+
// create a rope
47+
const rope = heax.rope(
48+
(i) => ({
49+
x: 100 + i * 5,
50+
y: 100 + i * 5,
51+
}),
52+
20
53+
);
54+
55+
// create custom shape
56+
const square = new Composite(heax);
57+
square.addPoint(100, 100, 100, 100);
58+
square.addPoint(200, 100, 200, 100);
59+
square.addPoint(200, 200, 200, 200);
60+
square.addPoint(100, 200, 100, 200);
61+
62+
square.addStick(0, 1);
63+
square.addStick(1, 2);
64+
square.addStick(2, 3);
65+
square.addStick(3, 0);
66+
square.addStick(1, 2);
67+
square.addStick(0, 3);
68+
69+
heax.composites.push(square);
70+
71+
// join two shapes
72+
square.addStick(square.points[0], rope.points[0]);
73+
74+
// hide all points of a composite
75+
cloth.hidePoints();
76+
77+
// hide all sticks of a composite
78+
box.hideConsraints();
79+
80+
// hide single point or stick
81+
cloth.points[0].hidden = true;
82+
box.sticks[0].hidden = true;
83+
84+
// pin a point
85+
square.points[2].pinned = true;
86+
```
87+
88+
4. Update and paint the heax instance
89+
90+
```js
91+
function update() {
92+
heax.update();
93+
heax.render();
94+
95+
// drag points with mouse
96+
heax.mouse.drag();
97+
98+
requestAnimationFrame(update);
99+
}
100+
101+
update();
102+
```
103+
104+
5. Save and refresh your browser. For complete api documentation visit [coderosh.github.io/heaxjs/docs](https://coderosh.github.io/heaxjs/docs)

dist/bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)