mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-05-23 02:56:43 -04:00
Clean up white spaces.
This commit is contained in:
parent
e573fe5dcd
commit
5655981f6d
34 changed files with 147 additions and 148 deletions
build
examples
Animated
Rasters
Scripts
Tools
lib
src
test
|
@ -19,5 +19,5 @@
|
|||
|
||||
echo "// Paper.js loader for development, as produced by the build/load.sh script
|
||||
var root = '../../';
|
||||
document.write('<script type=\"text/javascript\" src=\"' + root
|
||||
document.write('<script type=\"text/javascript\" src=\"' + root
|
||||
+ 'src/load.js\"></script>');" > ../dist/paper.js;
|
|
@ -30,7 +30,7 @@
|
|||
layer.insertChild(0, placedSymbol);
|
||||
}
|
||||
layer.position = view.center;
|
||||
|
||||
|
||||
function onFrame(event) {
|
||||
for (var i = 0, l = layer.children.length; i < l; i++) {
|
||||
var item = layer.children[i];
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
[new Point(104.91015625, 298.31494140625), new Point(44.30419921875, 0), new Point(-18.111328125, 0)],
|
||||
[new Point(56.984375, 286.0546875), new Point(10.03076171875, 6.6875)]
|
||||
];
|
||||
|
||||
|
||||
var lineGroup = new Group();
|
||||
var lineCount = 100;
|
||||
for (var i = 0; i < lineCount; i++) {
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
this.strength = param.strength ? param.strength : 0.55;
|
||||
this.mamb = values.invMass * values.invMass;
|
||||
},
|
||||
|
||||
|
||||
update: function() {
|
||||
var delta = this.b - this.a;
|
||||
var dist = delta.length;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<script type="text/javascript" src="../../dist/paper.js"></script>
|
||||
<script type="text/paperscript" canvas="canvas">
|
||||
var point = view.center;
|
||||
|
||||
|
||||
var colors = [];
|
||||
var cycles = 4;
|
||||
for (var i = 0, l = 60; i < l; i++) {
|
||||
|
@ -22,27 +22,27 @@
|
|||
var radius = Math.max(view.size.width, view.size.height) * 0.75;
|
||||
var gradientColor = new GradientColor(gradient, point, point + [radius, 0]);
|
||||
path.fillColor = gradientColor;
|
||||
|
||||
|
||||
var mouseDown = false,
|
||||
mousePoint = view.center;
|
||||
|
||||
|
||||
function onMouseDown(event) {
|
||||
mouseDown = true;
|
||||
mousePoint = event.point;
|
||||
}
|
||||
|
||||
|
||||
function onMouseDrag(event) {
|
||||
mousePoint = event.point;
|
||||
}
|
||||
|
||||
|
||||
function onMouseUp(event) {
|
||||
vector.length = 10;
|
||||
mouseDown = false;
|
||||
}
|
||||
|
||||
|
||||
var grow = false;
|
||||
var vector = new Point(150, 0);
|
||||
|
||||
|
||||
function onFrame() {
|
||||
for (var i = 0, l = gradient.stops.length; i < l; i++)
|
||||
gradient.stops[i].color.hue -= 20;
|
||||
|
@ -59,7 +59,7 @@
|
|||
}
|
||||
gradientColor.hilite = mouseDown ? point : point + vector;
|
||||
}
|
||||
|
||||
|
||||
function onResize(event) {
|
||||
point = view.center;
|
||||
path.bounds = view.bounds;
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
angle: 45,
|
||||
length: 0
|
||||
});
|
||||
|
||||
|
||||
var mouseVector = vector.clone();
|
||||
|
||||
function onMouseMove(event) {
|
||||
|
@ -45,7 +45,7 @@
|
|||
// The onFrame function is called up to 60 times a second:
|
||||
function onFrame(event) {
|
||||
vector = vector + (mouseVector - vector) / 30;
|
||||
|
||||
|
||||
// Run through the active layer's children list and change
|
||||
// the position of the placed symbols:
|
||||
for (var i = 0; i < count; i++) {
|
||||
|
@ -56,7 +56,7 @@
|
|||
keepInView(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function keepInView(item) {
|
||||
var position = item.position;
|
||||
var itemBounds = item.bounds;
|
||||
|
@ -72,7 +72,7 @@
|
|||
if (itemBounds.top > view.size.height) {
|
||||
position.y = -itemBounds.height;
|
||||
}
|
||||
|
||||
|
||||
if (position.y < -itemBounds.height) {
|
||||
position.y = bounds.height + itemBounds.height / 2;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<script type="text/paperscript" canvas="canvas">
|
||||
// Adapted from Flocking Processing example by Daniel Schiffman:
|
||||
// http://processing.org/learning/topics/flocking.html
|
||||
|
||||
|
||||
project.currentStyle = {
|
||||
strokeColor: 'white',
|
||||
strokeWidth: 2,
|
||||
|
@ -21,7 +21,7 @@
|
|||
var headSymbol = new Symbol(head);
|
||||
|
||||
var size = view.size;
|
||||
|
||||
|
||||
var Boid = Base.extend({
|
||||
initialize: function(position, maxSpeed, maxForce) {
|
||||
var strength = Math.random() * 0.5;
|
||||
|
@ -40,12 +40,12 @@
|
|||
if (i < 3)
|
||||
this.shortPath.add(this.loc);
|
||||
}
|
||||
|
||||
|
||||
this.firstSegment = this.path.segments[0];
|
||||
this.count = 0;
|
||||
this.lastRot = 0;
|
||||
},
|
||||
|
||||
|
||||
run: function(boids) {
|
||||
this.lastLoc = this.loc.clone();
|
||||
if (!groupTogether) {
|
||||
|
@ -77,12 +77,12 @@
|
|||
var rot = vector.angle;
|
||||
this.head.rotate(rot - this.lastRot);
|
||||
this.lastRot = rot;
|
||||
|
||||
|
||||
var shortSegments = this.shortPath.segments;
|
||||
for (var i = 0; i < 3; i++)
|
||||
shortSegments[i] = segments[i].clone();
|
||||
},
|
||||
|
||||
|
||||
// We accumulate a new acceleration each time based on three rules
|
||||
flock: function(boids) {
|
||||
var sep = this.separate(boids) * 3;
|
||||
|
@ -90,7 +90,7 @@
|
|||
var coh = this.cohesion(boids);
|
||||
this.acc += sep + ali + coh;
|
||||
},
|
||||
|
||||
|
||||
update: function() {
|
||||
// Update velocity
|
||||
this.vel += this.acc;
|
||||
|
@ -100,15 +100,15 @@
|
|||
// Reset acceleration to 0 each cycle
|
||||
this.acc.length = 0;
|
||||
},
|
||||
|
||||
|
||||
seek: function(target) {
|
||||
this.acc += this.steer(target, false);
|
||||
},
|
||||
|
||||
|
||||
arrive: function(target) {
|
||||
this.acc += this.steer(target, true);
|
||||
},
|
||||
|
||||
|
||||
// A method that calculates a steering vector towards a target
|
||||
// Takes a second argument, if true, it slows down as it approaches
|
||||
// the target
|
||||
|
@ -132,7 +132,7 @@
|
|||
}
|
||||
return steer;
|
||||
},
|
||||
|
||||
|
||||
borders: function() {
|
||||
var loc = this.loc;
|
||||
var r = this.r;
|
||||
|
@ -147,7 +147,7 @@
|
|||
if (!vector.isZero())
|
||||
this.path.position += vector;
|
||||
},
|
||||
|
||||
|
||||
separate: function(boids) {
|
||||
var desiredSeperation = 60;
|
||||
var steer = new Point(0, 0);
|
||||
|
@ -174,7 +174,7 @@
|
|||
}
|
||||
return steer;
|
||||
},
|
||||
|
||||
|
||||
// Alignment
|
||||
// For every nearby boid in the system, calculate the average velocity
|
||||
align: function(boids) {
|
||||
|
@ -195,7 +195,7 @@
|
|||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (count > 0)
|
||||
steer /= count;
|
||||
if (steer.length > 0) {
|
||||
|
@ -206,7 +206,7 @@
|
|||
}
|
||||
return steer;
|
||||
},
|
||||
|
||||
|
||||
// Cohesion
|
||||
// For the average location (i.e. center) of all nearby boids,
|
||||
// calculate steering vector towards that location
|
||||
|
@ -230,7 +230,7 @@
|
|||
return sum;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var heartPath = new Path([
|
||||
[[514.6962890625, 624.703125], [7.0966796875, -26.3369140625], [-7.10205078125, -27.0244140625]],
|
||||
[[484.29052734375, 548.6025390625], [13.16845703125, 23.7060546875], [-13.173828125, -23.70703125]],
|
||||
|
@ -254,7 +254,7 @@
|
|||
heartPath.position = view.center;
|
||||
heartPath.strokeColor = null;
|
||||
heartPath.scale(1.5);
|
||||
|
||||
|
||||
var groupTogether = false;
|
||||
var pathLength = heartPath.length;
|
||||
var mouseDown = false;
|
||||
|
@ -286,7 +286,7 @@
|
|||
function onMouseDown(event) {
|
||||
groupTogether = !groupTogether;
|
||||
}
|
||||
|
||||
|
||||
var layer = project.activeLayer;
|
||||
function onKeyDown(event) {
|
||||
if (event.key == 'space') {
|
||||
|
|
|
@ -52,7 +52,7 @@ function onMouseMove(event) {
|
|||
size = size.floor();
|
||||
secondPath.position += isLandscape
|
||||
? [size.width, 0]
|
||||
: [0, size.height];
|
||||
: [0, size.height];
|
||||
secondPath.fillColor = raster.getAverageColor(secondPath);
|
||||
secondPath.insertBelow(path);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// The amount of paths to produce:
|
||||
amount: 200
|
||||
};
|
||||
// Create a raster object, using the image
|
||||
// Create a raster object, using the image
|
||||
var raster = new Raster('sunflower');
|
||||
|
||||
// Transform the raster so it fills the bounding rectangle
|
||||
|
@ -29,7 +29,7 @@
|
|||
// Create the group of circle shaped paths and scale it up a bit:
|
||||
var group = createPhyllotaxis(values.amount);
|
||||
group.scale(3);
|
||||
|
||||
|
||||
function createPhyllotaxis(amount) {
|
||||
var group = new Group();
|
||||
// The Golden Angle (http://en.wikipedia.org/wiki/Golden_angle)
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
|
||||
if (path)
|
||||
path.remove();
|
||||
|
||||
|
||||
position = view.center;
|
||||
count = 0;
|
||||
path = new Path();
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
this.vector.x *= 0.99;
|
||||
var pre = this.point + this.vector;
|
||||
if (pre.x < this.radius || pre.x > size.width - this.radius)
|
||||
this.vector.x *= -this.dampen;
|
||||
this.vector.x *= -this.dampen;
|
||||
if (pre.y < this.radius || pre.y > size.height - this.radius) {
|
||||
if (Math.abs(this.vector.x) < 3)
|
||||
this.vector = Point.random() * [150, 100] + [-75, 20];
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
|
||||
var redPath = new Path.Circle(new Point(), 10);
|
||||
redPath.fillColor = 'red';
|
||||
|
||||
|
||||
function onResize() {
|
||||
// Whenever the view is resized:
|
||||
|
||||
// Fit the black path, so it covers the view:
|
||||
blackPath.fitBounds(view.bounds, true);
|
||||
|
||||
|
||||
// Fit the red path, so it fits inside the view:
|
||||
redPath.fitBounds(view.bounds);
|
||||
}
|
||||
|
|
|
@ -7,33 +7,33 @@
|
|||
<script type="text/javascript" src="../../dist/paper.js"></script>
|
||||
<script type="text/paperscript" canvas="canvas">
|
||||
var center = view.center;
|
||||
|
||||
|
||||
var path,
|
||||
h,
|
||||
s = 0.6,
|
||||
h,
|
||||
s = 0.6,
|
||||
l = 0.6,
|
||||
d = view.size.width * 0.012;
|
||||
p = new Point(),
|
||||
p = new Point(),
|
||||
r = view.size.width * .12;
|
||||
|
||||
|
||||
for (s = 0; s <= 1; s+=0.2) {
|
||||
for (h = 0; h < (s > 0 ? 360 : 1); h+= 20) {
|
||||
p.x = (center.x - r)*0.5 + Math.cos((h-90)/180*Math.PI) * r*s;
|
||||
p.y = center.y + Math.sin((h-90)/180*Math.PI) * r*s;
|
||||
path = new Path.Circle(p, Math.max(d*Math.sqrt(s), 5));
|
||||
path.fillColor = new HSLColor(h, s, 0.75);
|
||||
|
||||
|
||||
p.x = center.x + Math.cos((h-90)/180*Math.PI) * r*s;
|
||||
p.y = center.y + Math.sin((h-90)/180*Math.PI) * r*s;
|
||||
path = new Path.Circle(p, Math.max(d*Math.sqrt(s), 5));
|
||||
path.fillColor = new HSLColor(h, s, 0.5);
|
||||
|
||||
|
||||
p.x = center.x + (center.x + r) * .5 + Math.cos((h-90)/180*Math.PI) * r*s;
|
||||
p.y = center.y + Math.sin((h-90)/180*Math.PI) * r*s;
|
||||
path = new Path.Circle(p, Math.max(d*Math.sqrt(s), 5));
|
||||
path.fillColor = new HSLColor(h, s, 0.25);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
var path;
|
||||
var rect = new Rectangle([150, 150], [300, 300]);
|
||||
project.currentStyle.fillColor = 'black';
|
||||
|
||||
|
||||
function onFrame(event) {
|
||||
if (path)
|
||||
path.remove();
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
rect.strokeColor = 'green';
|
||||
rect.fillColor = null;
|
||||
}
|
||||
|
||||
|
||||
project.activeLayer.position = view.center;
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
@ -27,18 +27,18 @@
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
var currentSegment, mode, type;
|
||||
function onMouseDown(event) {
|
||||
if (currentSegment)
|
||||
currentSegment.selected = false;
|
||||
mode = type = currentSegment = null;
|
||||
|
||||
|
||||
if (!path) {
|
||||
path = new Path();
|
||||
path.fillColor = new HSBColor(360 * Math.random(), 1, 1, 0.5);
|
||||
}
|
||||
|
||||
|
||||
var result = findHandle(event.point);
|
||||
if (result) {
|
||||
currentSegment = result.segment;
|
||||
|
@ -51,7 +51,7 @@
|
|||
path = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mode != 'close') {
|
||||
mode = currentSegment ? 'move' : 'add';
|
||||
if (!currentSegment)
|
||||
|
@ -59,7 +59,7 @@
|
|||
currentSegment.selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onMouseDrag(event) {
|
||||
if (mode == 'move' && type == 'point') {
|
||||
currentSegment.point = event.point;
|
||||
|
@ -75,9 +75,9 @@
|
|||
</head>
|
||||
<body>
|
||||
<p>
|
||||
An emulation of a vector pen tool.
|
||||
An emulation of a vector pen tool.
|
||||
Click and drag to add a points.<br/>
|
||||
Drag segment handles and points to manipulate them.
|
||||
Drag segment handles and points to manipulate them.
|
||||
Close the path to start a new one.
|
||||
</p>
|
||||
<canvas id="canvas" resize></canvas>
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onMouseUp(event) {
|
||||
if (path) {
|
||||
path.add(event.point);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
project.currentStyle = {
|
||||
fillColor: 'black'
|
||||
};
|
||||
|
||||
|
||||
var handle_len_rate = 2.4;
|
||||
var circlePaths = [];
|
||||
var circlePath;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
var hue = Math.random() * 360;
|
||||
project.currentStyle.fillColor = new HSBColor(hue, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
function onMouseDrag(event) {
|
||||
var delta = event.point - event.downPoint;
|
||||
var radius = delta.length;
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
if (values.showCoordinates && !drag) {
|
||||
drawLength(vectorStart, vectorStart + [vector.x, 0],
|
||||
[1, 3].indexOf(quadrant) != -1 ? -1 : 1, true, vector.x, 'x: ');
|
||||
drawLength(vectorStart, vectorStart + [0, vector.y],
|
||||
drawLength(vectorStart, vectorStart + [0, vector.y],
|
||||
[1, 3].indexOf(quadrant) != -1 ? 1 : -1, true, vector.y, 'y: ');
|
||||
}
|
||||
for (var i = 0, l = dashedItems.length; i < l; i++) {
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
|
||||
// make a new line path from top to bottom
|
||||
new Path(top, bottom);
|
||||
|
||||
|
||||
// This is the point at the front of the worm:
|
||||
worm.firstSegment.point = event.point;
|
||||
|
||||
|
|
6
lib/bootstrap.js
vendored
6
lib/bootstrap.js
vendored
|
@ -1,10 +1,10 @@
|
|||
/**
|
||||
* Bootstrap JavaScript Library
|
||||
* (c) 2006 - 2011 Juerg Lehni, http://lehni.org/
|
||||
*
|
||||
*
|
||||
* Bootstrap is released under the MIT license
|
||||
* http://bootstrapjs.org/
|
||||
*
|
||||
*
|
||||
* Inspirations:
|
||||
* http://dean.edwards.name/weblog/2006/03/base/
|
||||
* http://dev.helma.org/Wiki/JavaScript+Inheritance+Sugar/
|
||||
|
@ -398,7 +398,7 @@ var Base = new function() { // Bootstrap scope
|
|||
|
||||
/**
|
||||
* A special constant, to be thrown by closures passed to each()
|
||||
*
|
||||
*
|
||||
* $continue / Base.next is not implemented, as the same
|
||||
* functionality can achieved by using return in the closure.
|
||||
* In prototype, the implementation of $continue also leads to a
|
||||
|
|
|
@ -553,7 +553,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
|
|||
// Avoid endless loops here: If sx is infinite and there was
|
||||
// no fitting ty, there's no solution for this bezier
|
||||
if (sx == -1)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -711,7 +711,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
|
|||
var maxDepth = 32,
|
||||
epsilon = Math.pow(2, -maxDepth - 1);
|
||||
|
||||
var zCubic = [
|
||||
var zCubic = [
|
||||
[1.0, 0.6, 0.3, 0.1],
|
||||
[0.4, 0.6, 0.6, 0.4],
|
||||
[0.1, 0.3, 0.6, 1.0]
|
||||
|
@ -745,7 +745,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
|
|||
// c's and d's
|
||||
for (var row = 0; row < n; row++) {
|
||||
cd[row] = [];
|
||||
for (var column = 0; column <= n; column++)
|
||||
for (var column = 0; column <= n; column++)
|
||||
cd[row][column] = d[row].dot(c[column]);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ var Numerical = new function() {
|
|||
sqrt = Math.sqrt,
|
||||
cos = Math.cos,
|
||||
PI = Math.PI;
|
||||
|
||||
|
||||
return {
|
||||
TOLERANCE: 10e-6,
|
||||
|
|
|
@ -55,7 +55,7 @@ function compareRectangles(rect1, rect2, message) {
|
|||
function compareRGBColors(color1, color2, message) {
|
||||
color1 = new RGBColor(color1);
|
||||
color2 = new RGBColor(color2);
|
||||
|
||||
|
||||
compareNumbers(color1.red, color2.red,
|
||||
(message || '') + ' red');
|
||||
compareNumbers(color1.green, color2.green,
|
||||
|
@ -69,7 +69,7 @@ function compareRGBColors(color1, color2, message) {
|
|||
function compareHSBColors(color1, color2, message) {
|
||||
color1 = new HSBColor(color1);
|
||||
color2 = new HSBColor(color2);
|
||||
|
||||
|
||||
compareNumbers(color1.hue, color2.hue,
|
||||
(message || '') + ' hue');
|
||||
compareNumbers(color1.saturation, color2.saturation,
|
||||
|
@ -83,7 +83,7 @@ function compareHSBColors(color1, color2, message) {
|
|||
function compareGrayColors(color1, color2, message) {
|
||||
color1 = new GrayColor(color1);
|
||||
color2 = new GrayColor(color2);
|
||||
|
||||
|
||||
compareNumbers(color1.gray, color2.gray,
|
||||
(message || '') + ' gray');
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ function compareItems(item, item2, checkIdentity) {
|
|||
equals(function() {
|
||||
return item != item2;
|
||||
}, true);
|
||||
|
||||
|
||||
equals(function() {
|
||||
return item.id != item2.id;
|
||||
}, true);
|
||||
|
@ -241,7 +241,7 @@ function compareItems(item, item2, checkIdentity) {
|
|||
|
||||
equals(item.position.toString(), item2.position.toString(),
|
||||
'Compare Item#position');
|
||||
|
||||
|
||||
if (item.matrix) {
|
||||
if (checkIdentity) {
|
||||
equals(function() {
|
||||
|
@ -308,7 +308,7 @@ function compareItems(item, item2, checkIdentity) {
|
|||
compareCharacterStyles(item.characterStyle, item2.characterStyle,
|
||||
checkIdentity);
|
||||
}
|
||||
|
||||
|
||||
// PointText specific:
|
||||
if (item instanceof PointText) {
|
||||
if (checkIdentity) {
|
||||
|
@ -318,7 +318,7 @@ function compareItems(item, item2, checkIdentity) {
|
|||
}
|
||||
equals(item.point.toString(), item2.point.toString(), checkIdentity);
|
||||
}
|
||||
|
||||
|
||||
if (item.style) {
|
||||
// Path Style
|
||||
comparePathStyles(item.style, item2.style, checkIdentity);
|
||||
|
|
|
@ -55,10 +55,10 @@ test('Set color to array', function() {
|
|||
});
|
||||
|
||||
test('Creating colors', function() {
|
||||
|
||||
|
||||
compareRGBColors(new RGBColor('#ff0000'), new RGBColor(1, 0, 0),
|
||||
'RGBColor from hex code');
|
||||
|
||||
|
||||
compareRGBColors(new RGBColor({ red: 1, green: 0, blue: 1}),
|
||||
new RGBColor(1, 0, 1), 'RGBColor from rgb object literal');
|
||||
|
||||
|
@ -70,7 +70,7 @@ test('Creating colors', function() {
|
|||
|
||||
compareRGBColors(new RGBColor([1, 0, 0]), new RGBColor(1, 0, 0),
|
||||
'RGBColor from array');
|
||||
|
||||
|
||||
compareHSBColors(new HSBColor('#000000'), new HSBColor(0, 0, 0),
|
||||
'HSBColor from hex code');
|
||||
|
||||
|
@ -82,7 +82,7 @@ test('Creating colors', function() {
|
|||
|
||||
compareHSBColors(new HSBColor([1, 0, 0]), new HSBColor(1, 0, 0),
|
||||
'HSBColor from array');
|
||||
|
||||
|
||||
compareGrayColors(new GrayColor('#000000'), new GrayColor(1),
|
||||
'GrayColor from hex code');
|
||||
|
||||
|
@ -123,14 +123,14 @@ test('Get red from HSBColor', function() {
|
|||
test('Get hue from RGBColor', function() {
|
||||
var color = new RGBColor(1, 0, 0);
|
||||
compareNumbers(color.hue, 0);
|
||||
compareNumbers(color.saturation, 1);
|
||||
compareNumbers(color.saturation, 1);
|
||||
});
|
||||
|
||||
test('Gray Color', function() {
|
||||
var color = new GrayColor(1);
|
||||
compareNumbers(color.gray, 1);
|
||||
compareNumbers(color.red, 0);
|
||||
|
||||
|
||||
color.red = 0.5;
|
||||
compareNumbers(color.gray, '0.84999');
|
||||
|
||||
|
@ -141,14 +141,14 @@ test('Gray Color', function() {
|
|||
test('Converting Colors', function() {
|
||||
var rgbColor = new RGBColor(1, 0.5, 0.2);
|
||||
compareNumbers(new GrayColor(rgbColor).gray, 0.38299560546875);
|
||||
|
||||
|
||||
var grayColor = new GrayColor(0.2);
|
||||
var rgbColor = new RGBColor(grayColor);
|
||||
compareRGBColors(rgbColor, [ 0.8, 0.8, 0.8, 1]);
|
||||
|
||||
|
||||
var hsbColor = new HSBColor(grayColor);
|
||||
compareHSBColors(hsbColor, [ 0, 0, 0.8, 1]);
|
||||
|
||||
|
||||
var rgbColor = new RGBColor(1, 0, 0);
|
||||
compareHSBColors(new HSBColor(rgbColor), [0, 1, 1, 1]);
|
||||
});
|
||||
|
@ -156,24 +156,24 @@ test('Converting Colors', function() {
|
|||
test('Setting RGBColor#gray', function() {
|
||||
var color = new RGBColor(1, 0.5, 0.2);
|
||||
color.gray = 0.1;
|
||||
compareRGBColors(color, [ 0.9, 0.9, 0.9, 1]);
|
||||
compareRGBColors(color, [ 0.9, 0.9, 0.9, 1]);
|
||||
});
|
||||
|
||||
test('Setting HSBColor#red', function() {
|
||||
var color = new HSBColor(180, 0, 0);
|
||||
color.red = 1;
|
||||
compareHSBColors(color, [0, 1, 1, 1]);
|
||||
compareHSBColors(color, [0, 1, 1, 1]);
|
||||
});
|
||||
|
||||
test('Setting HSBColor#gray', function() {
|
||||
var color = new HSBColor(180, 0, 0);
|
||||
color.gray = 0.5;
|
||||
compareHSBColors(color, [0, 0, 0.5, 1]);
|
||||
compareHSBColors(color, [0, 0, 0.5, 1]);
|
||||
});
|
||||
|
||||
test('Color.read(channels)', function() {
|
||||
var color = Color.read([0, 0, 1]);
|
||||
compareRGBColors(color, [0, 0, 1, 1]);
|
||||
compareRGBColors(color, [0, 0, 1, 1]);
|
||||
});
|
||||
|
||||
test('Cloning colors', function() {
|
||||
|
|
|
@ -32,7 +32,7 @@ test('moveTo / lineTo', function() {
|
|||
}
|
||||
|
||||
path.fillColor = 'black';
|
||||
|
||||
|
||||
equals(function() {
|
||||
return path.children.length;
|
||||
}, 2);
|
||||
|
|
|
@ -45,7 +45,7 @@ test('Group bounds', function() {
|
|||
var group = new Group([path, secondPath]);
|
||||
compareRectangles(group.bounds, { x: 90, y: 90, width: 170, height: 170 }, 'group.bounds');
|
||||
compareRectangles(group.strokeBounds, { x: 87.5, y: 87.5, width: 175, height: 175 }, 'group.strokeBounds');
|
||||
|
||||
|
||||
group.rotate(20);
|
||||
compareRectangles(group.bounds, { x: 89.97681, y: 82.94095, width: 170.04639, height: 177.08224 }, 'rotated group.bounds');
|
||||
compareRectangles(group.strokeBounds, { x: 87.47681, y: 80.44095, width: 175.04639, height: 182.08224 }, 'rotated group.strokeBounds');
|
||||
|
|
|
@ -156,7 +156,7 @@ test('isDescendant(item) / isAncestor(item)', function() {
|
|||
equals(function() {
|
||||
return project.activeLayer.isAncestor(path);
|
||||
}, true);
|
||||
|
||||
|
||||
// an item can't be its own descendant:
|
||||
equals(function() {
|
||||
return project.activeLayer.isDescendant(project.activeLayer);
|
||||
|
@ -173,7 +173,7 @@ test('isGroupedWith', function() {
|
|||
var secondPath = new Path();
|
||||
var group = new Group([path]);
|
||||
var secondGroup = new Group([secondPath]);
|
||||
|
||||
|
||||
equals(function() {
|
||||
return path.isGroupedWith(secondPath);
|
||||
}, false);
|
||||
|
@ -246,7 +246,7 @@ test('Check item#project when moving items across projects', function() {
|
|||
var path = new Path();
|
||||
var group = new Group();
|
||||
group.addChild(new Path());
|
||||
|
||||
|
||||
equals(function() {
|
||||
return path.project == doc1;
|
||||
}, true);
|
||||
|
@ -255,7 +255,7 @@ test('Check item#project when moving items across projects', function() {
|
|||
equals(function() {
|
||||
return path.project == doc2;
|
||||
}, true);
|
||||
|
||||
|
||||
doc2.activeLayer.addChild(group);
|
||||
equals(function() {
|
||||
return group.children[0].project == doc2;
|
||||
|
@ -270,12 +270,12 @@ test('group.selected', function() {
|
|||
equals(function() {
|
||||
return group.selected;
|
||||
}, true);
|
||||
|
||||
|
||||
path.selected = false;
|
||||
equals(function() {
|
||||
return group.selected;
|
||||
}, false);
|
||||
|
||||
|
||||
group.selected = true;
|
||||
equals(function() {
|
||||
return path.selected;
|
||||
|
@ -283,7 +283,7 @@ test('group.selected', function() {
|
|||
equals(function() {
|
||||
return path2.selected;
|
||||
}, true);
|
||||
|
||||
|
||||
group.selected = false;
|
||||
equals(function() {
|
||||
return path.selected;
|
||||
|
@ -299,22 +299,22 @@ test('Check parent children object for named item', function() {
|
|||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] == path;
|
||||
}, true);
|
||||
|
||||
|
||||
var path2 = new Path();
|
||||
path2.name = 'test';
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] == path2;
|
||||
}, true);
|
||||
|
||||
|
||||
path2.remove();
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] == path;
|
||||
}, true);
|
||||
|
||||
|
||||
path.remove();
|
||||
|
||||
|
||||
equals(function() {
|
||||
return !paper.project.activeLayer.children['test'];
|
||||
}, true);
|
||||
|
@ -326,9 +326,9 @@ test('Named child access 1', function() {
|
|||
|
||||
var path2 = new Path();
|
||||
path2.name = 'test';
|
||||
|
||||
|
||||
path.remove();
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] == path2;
|
||||
}, true);
|
||||
|
@ -340,23 +340,23 @@ test('Named child access 2', function() {
|
|||
|
||||
var path2 = new Path();
|
||||
path2.name = 'test';
|
||||
|
||||
|
||||
path.remove();
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] == path2;
|
||||
}, true);
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer._namedChildren['test'].length == 1;
|
||||
}, true);
|
||||
|
||||
|
||||
path2.remove();
|
||||
|
||||
equals(function() {
|
||||
return !paper.project.activeLayer._namedChildren['test'];
|
||||
}, true);
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] === undefined;
|
||||
}, true);
|
||||
|
@ -368,11 +368,11 @@ test('Named child access 3', function() {
|
|||
|
||||
var path2 = new Path();
|
||||
path2.name = 'test';
|
||||
|
||||
|
||||
var group = new Group();
|
||||
|
||||
|
||||
group.addChild(path2);
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] == path;
|
||||
}, true);
|
||||
|
@ -429,9 +429,9 @@ test('Setting name of child back to null', function() {
|
|||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] == path;
|
||||
}, true);
|
||||
|
||||
|
||||
path.name = null;
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] === undefined;
|
||||
}, true);
|
||||
|
@ -440,13 +440,13 @@ test('Setting name of child back to null', function() {
|
|||
test('Renaming item', function() {
|
||||
var path = new Path();
|
||||
path.name = 'test';
|
||||
|
||||
|
||||
path.name = 'test2';
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test'] === undefined;
|
||||
}, true);
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children['test2'] == path;
|
||||
}, true);
|
||||
|
|
|
@ -59,7 +59,7 @@ test('Path#clone() with GradientColor', function() {
|
|||
var colors = ['red', 'green', 'black'];
|
||||
var gradient = new Gradient(colors, 'radial');
|
||||
var color = new GradientColor(gradient, [0, 0], [20, 20], [10, 10]);
|
||||
|
||||
|
||||
var path = new Path([10, 20], [30, 40]);
|
||||
path.fillColor = color;
|
||||
cloneAndCompare(path);
|
||||
|
|
|
@ -26,7 +26,7 @@ test('previousSibling / nextSibling', function() {
|
|||
equals(function() {
|
||||
return secondLayer.nextSibling == null;
|
||||
}, true);
|
||||
|
||||
|
||||
// Move another layer into secondLayer and check nextSibling /
|
||||
// previousSibling:
|
||||
var path = new Path();
|
||||
|
@ -48,7 +48,7 @@ test('previousSibling / nextSibling', function() {
|
|||
equals(function() {
|
||||
return project.layers.length == 2;
|
||||
}, true);
|
||||
|
||||
|
||||
firstLayer.addChild(secondLayer);
|
||||
equals(function() {
|
||||
return project.layers.length == 1;
|
||||
|
@ -66,7 +66,7 @@ test('insertAbove / insertBelow', function() {
|
|||
equals(function() {
|
||||
return secondLayer.nextSibling == firstLayer;
|
||||
}, true);
|
||||
|
||||
|
||||
var path = new Path();
|
||||
firstLayer.addChild(path);
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ test('path.join(path)', function() {
|
|||
var path = new Path();
|
||||
path.add(0, 0);
|
||||
path.add(10, 0);
|
||||
|
||||
|
||||
var path2 = new Path();
|
||||
path2.add(10, 0);
|
||||
path2.add(20, 10);
|
||||
|
||||
|
||||
path.join(path2);
|
||||
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }');
|
||||
equals(function() {
|
||||
|
@ -34,13 +34,13 @@ test('path.join(path)', function() {
|
|||
var path = new Path();
|
||||
path.add(0, 0);
|
||||
path.add(10, 0);
|
||||
|
||||
|
||||
var path2 = new Path();
|
||||
path2.add(20, 10);
|
||||
path2.add(10, 0);
|
||||
path.join(path2);
|
||||
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }');
|
||||
|
||||
|
||||
var path = new Path();
|
||||
path.add(0, 0);
|
||||
path.add(10, 0);
|
||||
|
@ -60,9 +60,9 @@ test('path.join(path)', function() {
|
|||
path2.add(0, 0);
|
||||
path2.add(10, 5);
|
||||
path2.add(20, 10);
|
||||
|
||||
|
||||
path.join(path2);
|
||||
|
||||
|
||||
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } },{ point: { x: 10, y: 5 } }');
|
||||
equals(function() {
|
||||
return path.closed;
|
||||
|
@ -75,7 +75,7 @@ test('path.remove()', function() {
|
|||
path.add(10, 0);
|
||||
path.add(20, 0);
|
||||
path.add(30, 0);
|
||||
|
||||
|
||||
path.removeSegment(0);
|
||||
equals(function() {
|
||||
return path.segments.length;
|
||||
|
@ -92,7 +92,7 @@ test('path.remove()', function() {
|
|||
}, 1);
|
||||
|
||||
path.remove();
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.activeLayer.children.length;
|
||||
}, 0);
|
||||
|
@ -208,7 +208,7 @@ test('After cloning a selected item, it should be added to the Project#selectedI
|
|||
var path = new Path.Circle(new Size(80, 50), 35);
|
||||
path.selected = true;
|
||||
var copy = path.clone();
|
||||
|
||||
|
||||
equals(function() {
|
||||
return paper.project.selectedItems.length
|
||||
}, 2);
|
||||
|
|
|
@ -26,7 +26,7 @@ test('currentStyle', function() {
|
|||
paper.project.currentStyle.fillColor = 'black';
|
||||
var path = new Path();
|
||||
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
|
||||
|
||||
|
||||
// When changing the current style of the project, the style of
|
||||
// paths created using project.currentStyle should not change.
|
||||
paper.project.currentStyle.fillColor = 'red';
|
||||
|
@ -72,17 +72,17 @@ test('getting group styles', function() {
|
|||
group.addChild(path);
|
||||
|
||||
compareRGBColors(group.fillColor, 'red', 'group.fillColor');
|
||||
|
||||
|
||||
var secondPath = new Path();
|
||||
secondPath.fillColor = 'black';
|
||||
group.addChild(secondPath);
|
||||
|
||||
|
||||
// the group now contains two paths with different fillColors and therefore
|
||||
// should return undefined:
|
||||
equals(function() {
|
||||
return group.fillColor;
|
||||
}, undefined);
|
||||
|
||||
|
||||
//If we remove the first path, it should now return 'black':
|
||||
group.children[0].remove();
|
||||
compareRGBColors(group.fillColor, 'black', 'group.fillColor');
|
||||
|
@ -98,15 +98,15 @@ test('setting group styles', function() {
|
|||
secondPath.fillColor = 'blue';
|
||||
secondPath.strokeColor = 'red';
|
||||
group.addChild(secondPath);
|
||||
|
||||
|
||||
// Change the fill color of the group:
|
||||
group.fillColor = 'black';
|
||||
|
||||
|
||||
// the paths contained in the group should now both have their fillColor
|
||||
// set to black:
|
||||
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
|
||||
compareRGBColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
|
||||
|
||||
|
||||
// The second path still has its strokeColor set to red:
|
||||
compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
||||
});
|
||||
|
@ -116,14 +116,14 @@ test('setting group styles 2', function() {
|
|||
var path = new Path();
|
||||
path.fillColor = 'red';
|
||||
group.addChild(path);
|
||||
|
||||
|
||||
compareRGBColors(group.fillColor, 'red', 'group.fillColor');
|
||||
|
||||
|
||||
var secondPath = new Path();
|
||||
secondPath.fillColor = 'blue';
|
||||
secondPath.strokeColor = 'red';
|
||||
group.addChild(secondPath);
|
||||
|
||||
|
||||
compareRGBColors(secondPath.fillColor, 'blue', 'secondPath.fillColor');
|
||||
compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
||||
|
||||
|
@ -132,18 +132,18 @@ test('setting group styles 2', function() {
|
|||
equals(function() {
|
||||
return group.fillColor;
|
||||
}, undefined);
|
||||
|
||||
|
||||
// But, both paths have a red strokeColor, so:
|
||||
compareRGBColors(group.strokeColor, 'red', 'group.strokeColor');
|
||||
|
||||
|
||||
// Change the fill color of the group's style:
|
||||
group.style.fillColor = 'black';
|
||||
|
||||
|
||||
// the paths contained in the group should now both have their fillColor
|
||||
// set to black:
|
||||
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
|
||||
compareRGBColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
|
||||
|
||||
|
||||
// The second path still has its strokeColor set to red:
|
||||
compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
||||
});
|
|
@ -49,7 +49,7 @@ test('path.flatten(maxDistance)', function() {
|
|||
equals(function() {
|
||||
return path.lastSegment.point.equals(path.firstSegment.point);
|
||||
}, false, 'The points of the last and first segments should not be the same.');
|
||||
|
||||
|
||||
equals(function() {
|
||||
return path.lastSegment.point.toString() != path.segments[path.segments.length - 2].point.toString();
|
||||
}, true, 'The points of the last and before last segments should not be so close, that calling toString on them returns the same string value.');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue