mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
965f49d156
4 changed files with 19 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting
|
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting
|
||||||
|
|
||||||
If you want to work with Paper.js, simply download the latest "stable" version from [http://paperjs.org/downloads/](http://paperjs.org/downloads/)
|
If you want to work with Paper.js, simply download the latest "stable" version from [http://paperjs.org/download/](http://paperjs.org/download/)
|
||||||
|
|
||||||
- Website: <http://paperjs.org/>
|
- Website: <http://paperjs.org/>
|
||||||
- Discussion forum: <http://groups.google.com/group/paperjs>
|
- Discussion forum: <http://groups.google.com/group/paperjs>
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
initialize: function(position, maxSpeed, maxForce) {
|
initialize: function(position, maxSpeed, maxForce) {
|
||||||
var strength = Math.random() * 0.5;
|
var strength = Math.random() * 0.5;
|
||||||
this.acc = new Point(0, 0);
|
this.acc = new Point(0, 0);
|
||||||
this.vel = new Point(Math.random() * 2 - 1, Math.random() * 2 - 1);
|
this.vel = Point.random() * 2 - 1;
|
||||||
this.loc = position.clone();
|
this.loc = position.clone();
|
||||||
this.r = 30;
|
this.r = 30;
|
||||||
this.maxSpeed = maxSpeed + strength;
|
this.maxSpeed = maxSpeed + strength;
|
||||||
|
@ -64,8 +64,10 @@
|
||||||
var segment = segments[i];
|
var segment = segments[i];
|
||||||
var vector = lastPoint - segment.point;
|
var vector = lastPoint - segment.point;
|
||||||
this.count += this.vel.length * 10;
|
this.count += this.vel.length * 10;
|
||||||
var rotated = lastVector.rotate(90).normalize(Math.sin((this.count + i * 3) / 300));
|
var rotLength = Math.sin((this.count + i * 3) / 300);
|
||||||
lastPoint = segment.point = lastPoint + lastVector.normalize(-5 - this.vel.length / 3);
|
var rotated = lastVector.rotate(90).normalize(rotLength);
|
||||||
|
lastPoint += lastVector.normalize(-5 - this.vel.length / 3);
|
||||||
|
segment.point = lastPoint;
|
||||||
segment.point += rotated;
|
segment.point += rotated;
|
||||||
lastVector = vector;
|
lastVector = vector;
|
||||||
}
|
}
|
||||||
|
@ -108,15 +110,18 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
// A method that calculates a steering vector towards a target
|
// A method that calculates a steering vector towards a target
|
||||||
// Takes a second argument, if true, it slows down as it approaches the target
|
// Takes a second argument, if true, it slows down as it approaches
|
||||||
|
// the target
|
||||||
steer: function(target, slowdown) {
|
steer: function(target, slowdown) {
|
||||||
var steer,
|
var steer,
|
||||||
desired = target - this.loc,
|
desired = target - this.loc,
|
||||||
d = desired.length;
|
d = desired.length;
|
||||||
if (d > 0) {
|
if (d > 0) {
|
||||||
// Two options for desired vector magnitude (1 -- based on distance, 2 -- maxSpeed)
|
// Two options for desired vector magnitude
|
||||||
|
// (1 -- based on distance, 2 -- maxSpeed)
|
||||||
if (slowdown && d < 100) {
|
if (slowdown && d < 100) {
|
||||||
desired.length = this.maxSpeed * (d / 100); // This damping is somewhat arbitrary
|
// // This damping is somewhat arbitrary:
|
||||||
|
desired.length = this.maxSpeed * (d / 100);
|
||||||
} else {
|
} else {
|
||||||
desired.length = this.maxSpeed;
|
desired.length = this.maxSpeed;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +208,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
// Cohesion
|
// Cohesion
|
||||||
// For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
|
// For the average location (i.e. center) of all nearby boids,
|
||||||
|
// calculate steering vector towards that location
|
||||||
cohesion: function(boids) {
|
cohesion: function(boids) {
|
||||||
var neighborDist = 100;
|
var neighborDist = 100;
|
||||||
var sum = new Point(0, 0);
|
var sum = new Point(0, 0);
|
||||||
|
@ -263,7 +269,8 @@
|
||||||
function onFrame(event) {
|
function onFrame(event) {
|
||||||
for (var i = 0, l = boids.length; i < l; i++) {
|
for (var i = 0, l = boids.length; i < l; i++) {
|
||||||
if (groupTogether) {
|
if (groupTogether) {
|
||||||
var point = heartPath.getPointAt(((i + event.count / 30) % l) / l * pathLength);
|
var length = ((i + event.count / 30) % l) / l * pathLength;
|
||||||
|
var point = heartPath.getPointAt(length);
|
||||||
boids[i].arrive(point);
|
boids[i].arrive(point);
|
||||||
}
|
}
|
||||||
boids[i].run(boids);
|
boids[i].run(boids);
|
||||||
|
|
|
@ -68,14 +68,6 @@
|
||||||
path.strokeCap = 'round';
|
path.strokeCap = 'round';
|
||||||
path.strokeJoin = 'miter';
|
path.strokeJoin = 'miter';
|
||||||
|
|
||||||
var path = new Path.Circle([50, 50], 35);
|
|
||||||
path.strokeColor = 'black';
|
|
||||||
path.strokeWidth = 30;
|
|
||||||
path.strokeJoin = 'round';
|
|
||||||
path.strokeCap = 'round';
|
|
||||||
// path.scale(1, 0.5);
|
|
||||||
paths.push(path);
|
|
||||||
|
|
||||||
for (var i = 0; i < paths.length; i++) {
|
for (var i = 0; i < paths.length; i++) {
|
||||||
var path = paths[i];
|
var path = paths[i];
|
||||||
path.scale(1.5, new Point(300, 0));
|
path.scale(1.5, new Point(300, 0));
|
||||||
|
@ -88,6 +80,8 @@
|
||||||
rect.strokeColor = 'red'
|
rect.strokeColor = 'red'
|
||||||
rect.fillColor = null;
|
rect.fillColor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project.activeLayer.position = view.center;
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
* @class The View object wraps a canvas element and handles drawing and user
|
* @class The View object wraps a canvas element and handles drawing and user
|
||||||
* interaction through mouse and keyboard for it. It offer means to scroll the
|
* interaction through mouse and keyboard for it. It offer means to scroll the
|
||||||
* view, find the currently visible bounds in project coordinates, or the
|
* view, find the currently visible bounds in project coordinates, or the
|
||||||
* center, both useful fo constructing artwork that should appear centered on
|
* center, both useful for constructing artwork that should appear centered on
|
||||||
* screen.
|
* screen.
|
||||||
*/
|
*/
|
||||||
var View = this.View = Base.extend(/** @lends View# */{
|
var View = this.View = Base.extend(/** @lends View# */{
|
||||||
|
|
Loading…
Reference in a new issue