Rename RGBColor -> RgbColor, to avoid clash with native constructor, and follow same naming convention for HsbColor and HslColor, but keep references to old names for PaperScript scopes for now.

This commit is contained in:
Jürg Lehni 2011-11-10 19:16:34 +01:00
parent c4bea4d24c
commit 42d0e722db
19 changed files with 171 additions and 171 deletions

View file

@ -9,7 +9,7 @@
var amount = 180;
for (var i = 0; i < amount; i++) {
var path = new Path();
path.fillColor = new HSBColor(1, 1, Math.random());
path.fillColor = new HsbColor(1, 1, Math.random());
path.strokeCap = 'round';
path.closed = true;
}

View file

@ -13,7 +13,7 @@
for (var i = 0, l = 60; i < l; i++) {
var brightness = 1 - (i / l) * 1.5;
var hue = i / l * cycles * 360;
var color = new HSBColor(hue, 1, brightness);
var color = new HsbColor(hue, 1, brightness);
colors.push(color);
}

View file

@ -31,7 +31,7 @@
new Path.Circle(this.point, this.radius),
new Path.Circle(overlayPos, this.radius / 2)
]);
var color = new HSBColor(Math.random() * 360, 1, 1);
var color = new HsbColor(Math.random() * 360, 1, 1);
var gradient = new Gradient([color, 'black'], 'radial');
compound.children[0].fillColor = new GradientColor(gradient, this.point,
this.point + this.radius, overlayPos);
@ -39,7 +39,7 @@
var overlayColor = color.clone();
var fullOverlay = color.clone();
overlayColor.alpha = 0.5;
var overlayGradient = new Gradient([new RGBColor(1, 1, 1, 0.5), new RGBColor(1, 1, 1, 1)]);
var overlayGradient = new Gradient([new RgbColor(1, 1, 1, 0.5), new RgbColor(1, 1, 1, 1)]);
overlay.fillColor = new GradientColor(overlayGradient, overlayPos, overlayPos + this.radius / 2);
this.item = new Group([compound, overlay]);
},

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>HSLColor</title>
<title>HslColor</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">
@ -35,7 +35,7 @@
var colors = [];
for (var i = 0; i < steps.saturation; i++) {
var saturation = i / steps.saturation;
var color = new HSLColor(hue, saturation, lightness);
var color = new HslColor(hue, saturation, lightness);
colors.push(color);
}
var gradient = new Gradient(colors, 'radial');

View file

@ -36,7 +36,7 @@
if (!path) {
path = new Path();
path.fillColor = new HSBColor(360 * Math.random(), 1, 1, 0.5);
path.fillColor = new HsbColor(360 * Math.random(), 1, 1, 0.5);
}
var result = findHandle(event.point);

View file

@ -30,7 +30,7 @@
var lightness = (Math.random() - 0.5) * 0.4 + 0.4;
var hue = Math.random() * 360;
path.style = {
fillColor: new HSLColor(hue, 1, lightness),
fillColor: new HslColor(hue, 1, lightness),
strokeColor: 'black'
};
};

View file

