Skip to content

Commit 76ca876

Browse files
committed
adding license
1 parent 4b25ca2 commit 76ca876

File tree

9 files changed

+197
-75
lines changed

9 files changed

+197
-75
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright 2013 Sub Protocol and other contributors
2+
http://subprotocol.com/
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

experiments/01-shapes.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script type="text/javascript" src="../js/common/vec2.js"></script>
99
<script type="text/javascript" src="../js/common/constraint.js"></script>
1010
<script type="text/javascript" src="../js/common/verlet.js"></script>
11+
<script type="text/javascript" src="../js/common/objects.js"></script>
1112
</head>
1213
<body>
1314
<canvas id="scratch" style="width: 500px; height: 300px;"></canvas>

experiments/02-angle.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script type="text/javascript" src="../js/common/vec2.js"></script>
99
<script type="text/javascript" src="../js/common/constraint.js"></script>
1010
<script type="text/javascript" src="../js/common/verlet.js"></script>
11+
<script type="text/javascript" src="../js/common/objects.js"></script>
1112
</head>
1213
<body>
1314
<canvas id="scratch" style="width: 800px; height: 500px;"></canvas>

experiments/03-cloth.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script type="text/javascript" src="../js/common/vec2.js"></script>
99
<script type="text/javascript" src="../js/common/constraint.js"></script>
1010
<script type="text/javascript" src="../js/common/verlet.js"></script>
11+
<script type="text/javascript" src="../js/common/objects.js"></script>
1112
</head>
1213
<body>
1314
<canvas id="scratch" style="width: 800px; height: 500px; background: #000;"></canvas>

experiments/04-spiderweb.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script type="text/javascript" src="../js/common/vec2.js"></script>
99
<script type="text/javascript" src="../js/common/constraint.js"></script>
1010
<script type="text/javascript" src="../js/common/verlet.js"></script>
11+
<script type="text/javascript" src="../js/common/objects.js"></script>
1112
</head>
1213
<body>
1314
<canvas id="scratch" style="width: 800px; height: 500px;"></canvas>

js/common/constraint.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11

