paper.js/test/tests/Color.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2011-02-19 10:48:59 -05:00
module('RGB Color');
test('Set named color', function() {
var doc = new Document();
2011-02-19 10:48:59 -05:00
var path = new Path();
path.fillColor = 'red';
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
2011-02-19 10:48:59 -05:00
});
test('Set color to hex', function() {
var doc = new Document();
2011-02-19 10:48:59 -05:00
var path = new Path();
path.fillColor = '#ff0000';
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
2011-02-19 10:48:59 -05:00
var path = new Path();
path.fillColor = '#f00';
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
2011-02-19 10:48:59 -05:00
});
test('Set color to object', function() {
var doc = new Document();
2011-02-19 10:48:59 -05:00
var path = new Path();
path.fillColor = { red: 1, green: 0, blue: 1};
compareRGBColors(path.fillColor, new RGBColor(1, 0, 1));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 255, 1)');
2011-02-19 10:48:59 -05:00
var path = new Path();
path.fillColor = { gray: 0.2 };
compareRGBColors(path.fillColor, new RGBColor(0.8, 0.8, 0.8));
equals(path.fillColor.toCssString(), 'rgba(204, 204, 204, 1)');
2011-02-19 10:48:59 -05:00
});
test('Set color to array', function() {
var doc = new Document();
2011-02-19 10:48:59 -05:00
var path = new Path();
path.fillColor = [1, 0, 0];
compareRGBColors(path.fillColor, new RGBColor(1, 0, 0));
equals(path.fillColor.toCssString(), 'rgba(255, 0, 0, 1)');
2011-02-19 10:48:59 -05:00
});
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);
compareNumbers(color.gray, 0.72137451171875);
});
test('Gray Color', function() {
var color = new GrayColor(1);
compareNumbers(color.gray, 1);
2011-02-19 11:11:17 -05:00
compareNumbers(color.red, 0);
2011-02-19 10:48:59 -05:00
color.red = 0.5;
compareNumbers(color.gray, '0.84999');
color.green = 0.2;
compareNumbers(color.gray, '0.82051');
});
test('Converting Colors', function() {
var color = new RGBColor(1, 0.5, 0.2);
compareNumbers(new GrayColor(color).gray, 0.38299560546875);
var color = new GrayColor(0.2);
var rgbColor = new RGBColor(color);
2011-02-24 07:00:46 -05:00
compareRGBColors(rgbColor, [ 0.8, 0.8, 0.8, 1]);
});
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]);
2011-02-19 10:48:59 -05:00
});