@ -8,7 +8,7 @@
<script type="text/paperscript" canvas="canvas">
function onMouseDown(event) {
var hue = Math.random() * 360;
project.currentStyle.fillColor = new HSBColor(hue, 1, 1);
project.currentStyle.fillColor = new HsbColor(hue, 1, 1);
}
function onMouseDrag(event) {

View file

@ -19,10 +19,10 @@
* @name Color
*
* @class All properties and functions that expect color values accept
* instances of the different color classes such as {@link RGBColor},
* {@link HSBColor} and {@link GrayColor}, and also accept named colors
* instances of the different color classes such as {@link RgbColor},
* {@link HsbColor} and {@link GrayColor}, and also accept named colors
* and hex values as strings which are then converted to instances of
* {@link RGBColor} internally.
* {@link RgbColor} internally.
*
* @classexample {@paperscript}
* // Named color values:
@ -32,7 +32,7 @@
* var circle = new Path.Circle(new Point(80, 50), 30);
*
* // Pass a color name to the fillColor property, which is internally
* // converted to an RGBColor.
* // converted to an RgbColor.
* circle.fillColor = 'green';
*
* @classexample {@paperscript}
@ -43,7 +43,7 @@
* var circle = new Path.Circle(new Point(80, 50), 30);
*
* // Pass a hex string to the fillColor property, which is internally
* // converted to an RGBColor.
* // converted to an RgbColor.
* circle.fillColor = '#ff0000';
*/
var Color = this.Color = Base.extend(new function() {
@ -58,7 +58,7 @@ var Color = this.Color = Base.extend(new function() {
var colorCache = {},
colorContext;
function nameToRGBColor(name) {
function nameToRgbColor(name) {
var color = colorCache[name];
if (color)
return color.clone();
@ -79,10 +79,10 @@ var Color = this.Color = Base.extend(new function() {
colorContext.fillRect(0, 0, 1, 1);
var data = colorContext.getImageData(0, 0, 1, 1).data,
rgb = [data[0] / 255, data[1] / 255, data[2] / 255];
return (colorCache[name] = RGBColor.read(rgb)).clone();
return (colorCache[name] = RgbColor.read(rgb)).clone();
}
function hexToRGBColor(string) {
function hexToRgbColor(string) {
var hex = string.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
if (hex.length >= 4) {
var rgb = new Array(3);
@ -91,7 +91,7 @@ var Color = this.Color = Base.extend(new function() {
rgb[i] = parseInt(channel.length == 1
? channel + channel : channel, 16) / 255;
}
return RGBColor.read(rgb);
return RgbColor.read(rgb);
}
}
@ -120,7 +120,7 @@ var Color = this.Color = Base.extend(new function() {
: (r - g) / delta + 4) * 60, // max == b
s = max == 0 ? 0 : delta / max,
v = max; // = brightness, also called value
return new HSBColor(h, s, v, color._alpha);
return new HsbColor(h, s, v, color._alpha);
},
'hsb-rgb': function(color) {
@ -136,7 +136,7 @@ var Color = this.Color = Base.extend(new function() {
b * (1 - s * f), // q, index 2
b * (1 - s * (1 - f)) // t, index 3
];
return new RGBColor(v[i[0]], v[i[1]], v[i[2]], color._alpha);
return new RgbColor(v[i[0]], v[i[1]], v[i[2]], color._alpha);
},
// HSL code is based on:
@ -157,7 +157,7 @@ var Color = this.Color = Base.extend(new function() {
s = achromatic ? 0 : l < 0.5
? delta / (max + min)
: delta / (2 - max - min);
return new HSLColor(h, s, l, color._alpha);
return new HslColor(h, s, l, color._alpha);
},
'hsl-rgb': function(color) {
@ -166,7 +166,7 @@ var Color = this.Color = Base.extend(new function() {
l = color._lightness,
t1, t2, c;
if (s == 0)
return new RGBColor(l, l, l, color._alpha);
return new RgbColor(l, l, l, color._alpha);
var t3s = [ h + 1 / 3, h, h - 1 / 3 ],
t2 = l < 0.5 ? l * (1 + s) : l + s - l * s,
t1 = 2 * l - t2,
@ -183,7 +183,7 @@ var Color = this.Color = Base.extend(new function() {
? t1 + (t2 - t1) * ((2 / 3) - t3) * 6
: t1;
}
return new RGBColor(c[0], c[1], c[2], color._alpha);
return new RgbColor(c[0], c[1], c[2], color._alpha);
},
'rgb-gray': function(color) {
@ -196,15 +196,15 @@ var Color = this.Color = Base.extend(new function() {
'gray-rgb': function(color) {
var comp = 1 - color._gray;
return new RGBColor(comp, comp, comp, color._alpha);
return new RgbColor(comp, comp, comp, color._alpha);
},
'gray-hsb': function(color) {
return new HSBColor(0, 0, 1 - color._gray, color._alpha);
return new HsbColor(0, 0, 1 - color._gray, color._alpha);
},
'gray-hsl': function(color) {
return new HSLColor(0, 0, 1 - color._gray, color._alpha);
return new HslColor(0, 0, 1 - color._gray, color._alpha);
}
};
@ -219,16 +219,16 @@ var Color = this.Color = Base.extend(new function() {
// Called on the abstract Color class. Guess color type
// from arg
return arg.red !== undefined
? new RGBColor(arg.red, arg.green, arg.blue, arg.alpha)
? new RgbColor(arg.red, arg.green, arg.blue, arg.alpha)
: arg.gray !== undefined
? new GrayColor(arg.gray, arg.alpha)
: arg.lightness !== undefined
? new HSLColor(arg.hue, arg.saturation, arg.lightness,
? new HslColor(arg.hue, arg.saturation, arg.lightness,
arg.alpha)
: arg.hue !== undefined
? new HSBColor(arg.hue, arg.saturation, arg.brightness,
? new HsbColor(arg.hue, arg.saturation, arg.brightness,
arg.alpha)
: new RGBColor(); // Fallback
: new RgbColor(); // Fallback
} else {
// Called on a subclass instance. Return the converted
// color.
@ -236,8 +236,8 @@ var Color = this.Color = Base.extend(new function() {
}
} else if (typeof arg === 'string') {
var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i)
? hexToRGBColor(arg)
: nameToRGBColor(arg);
? hexToRgbColor(arg)
: nameToRgbColor(arg);
return type
? rgbColor.convert(type)
: rgbColor;
@ -248,9 +248,9 @@ var Color = this.Color = Base.extend(new function() {
// Called on the abstract Color class. Guess color type
// from arg
//if (components.length >= 4)
// return new CMYKColor(components);
// return new CmykColor(components);
if (components.length >= 3)
return new RGBColor(components);
return new RgbColor(components);
return new GrayColor(components);
} else {
// Called on a subclass instance. Just copy over
@ -268,7 +268,7 @@ var Color = this.Color = Base.extend(new function() {
},
/**
* @return {RGBColor|GrayColor|HSBColor} a copy of the color object
* @return {RgbColor|GrayColor|HsbColor} a copy of the color object
*/
clone: function() {
var ctor = this.constructor,
@ -395,7 +395,7 @@ var Color = this.Color = Base.extend(new function() {
* @bean
*
* @example
* var color = new RGBColor(1, 0, 0);
* var color = new RgbColor(1, 0, 0);
* console.log(color.type); // 'rgb'
*/
getType: function() {
@ -671,15 +671,15 @@ var GrayColor = this.GrayColor = Color.extend(/** @lends GrayColor# */{
});
/**
* @name RGBColor
* @class An RGBColor object is used to represent any RGB color value.
* @name RgbColor
* @class An RgbColor object is used to represent any RGB color value.
* @extends Color
*/
var RGBColor = this.RGBColor = Color.extend(/** @lends RGBColor# */{
var RgbColor = this.RgbColor = this.RGBColor = Color.extend(/** @lends RgbColor# */{
/**
* Creates an RGBColor object
* Creates an RgbColor object
*
* @name RGBColor#initialize
* @name RgbColor#initialize
* @param {Number} red the amount of red in the color as a value
* between {@code 0} and {@code 1}
* @param {Number} green the amount of green in the color as a value
@ -690,21 +690,21 @@ var RGBColor = this.RGBColor = Color.extend(/** @lends RGBColor# */{
* {@code 0} and {@code 1}
*
* @example {@paperscript}
* // Creating an RGBColor:
* // Creating an RgbColor:
*
* // Create a circle shaped path at {x: 80, y: 50}
* // with a radius of 30:
* var circle = new Path.Circle(new Point(80, 50), 30);
*
* // 100% red, 0% blue, 50% blue:
* circle.fillColor = new RGBColor(1, 0, 0.5);
* circle.fillColor = new RgbColor(1, 0, 0.5);
*/
/**
* The amount of red in the color as a value between {@code 0} and
* {@code 1}.
*
* @name RGBColor#red
* @name RgbColor#red
* @property
* @type Number
*
@ -721,7 +721,7 @@ var RGBColor = this.RGBColor = Color.extend(/** @lends RGBColor# */{
* The amount of green in the color as a value between {@code 0} and
* {@code 1}.
*
* @name RGBColor#green
* @name RgbColor#green
* @property
* @type Number
*
@ -740,7 +740,7 @@ var RGBColor = this.RGBColor = Color.extend(/** @lends RGBColor# */{
* The amount of blue in the color as a value between {@code 0} and
* {@code 1}.
*
* @name RGBColor#blue
* @name RgbColor#blue
* @property
* @type Number
*
@ -759,15 +759,15 @@ var RGBColor = this.RGBColor = Color.extend(/** @lends RGBColor# */{
});
/**
* @name HSBColor
* @class An HSBColor object is used to represent any HSB color value.
* @name HsbColor
* @class An HsbColor object is used to represent any HSB color value.
* @extends Color
*/
var HSBColor = this.HSBColor = Color.extend(/** @lends HSBColor# */{
var HsbColor = this.HsbColor = this.HSBColor = Color.extend(/** @lends HsbColor# */{
/**
* Creates an HSBColor object
* Creates an HsbColor object
*
* @name HSBColor#initialize
* @name HsbColor#initialize
* @param {Number} hue the hue of the color as a value in degrees between
* {@code 0} and {@code 360}.
* @param {Number} saturation the saturation of the color as a value
@ -778,22 +778,22 @@ var HSBColor = this.HSBColor = Color.extend(/** @lends HSBColor# */{
* {@code 0} and {@code 1}
*
* @example {@paperscript}
* // Creating an HSBColor:
* // Creating an HsbColor:
*
* // Create a circle shaped path at {x: 80, y: 50}
* // with a radius of 30:
* var circle = new Path.Circle(new Point(80, 50), 30);
*
* // Create an HSBColor with a hue of 90 degrees, a saturation
* // Create an HsbColor with a hue of 90 degrees, a saturation
* // 100% and a brightness of 100%:
* circle.fillColor = new HSBColor(90, 1, 1);
* circle.fillColor = new HsbColor(90, 1, 1);
*/
/**
* The hue of the color as a value in degrees between {@code 0} and
* {@code 360}.
*
* @name HSBColor#hue
* @name HsbColor#hue
* @property
* @type Number
*
@ -819,7 +819,7 @@ var HSBColor = this.HSBColor = Color.extend(/** @lends HSBColor# */{
/**
* The saturation of the color as a value between {@code 0} and {@code 1}.
*
* @name HSBColor#saturation
* @name HsbColor#saturation
* @property
* @type Number
*/
@ -827,7 +827,7 @@ var HSBColor = this.HSBColor = Color.extend(/** @lends HSBColor# */{
/**
* The brightness of the color as a value between {@code 0} and {@code 1}.
*
* @name HSBColor#brightness
* @name HsbColor#brightness
* @property
* @type Number
*/
@ -837,15 +837,15 @@ var HSBColor = this.HSBColor = Color.extend(/** @lends HSBColor# */{
/**
* @name HSLColor
* @class An HSLColor object is used to represent any HSL color value.
* @name HslColor
* @class An HslColor object is used to represent any HSL color value.
* @extends Color
*/
var HSLColor = this.HSLColor = Color.extend(/** @lends HSLColor# */{
var HslColor = this.HslColor = this.HSLColor = Color.extend(/** @lends HslColor# */{
/**
* Creates an HSLColor object
* Creates an HslColor object
*
* @name HSLColor#initialize
* @name HslColor#initialize
* @param {Number} hue the hue of the color as a value in degrees between
* {@code 0} and {@code 360}.
* @param {Number} saturation the saturation of the color as a value
@ -856,22 +856,22 @@ var HSLColor = this.HSLColor = Color.extend(/** @lends HSLColor# */{
* {@code 0} and {@code 1}
*
* @example {@paperscript}
* // Creating an HSLColor:
* // Creating an HslColor:
*
* // Create a circle shaped path at {x: 80, y: 50}
* // with a radius of 30:
* var circle = new Path.Circle(new Point(80, 50), 30);
*
* // Create an HSLColor with a hue of 90 degrees, a saturation
* // Create an HslColor with a hue of 90 degrees, a saturation
* // 100% and a lightness of 50%:
* circle.fillColor = new HSLColor(90, 1, 0.5);
* circle.fillColor = new HslColor(90, 1, 0.5);
*/
/**
* The hue of the color as a value in degrees between {@code 0} and
* {@code 360}.
*
* @name HSLColor#hue
* @name HslColor#hue
* @property
* @type Number
*/
@ -879,7 +879,7 @@ var HSLColor = this.HSLColor = Color.extend(/** @lends HSLColor# */{
/**
* The saturation of the color as a value between {@code 0} and {@code 1}.
*
* @name HSLColor#saturation
* @name HslColor#saturation
* @property
* @type Number
*/
@ -887,7 +887,7 @@ var HSLColor = this.HSLColor = Color.extend(/** @lends HSLColor# */{
/**
* The lightness of the color as a value between {@code 0} and {@code 1}.
*
* @name HSLColor#lightness
* @name HslColor#lightness
* @property
* @type Number
*/

View file

@ -24,7 +24,7 @@ var GradientStop = this.GradientStop = Base.extend(/** @lends GradientStop# */{
/**
* Creates a GradientStop object.
*
* @param {Color} [color=new RGBColor(0, 0, 0)] the color of the stop
* @param {Color} [color=new RgbColor(0, 0, 0)] the color of the stop
* @param {Number} [rampPoint=0] the position of the stop on the gradient
* ramp {@default 0}
*/

View file

@ -720,7 +720,7 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
* <b>options.fill:</b> {@code Boolean} - Hit test the fill of items.
* <b>options.stroke:</b> {@code Boolean} - Hit test the curves of path
* items, taking into account stroke width.
* <b>options.segments:</b> {@code Boolean} - Hit test for
* <b>options.segment:</b> {@code Boolean} - Hit test for
* {@link Segment#point} of {@link Path} items.
* <b>options.handles:</b> {@code Boolean} - Hit test for the handles
* ({@link Segment#handleIn} / {@link Segment#handleOut}) of path segments.
@ -1291,7 +1291,7 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
*
* @property
* @name Item#strokeColor
* @type RGBColor|HSBColor|HSLColor|GrayColor
* @type RgbColor|HsbColor|HslColor|GrayColor
*
* @example {@paperscript}
* // Setting the stroke color of a path:
@ -1301,7 +1301,7 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
* var circle = new Path.Circle(new Point(80, 50), 35);
*
* // Set its stroke color to RGB red:
* circle.strokeColor = new RGBColor(1, 0, 0);
* circle.strokeColor = new RgbColor(1, 0, 0);
*/
/**
@ -1435,7 +1435,7 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
*
* @property
* @name Item#fillColor
* @type RGBColor|HSBColor|HSLColor|GrayColor
* @type RgbColor|HsbColor|HslColor|GrayColor
*
* @example {@paperscript}
* // Setting the fill color of a path to red:
@ -1445,7 +1445,7 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
* var circle = new Path.Circle(new Point(80, 50), 35);
*
* // Set the fill color of the circle to RGB red:
* circle.fillColor = new RGBColor(1, 0, 0);
* circle.fillColor = new RgbColor(1, 0, 0);
*/
// DOCS: document the different arguments that this function can receive.

View file

@ -222,7 +222,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
* effects.
*
* @param {Path|Rectangle|Point} object
* @return {RGBColor} the average color contained in the area covered by the
* @return {RgbColor} the average color contained in the area covered by the
* specified path, rectangle or point.
*/
getAverageColor: function(object) {
@ -294,7 +294,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
* @function
* @param x the x offset of the pixel in pixel coordinates
* @param y the y offset of the pixel in pixel coordinates
* @return {RGBColor} the color of the pixel
* @return {RgbColor} the color of the pixel
*/
/**
* Gets the color of a pixel in the raster.
@ -302,7 +302,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
* @name Raster#getPixel
* @function
* @param point the offset of the pixel as a point in pixel coordinates
* @return {RGBColor} the color of the pixel
* @return {RgbColor} the color of the pixel
*/
getPixel: function(point) {
point = Point.read(arguments);
@ -310,7 +310,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
channels = new Array(4);
for (var i = 0; i < 4; i++)
channels[i] = pixels[i] / 255;
return RGBColor.read(channels);
return RgbColor.read(channels);
},
/**

View file

@ -30,7 +30,7 @@
*
* @classexample {@paperscript}
* var circleStyle = {
* fillColor: new RGBColor(1, 0, 0),
* fillColor: new RgbColor(1, 0, 0),
* strokeColor: 'black',
* strokeWidth: 5
* };
@ -77,7 +77,7 @@ var PathStyle = this.PathStyle = Style.extend(/** @lends PathStyle# */{
*
* @property
* @name PathStyle#strokeColor
* @type RGBColor|HSBColor|HSLColor|GrayColor
* @type RgbColor|HsbColor|HslColor|GrayColor
*
* @example {@paperscript}
* // Setting the stroke color of a path:
@ -87,7 +87,7 @@ var PathStyle = this.PathStyle = Style.extend(/** @lends PathStyle# */{
* var circle = new Path.Circle(new Point(80, 50), 35);
*
* // Set its stroke color to RGB red:
* circle.strokeColor = new RGBColor(1, 0, 0);
* circle.strokeColor = new RgbColor(1, 0, 0);
*/
/**
@ -220,7 +220,7 @@ var PathStyle = this.PathStyle = Style.extend(/** @lends PathStyle# */{
*
* @property
* @name PathStyle#fillColor
* @type RGBColor|HSBColor|HSLColor|GrayColor
* @type RgbColor|HsbColor|HslColor|GrayColor
*
* @example {@paperscript}
* // Setting the fill color of a path to red:
@ -230,6 +230,6 @@ var PathStyle = this.PathStyle = Style.extend(/** @lends PathStyle# */{
* var circle = new Path.Circle(new Point(80, 50), 35);
*
* // Set the fill color of the circle to RGB red:
* circle.fillColor = new RGBColor(1, 0, 0);
* circle.fillColor = new RgbColor(1, 0, 0);
*/
});

View file

@ -52,9 +52,9 @@ function compareRectangles(rect1, rect2, message) {
(message || '') + ' height');
}
function compareRGBColors(color1, color2, message) {
color1 = new RGBColor(color1);
color2 = new RGBColor(color2);
function compareRgbColors(color1, color2, message) {
color1 = new RgbColor(color1);
color2 = new RgbColor(color2);
compareNumbers(color1.red, color2.red,
(message || '') + ' red');
@ -66,9 +66,9 @@ function compareRGBColors(color1, color2, message) {
(message || '') + ' alpha');
}
function compareHSBColors(color1, color2, message) {
color1 = new HSBColor(color1);
color2 = new HSBColor(color2);
function compareHsbColors(color1, color2, message) {
color1 = new HsbColor(color1);
color2 = new HsbColor(color2);
compareNumbers(color1.hue, color2.hue,
(message || '') + ' hue');

View file

@ -19,69 +19,69 @@ module('Color');
test('Set named color', function() {
var path = new Path();
path.fillColor = 'red';
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
compareRgbColors(path.fillColor, new RgbColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
});
test('Set color to hex', function() {
var path = new Path();
path.fillColor = '#ff0000';
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
compareRgbColors(path.fillColor, new RgbColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
var path = new Path();
path.fillColor = '#f00';
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
compareRgbColors(path.fillColor, new RgbColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
});
test('Set color to object', function() {
var path = new Path();
path.fillColor = { red: 1, green: 0, blue: 1};
compareRGBColors(path.fillColor, new RGBColor(1, 0, 1));
compareRgbColors(path.fillColor, new RgbColor(1, 0, 1));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 255, 1)');
var path = new Path();
path.fillColor = { gray: 0.2 };
compareRGBColors(path.fillColor, new RGBColor(0.8, 0.8, 0.8));
compareRgbColors(path.fillColor, new RgbColor(0.8, 0.8, 0.8));
equals(path.fillColor.toCssString(), 'rgba(204, 204, 204, 1)');
});
test('Set color to array', function() {
var path = new Path();
path.fillColor = [1, 0, 0];
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
compareRgbColors(path.fillColor, new RgbColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
});
test('Creating colors', function() {
compareRGBColors(new RGBColor('#ff0000'), new RGBColor(1, 0, 0),
'RGBColor from hex code');
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');
compareRgbColors(new RgbColor({ red: 1, green: 0, blue: 1}),
new RgbColor(1, 0, 1), 'RgbColor from rgb object literal');
compareRGBColors(new RGBColor({ gray: 0.2 }),
new RGBColor(0.8, 0.8, 0.8), 'RGBColor from gray object literal');
compareRgbColors(new RgbColor({ gray: 0.2 }),
new RgbColor(0.8, 0.8, 0.8), 'RgbColor from gray object literal');
compareRGBColors(new RGBColor({ hue: 0, saturation: 1, brightness: 1}),
new RGBColor(1, 0, 0), 'RGBColor from hsb object literal');
compareRgbColors(new RgbColor({ hue: 0, saturation: 1, brightness: 1}),
new RgbColor(1, 0, 0), 'RgbColor from hsb object literal');
compareRGBColors(new RGBColor([1, 0, 0]), new RGBColor(1, 0, 0),
'RGBColor from array');
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');
compareHsbColors(new HsbColor('#000000'), new HsbColor(0, 0, 0),
'HsbColor from hex code');
compareHSBColors(new HSBColor({ red: 1, green: 0, blue: 0}),
new HSBColor(0, 1, 1), 'HSBColor from rgb object literal');
compareHsbColors(new HsbColor({ red: 1, green: 0, blue: 0}),
new HsbColor(0, 1, 1), 'HsbColor from rgb object literal');
compareHSBColors(new HSBColor({ gray: 0.8 }),
new HSBColor(0, 0, 0.2), 'RGBColor from gray object literal');
compareHsbColors(new HsbColor({ gray: 0.8 }),
new HsbColor(0, 0, 0.2), 'RgbColor from gray object literal');
compareHSBColors(new HSBColor([1, 0, 0]), new HSBColor(1, 0, 0),
'HSBColor from array');
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');
@ -102,26 +102,26 @@ test('Creating colors', function() {
'GrayColor from array');
});
test('Get gray from RGBColor', function() {
var color = new RGBColor(1, 0.5, 0.2);
test('Get gray from RgbColor', function() {
var color = new RgbColor(1, 0.5, 0.2);
compareNumbers(color.gray, 0.38458251953125);
var color = new RGBColor(0.5, 0.2, 0.1);
var color = new RgbColor(0.5, 0.2, 0.1);
compareNumbers(color.gray, 0.72137451171875);
});
test('Get gray from HSBColor', function() {
var color = new HSBColor(0, 0, 0.2);
test('Get gray from HsbColor', function() {
var color = new HsbColor(0, 0, 0.2);
compareNumbers(color.gray, 0.8);
});
test('Get red from HSBColor', function() {
var color = new HSBColor(0, 1, 1);
test('Get red from HsbColor', function() {
var color = new HsbColor(0, 1, 1);
compareNumbers(color.red, 1);
});
test('Get hue from RGBColor', function() {
var color = new RGBColor(1, 0, 0);
test('Get hue from RgbColor', function() {
var color = new RgbColor(1, 0, 0);
compareNumbers(color.hue, 0);
compareNumbers(color.saturation, 1);
});
@ -139,56 +139,56 @@ test('Gray Color', function() {
});
test('Converting Colors', function() {
var rgbColor = new RGBColor(1, 0.5, 0.2);
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 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 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]);
var rgbColor = new RgbColor(1, 0, 0);
compareHsbColors(new HsbColor(rgbColor), [0, 1, 1, 1]);
});
test('Setting RGBColor#gray', function() {
var color = new RGBColor(1, 0.5, 0.2);
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);
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);
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() {
var color = new RGBColor(0, 0, 0);
var color = new RgbColor(0, 0, 0);
equals(function() {
return color.clone() != color;
}, true);
equals(function() {
return new RGBColor(color) != color;
return new RgbColor(color) != color;
}, true);
});
test('Color#convert', function() {
var color = new RGBColor(0, 0, 0);
var color = new RgbColor(0, 0, 0);
var converted = color.convert('rgb');
equals(function() {
return converted !== color;
@ -200,6 +200,6 @@ test('Color#convert', function() {
test('Saturation from black rgb', function() {
equals(function() {
return new RGBColor(0, 0, 0).saturation == 0;
return new RgbColor(0, 0, 0).saturation == 0;
}, true);
});

View file

@ -41,8 +41,8 @@ test('Path#clone()', function() {
strokeJoin: 'round',
dashOffset: 10,
dashArray: [10, 2, 10],
fillColor: new RGBColor(0, 0, 1),
strokeColor: new RGBColor(0, 0, 1),
fillColor: new RgbColor(0, 0, 1),
strokeColor: new RgbColor(0, 0, 1),
miterLimit: 5
};
path.clockwise = false;
@ -96,8 +96,8 @@ test('Group#clone()', function() {
strokeJoin: 'round',
dashOffset: 10,
dashArray: [10, 2, 10],
fillColor: new RGBColor(0, 0, 1),
strokeColor: new RGBColor(0, 0, 1),
fillColor: new RgbColor(0, 0, 1),
strokeColor: new RgbColor(0, 0, 1),
miterLimit: 5
};
var secondPath = new Path.Circle([175, 175], 85);
@ -133,8 +133,8 @@ test('Symbol#clone()', function() {
strokeJoin: 'round',
dashOffset: 10,
dashArray: [10, 2, 10],
fillColor: new RGBColor(0, 0, 1),
strokeColor: new RGBColor(0, 0, 1),
fillColor: new RgbColor(0, 0, 1),
strokeColor: new RgbColor(0, 0, 1),
miterLimit: 5
};
path.selected = true;
@ -152,8 +152,8 @@ test('Symbol#clone()', function() {
test('Raster#clone()', function() {
var path = new Path.Circle([150, 150], 60);
path.style = {
fillColor: new RGBColor(0, 0, 1),
strokeColor: new RGBColor(0, 0, 1)
fillColor: new RgbColor(0, 0, 1),
strokeColor: new RgbColor(0, 0, 1)
};
var raster = path.rasterize();
raster.opacity = 0.5;

View file

@ -25,12 +25,12 @@ test('style defaults', function() {
test('currentStyle', function() {
paper.project.currentStyle.fillColor = 'black';
var path = new Path();
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
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';
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
compareRgbColors(path.fillColor, 'black', 'path.fillColor');
});
test('setting currentStyle to an object', function() {
@ -39,8 +39,8 @@ test('setting currentStyle to an object', function() {
strokeColor: 'green'
};
var path = new Path();
compareRGBColors(path.fillColor, 'red', 'path.fillColor');
compareRGBColors(path.strokeColor, 'green', 'path.strokeColor');
compareRgbColors(path.fillColor, 'red', 'path.fillColor');
compareRgbColors(path.strokeColor, 'green', 'path.strokeColor');
});
test('setting path styles to an object', function() {
@ -49,8 +49,8 @@ test('setting path styles to an object', function() {
fillColor: 'red',
strokeColor: 'green'
};
compareRGBColors(path.fillColor, 'red', 'path.fillColor');
compareRGBColors(path.strokeColor, 'green', 'path.strokeColor');
compareRgbColors(path.fillColor, 'red', 'path.fillColor');
compareRgbColors(path.strokeColor, 'green', 'path.strokeColor');
});
test('setting group styles to an object', function() {
@ -61,8 +61,8 @@ test('setting group styles to an object', function() {
fillColor: 'red',
strokeColor: 'green'
};
compareRGBColors(path.fillColor, 'red', 'path.fillColor');
compareRGBColors(path.strokeColor, 'green', 'path.strokeColor');
compareRgbColors(path.fillColor, 'red', 'path.fillColor');
compareRgbColors(path.strokeColor, 'green', 'path.strokeColor');
});
test('getting group styles', function() {
@ -71,7 +71,7 @@ test('getting group styles', function() {
path.fillColor = 'red';
group.addChild(path);
compareRGBColors(group.fillColor, 'red', 'group.fillColor');
compareRgbColors(group.fillColor, 'red', 'group.fillColor');
var secondPath = new Path();
secondPath.fillColor = 'black';
@ -85,7 +85,7 @@ test('getting group styles', function() {
//If we remove the first path, it should now return 'black':
group.children[0].remove();
compareRGBColors(group.fillColor, 'black', 'group.fillColor');
compareRgbColors(group.fillColor, 'black', 'group.fillColor');
});
test('setting group styles', function() {
@ -104,11 +104,11 @@ test('setting group styles', function() {
// 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');
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');
compareRgbColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
});
test('setting group styles 2', function() {
@ -117,15 +117,15 @@ test('setting group styles 2', function() {
path.fillColor = 'red';
group.addChild(path);
compareRGBColors(group.fillColor, 'red', 'group.fillColor');
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');
compareRgbColors(secondPath.fillColor, 'blue', 'secondPath.fillColor');
compareRgbColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
// By appending a path with a different fillcolor,
// the group's fillColor should return undefined:
@ -134,16 +134,16 @@ test('setting group styles 2', function() {
}, undefined);
// But, both paths have a red strokeColor, so:
compareRGBColors(group.strokeColor, 'red', 'group.strokeColor');
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');
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');
compareRgbColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
});