2+
/*
3+
Copyright 2013 Sub Protocol and other contributors
4+
http://subprotocol.com/
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
226
// DistanceConstraint -- constrains to initial distance
327
// PinConstraint -- constrains to static/fixed point
428
// AngleConstraint -- constrains 3 particles to an angle

js/common/objects.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
/*
3+
Copyright 2013 Sub Protocol and other contributors
4+
http://subprotocol.com/
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
// generic verlet entities
27+
28+
VerletJS.prototype.lineSegments = function(vertices, stiffness) {
29+
var i;
30+
31+
var composite = new this.Composite();
32+
33+
for (i in vertices) {
34+
composite.particles.push(new Particle(vertices[i]));
35+
if (i > 0)
36+
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[i-1], stiffness));
37+
}
38+
39+
this.composites.push(composite);
40+
return composite;
41+
}
42+
43+
VerletJS.prototype.cloth = function(origin, width, height, segments, pinMod, stiffness) {
44+
45+
var composite = new this.Composite();
46+
47+
var xStride = width/segments;
48+
var yStride = height/segments;
49+
50+
var x,y;
51+
for (y=0;y<segments;++y) {
52+
for (x=0;x<segments;++x) {
53+
var px = origin.x + x*xStride - width/2 + xStride/2;
54+
var py = origin.y + y*yStride - height/2 + yStride/2;
55+
composite.particles.push(new Particle(new Vec2(px, py)));
56+
57+
if (x > 0)
58+
composite.constraints.push(new DistanceConstraint(composite.particles[y*segments+x], composite.particles[y*segments+x-1], stiffness));
59+
60+
if (y > 0)
61+
composite.constraints.push(new DistanceConstraint(composite.particles[y*segments+x], composite.particles[(y-1)*segments+x], stiffness));
62+
}
63+
}
64+
65+
for (x=0;x<segments;++x) {
66+
if (x%pinMod == 0)
67+
composite.pin(x);
68+
}
69+
70+
this.composites.push(composite);
71+
return composite;
72+
}
73+
74+
VerletJS.prototype.tire = function(origin, radius, segments, spokeStiffness, treadStiffness) {
75+
var stride = (2*Math.PI)/segments;
76+
var i;
77+
78+
var composite = new this.Composite();
79+
80+
// particles
81+
for (i=0;i<segments;++i) {
82+
var theta = i*stride;
83+
composite.particles.push(new Particle(new Vec2(origin.x + Math.cos(theta)*radius, origin.y + Math.sin(theta)*radius)));
84+
}
85+
86+
var center = new Particle(origin);
87+
composite.particles.push(center);
88+
89+
// constraints
90+
for (i=0;i<segments;++i) {
91+
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[(i+1)%segments], treadStiffness));
92+
composite.constraints.push(new DistanceConstraint(composite.particles[i], center, spokeStiffness))
93+
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[(i+5)%segments], treadStiffness));
94+
}
95+
96+
this.composites.push(composite);
97+
return composite;
98+
}
99+

js/common/vec2.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11

2-
// 2-dimensional vector implementation
2+
/*
3+
Copyright 2013 Sub Protocol and other contributors
4+
http://subprotocol.com/
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
27+
// A simple 2-dimensional vector implementation
328

429
function Vec2(x, y) {
530
this.x = x || 0;

js/common/verlet.js

Lines changed: 23 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11

2+
/*
3+
Copyright 2013 Sub Protocol and other contributors
4+
http://subprotocol.com/
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
225

326
window.requestAnimFrame = window.requestAnimationFrame
427
|| window.webkitRequestAnimationFrame
@@ -87,80 +110,6 @@ VerletJS.prototype.point = function(pos) {
87110
return composite;
88111
}
89112

90-
VerletJS.prototype.lineSegments = function(vertices, stiffness) {
91-
var i;
92-
93-
var composite = new this.Composite();
94-
95-
for (i in vertices) {
96-
composite.particles.push(new Particle(vertices[i]));
97-
if (i > 0)
98-
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[i-1], stiffness));
99-
}
100-
101-
this.composites.push(composite);
102-
return composite;
103-
}
104-
105-
VerletJS.prototype.cloth = function(origin, width, height, segments, pinMod, stiffness) {
106-
107-
var composite = new this.Composite();
108-
109-
var xStride = width/segments;
110-
var yStride = height/segments;
111-
112-
var x,y;
113-
for (y=0;y<segments;++y) {
114-
for (x=0;x<segments;++x) {
115-
var px = origin.x + x*xStride - width/2 + xStride/2;
116-
var py = origin.y + y*yStride - height/2 + yStride/2;
117-
composite.particles.push(new Particle(new Vec2(px, py)));
118-
119-
if (x > 0)
120-
composite.constraints.push(new DistanceConstraint(composite.particles[y*segments+x], composite.particles[y*segments+x-1], stiffness));
121-
122-
if (y > 0)
123-
composite.constraints.push(new DistanceConstraint(composite.particles[y*segments+x], composite.particles[(y-1)*segments+x], stiffness));
124-
}
125-
}
126-
127-
for (x=0;x<segments;++x) {
128-
if (x%pinMod == 0)
129-
composite.pin(x);
130-
}
131-
132-
this.composites.push(composite);
133-
return composite;
134-
}
135-
136-
137-
VerletJS.prototype.tire = function(origin, radius, segments, spokeStiffness, treadStiffness) {
138-
var stride = (2*Math.PI)/segments;
139-
var i;
140-
141-
var composite = new this.Composite();
142-
143-
// particles
144-
for (i=0;i<segments;++i) {
145-
var theta = i*stride;
146-
composite.particles.push(new Particle(new Vec2(origin.x + Math.cos(theta)*radius, origin.y + Math.sin(theta)*radius)));
147-
}
148-
149-
var center = new Particle(origin);
150-
composite.particles.push(center);
151-
152-
// constraints
153-
for (i=0;i<segments;++i) {
154-
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[(i+1)%segments], treadStiffness));
155-
composite.constraints.push(new DistanceConstraint(composite.particles[i], center, spokeStiffness))
156-
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[(i+5)%segments], treadStiffness));
157-
}
158-
159-
this.composites.push(composite);
160-
return composite;
161-
}
162-
163-
164113
VerletJS.prototype.frame = function(step) {
165114
var i, j, c;
166115

0 commit comments

Comments
 (0)