Skip to content
This repository was archived by the owner on Dec 15, 2019. It is now read-only.

Commit eefc5ac

Browse files
Merge branch '1.0.0-rc1'
2 parents 7892343 + b96fc61 commit eefc5ac

File tree

160 files changed

+87433
-21768
lines changed

Some content is hidden

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

160 files changed

+87433
-21768
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
.grunt
33
.DS_Store
44
_SpecRunner.html
5-
_working
5+
_working
6+
.sass-cache

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A modular, extendable, and easy-to-use physics engine for javascript.
44

5-
Latest version: 0.5.4 (alpha)
5+
Latest version: 0.6.0 (beta)
66

77
## Usage
88

@@ -28,7 +28,7 @@ then run grunt
2828
$ grunt
2929

3030
The default grunt task will create a `_working/` directory with the
31-
PhysicsJS development build. You can play around with that.
31+
PhysicsJS development build. You can play around with that.
3232
**NOTE**: the `_working/` directory won't be committed
3333
(it is in .gitignore).
3434

bower.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "PhysicsJS",
3+
"version": "0.6.0",
4+
"homepage": "http://wellcaffeinated.net/PhysicsJS",
5+
"authors": [
6+
"Jasper Palfree <[email protected]>"
7+
],
8+
"description": "A modular, extendable, and easy-to-use physics engine for javascript",
9+
"main": "dist/physicsjs-full-0.6.0.js",
10+
"moduleType": [
11+
"amd",
12+
"globals",
13+
"node"
14+
],
15+
"keywords": [
16+
"physics",
17+
"engine",
18+
"simulation"
19+
],
20+
"license": "MIT",
21+
"ignore": [
22+
"**/.*",
23+
"node_modules",
24+
"bower_components",
25+
"test",
26+
"tests",
27+
"editor",
28+
"lib",
29+
"src",
30+
"jshint.json",
31+
"gruntfile.js",
32+
"package.json"
33+
]
34+
}

dist/behaviors/attractor.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* PhysicsJS v0.6.0 - 2014-04-22
3+
* A modular, extendable, and easy-to-use physics engine for javascript
4+
* http://wellcaffeinated.net/PhysicsJS
5+
*
6+
* Copyright (c) 2014 Jasper Palfree <[email protected]>
7+
* Licensed MIT
8+
*/
9+
(function (root, factory) {
10+
if (typeof define === 'function' && define.amd) {
11+
define(['physicsjs'], factory);
12+
} else if (typeof exports === 'object') {
13+
module.exports = factory.apply(root, ['physicsjs'].map(require));
14+
} else {
15+
factory.call(root, root.Physics);
16+
}
17+
}(this, function (Physics) {
18+
'use strict';
19+
/**
20+
* class AttractorBehavior < Behavior
21+
*
22+
* `Physics.behavior('attractor')`.
23+
*
24+
* Attractor behavior attracts bodies to a specific point.
25+
*
26+
* Additional options include:
27+
* - pos: The position of the attraction point
28+
* - strength: How strong the attraction is (default: `1`)
29+
* - order: The power of the inverse distance (default: `2` because that is newtonian gravity... inverse square)
30+
* - max: The maximum distance in which to apply the attraction (default: Infinity)
31+
* - min: The minimum distance above which to apply the attraction (default: very small non-zero)
32+
**/
33+
Physics.behavior('attractor', function( parent ){
34+
35+
var defaults = {
36+
37+
pos: null, // default to (0, 0)
38+
// how strong the attraction is
39+
strength: 1,
40+
// power of the inverse distance (2 is inverse square)
41+
order: 2,
42+
// max distance to apply it to
43+
max: false, // infinite
44+
// min distance to apply it to
45+
min: false // auto calc
46+
};
47+
48+
return {
49+
50+
// extended
51+
init: function( options ){
52+
53+
var self = this;
54+
this._pos = new Physics.vector();
55+
// call parent init method
56+
parent.init.call( this );
57+
this.options.defaults( defaults );
58+
this.options.onChange(function( opts ){
59+
self._maxDist = opts.max === false ? Infinity : opts.max;
60+
self._minDist = opts.min ? opts.min : 10;
61+
self.position( opts.pos );
62+
});
63+
this.options( options );
64+
},
65+
66+
/**
67+
* AttractorBehavior#position( [pos] ) -> this|Object
68+
* - pos (Vectorish): The position to set
69+
* + (Object): Returns the [[Vectorish]] position if no arguments provided
70+
* + (this): For chaining
71+
*
72+
* Get or set the position of the attractor.
73+
**/
74+
position: function( pos ){
75+
76+
var self = this;
77+
78+
if ( pos ){
79+
this._pos.clone( pos );
80+
return self;
81+
}
82+
83+
return this._pos.values();
84+
},
85+
86+
// extended
87+
behave: function( data ){
88+
89+
var bodies = this.getTargets()
90+
,body
91+
,order = this.options.order
92+
,strength = this.options.strength
93+
,minDist = this._minDist
94+
,maxDist = this._maxDist
95+
,scratch = Physics.scratchpad()
96+
,acc = scratch.vector()
97+
,norm
98+
,g
99+
;
100+
101+
for ( var j = 0, l = bodies.length; j < l; j++ ){
102+
103+
body = bodies[ j ];
104+
105+
// clone the position
106+
acc.clone( this._pos );
107+
acc.vsub( body.state.pos );
108+
// get the distance
109+
norm = acc.norm();
110+
111+
if (norm > minDist && norm < maxDist){
112+
113+
g = strength / Math.pow(norm, order);
114+
115+
body.accelerate( acc.normalize().mult( g ) );
116+
}
117+
}
118+
119+
scratch.done();
120+
}
121+
};
122+
});
123+
124+
// end module: behaviors/attractor.js
125+
return Physics;
126+
}));// UMD

0 commit comments

Comments
 (0)