Skip to content

Commit 1249ea7

Browse files
committed
Get hue, saturation, brightness funcs now return expect vals; hold for rebase
1 parent 8acc450 commit 1249ea7

File tree

6 files changed

+73
-35
lines changed

6 files changed

+73
-35
lines changed

lib/p5.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.js v0.4.5 May 28, 2015 */
1+
/*! p5.js v0.4.5 May 29, 2015 */
22
(function (root, factory) {
33
if (typeof define === 'function' && define.amd)
44
define('p5', [], function () { return (root.returnExportsGlobal = factory());});
@@ -493,24 +493,25 @@ amdclean['p5Color'] = function (require, core, utilscolor_utils, constants) {
493493
var constants = constants;
494494
p5.Color = function (pInst, vals) {
495495
this.color_array = p5.Color._getFormattedColor.apply(pInst, vals);
496-
this._normalizeColorArray(pInst);
497-
if (pInst._colorMode === constants.HSB) {
496+
this._converted_color = this._normalizeColorArray(pInst);
497+
var isHSB = pInst._colorMode === constants.HSB;
498+
if (isHSB) {
498499
this.hsba = this.color_array;
499-
this.rgba = color_utils.hsbaToRGBA(this.hsba);
500+
this.rgba = color_utils.hsbaToRGBA(this._converted_color);
500501
} else {
501-
this.rgba = this.color_array;
502+
this.rgba = this._converted_color;
502503
this.hsba = color_utils.rgbaToHSBA(this.rgba);
503504
}
504505
return this;
505506
};
506507
p5.Color.prototype._normalizeColorArray = function (pInst) {
507508
var isRGB = pInst._colorMode === constants.RGB;
508509
var maxArr = isRGB ? pInst._maxRGB : pInst._maxHSB;
509-
var arr = this.color_array;
510-
arr[0] *= 255 / maxArr[0];
511-
arr[1] *= 255 / maxArr[1];
512-
arr[2] *= 255 / maxArr[2];
513-
arr[3] *= 255 / maxArr[3];
510+
var arr = [];
511+
arr[0] = this.color_array[0] * 255 / maxArr[0];
512+
arr[1] = this.color_array[1] * 255 / maxArr[1];
513+
arr[2] = this.color_array[2] * 255 / maxArr[2];
514+
arr[3] = this.color_array[3] * 255 / maxArr[3];
514515
return arr;
515516
};
516517
p5.Color.prototype.getHue = function () {

lib/p5.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/color/setting.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ define(function (require) {
3131
* (depending on the current
3232
* color mode), color string,
3333
* p5.Color, or p5.Image
34-
* @param {Number|Array} [v2] green or saturation value
34+
* @param {Number} [v2] green or saturation value
3535
* (depending on the current
3636
* color mode)
37-
* @param {Number|Array} [v3] blue or brightness value
37+
* @param {Number} [v3] blue or brightness value
3838
* (depending on the current
3939
* color mode)
40-
* @param {Number|Array} [a] opacity of the background
40+
* @param {Number} [a] opacity of the background
4141
*
4242
* @example
4343
* <div>
@@ -149,7 +149,9 @@ define(function (require) {
149149
* Changes the way p5.js interprets color data. By default, the parameters
150150
* for fill(), stroke(), background(), and color() are defined by values
151151
* between 0 and 255 using the RGB color model. The colorMode() function is
152-
* used to switch color systems.
152+
* used to switch color systems. Regardless of color system, all value ranges
153+
* are presumed to be 0–255 unless explicitly set otherwise. That is,
154+
* for a standard HSB range, one would pass colorMode(HSB, 360, 100, 100, 1).
153155
*
154156
* @method colorMode
155157
* @param {Number|Constant} mode either RGB or HSB, corresponding to
@@ -226,13 +228,13 @@ define(function (require) {
226228
* (depending on the current color
227229
* mode), or color Array, or CSS
228230
* color string
229-
* @param {Number|Array} [v2] green or saturation value
231+
* @param {Number} [v2] green or saturation value
230232
* (depending on the current
231233
* color mode)
232-
* @param {Number|Array} [v3] blue or brightness value
234+
* @param {Number} [v3] blue or brightness value
233235
* (depending on the current
234236
* color mode)
235-
* @param {Number|Array} [a] opacity of the background
237+
* @param {Number} [a] opacity of the background
236238
*
237239
* @example
238240
* <div>
@@ -377,13 +379,13 @@ define(function (require) {
377379
* (depending on the current color
378380
* mode), or color Array, or CSS
379381
* color string
380-
* @param {Number|Array} [v2] green or saturation value
382+
* @param {Number} [v2] green or saturation value
381383
* (depending on the current
382384
* color mode)
383-
* @param {Number|Array} [v3] blue or brightness value
385+
* @param {Number} [v3] blue or brightness value
384386
* (depending on the current
385387
* color mode)
386-
* @param {Number|Array} [a] opacity of the background
388+
* @param {Number} [a] opacity of the background
387389
*
388390
* @example
389391
* <div>

src/objects/p5.Color.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ define(function(require) {
1616
*/
1717
p5.Color = function (pInst, vals) {
1818
this.color_array = p5.Color._getFormattedColor.apply(pInst, vals);
19-
this._normalizeColorArray(pInst);
19+
this._converted_color = this._normalizeColorArray(pInst);
20+
21+
var isHSB = pInst._colorMode === constants.HSB;
2022

21-
if (pInst._colorMode === constants.HSB) {
23+
if (isHSB) {
2224
this.hsba = this.color_array;
23-
this.rgba = color_utils.hsbaToRGBA(this.hsba);
25+
this.rgba = color_utils.hsbaToRGBA(this._converted_color);
2426
} else {
25-
this.rgba = this.color_array;
27+
this.rgba = this._converted_color;
2628
this.hsba = color_utils.rgbaToHSBA(this.rgba);
2729
}
2830

@@ -32,11 +34,13 @@ define(function(require) {
3234
p5.Color.prototype._normalizeColorArray = function (pInst) {
3335
var isRGB = pInst._colorMode === constants.RGB;
3436
var maxArr = isRGB ? pInst._maxRGB : pInst._maxHSB;
35-
var arr = this.color_array;
36-
arr[0] *= 255 / maxArr[0];
37-
arr[1] *= 255 / maxArr[1];
38-
arr[2] *= 255 / maxArr[2];
39-
arr[3] *= 255 / maxArr[3];
37+
// var arr = this.color_array;
38+
var arr = [];
39+
arr[0] = this.color_array[0] * 255 / maxArr[0];
40+
arr[1] = this.color_array[1] * 255 / maxArr[1];
41+
arr[2] = this.color_array[2] * 255 / maxArr[2];
42+
arr[3] = this.color_array[3] * 255 / maxArr[3];
43+
// why does this return the arr when it is actually mutating the reference?
4044
return arr;
4145
};
4246

src/objects/p5.Table.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ define(function (require) {
2323
* <p>A rough "spec" for CSV can be found
2424
* <a href="http://tools.ietf.org/html/rfc4180">here</a>.</p>
2525
* <p>To load files, use the loadTable method.</p>
26-
* <p>To save tables to your computer, use the save method or the saveTable method.</p>
26+
* <p>To save tables to your computer, use the save method
27+
* or the saveTable method.</p>
2728
*
2829
* Possible options include:
2930
* <ul>

test/unit/objects/p5.Color.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,15 @@ suite('p5.Color', function() {
534534
});
535535
});
536536

537-
suite('new p5.Color in HSB mode', function() {
537+
suite('new p5.Color in HSB-255 mode', function() {
538538
setup(function() {
539539
myp5.colorMode(myp5.HSB);
540540
c = myp5.color(149, 170, 30, 255);
541541
});
542542

543543
test('should correctly set HSBA property', function() {
544+
assert.equal(c.hsba.length, 4);
545+
assert.equal(Math.round(c.getHue()), 149);
544546
assert.deepEqual(c.hsba, [149, 170, 30, 255]);
545547
});
546548

@@ -553,6 +555,34 @@ suite('p5.Color', function() {
553555
});
554556
});
555557

558+
suite('new p5.Color in HSB-360 mode', function() {
559+
setup(function() {
560+
myp5.colorMode(myp5.HSB, 360, 100, 100, 1);
561+
c = myp5.color(48, 100, 100, 1);
562+
});
563+
564+
test('should correctly set HSBA value', function(){
565+
assert.deepEqual(c.hsba, [48, 100, 100, 1]);
566+
});
567+
568+
test('should correctly set converted value', function(){
569+
assert.deepEqual(c._converted_color, [34, 255, 255, 255]);
570+
});
571+
572+
test('should return passed, unconverted, hue value', function(){
573+
assert.equal(c.getHue(), 48);
574+
});
575+
576+
test('should return passed, unconverted, saturation value', function(){
577+
assert.equal(c.getSaturation(), 100);
578+
});
579+
580+
test('should return passed, unconverted, brightness value', function(){
581+
assert.equal(c.getBrightness(), 100);
582+
});
583+
584+
});
585+
556586
suite('new p5.Color with Base 1 colors', function() {
557587
var base_1_rgba = [0.2, 0.4, 0.6, 0.5];
558588
var base_255_rgba = [51, 102, 153, 127.5];

0 commit comments

Comments
 (0)