Skip to content

Commit 9750cb7

Browse files
author
Saksham Saxena
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents 61f9ce4 + 5d72b2d commit 9750cb7

31 files changed

+1039
-186
lines changed

Gruntfile.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
* served from the /reference/ folder of the p5js
1414
* website (https://github.com/processing/p5.js-website).
1515
*
16-
* grunt yui:dev - This will build the inline documentation but linking to
17-
* remote JS/CSS and assets so pages look correct in local
18-
* testing. The generated documentation is assumed
19-
* to be served from a development web server running
20-
* at the root of the repository. "grunt yui" should
21-
* be run to build docs ready for production.
22-
*
2316
* grunt test - This rebuilds the source and runs the automated tests on
2417
* both the minified and unminified code. If you need to debug
2518
* a test suite in a browser, `grunt test --keepalive` will
@@ -64,6 +57,8 @@ function getYuidocOptions() {
6457
}
6558
};
6659

60+
// note dev is no longer used, prod is used to build both testing and production ready docs
61+
6762
var o = {
6863
prod: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS)),
6964
dev: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS))
@@ -212,7 +207,7 @@ module.exports = function(grunt) {
212207
run: true,
213208
log: true,
214209
logErrors: true,
215-
timeout: 5000
210+
timeout: 100000
216211
}
217212
}
218213
},
@@ -370,11 +365,10 @@ module.exports = function(grunt) {
370365

371366
// Create the multitasks.
372367
grunt.registerTask('build', ['browserify', 'uglify', 'requirejs']);
373-
grunt.registerTask('test', ['jshint', 'jscs', 'build', 'yuidoc:dev', 'connect', 'mocha', 'mochaTest']);
368+
grunt.registerTask('test', ['jshint', 'jscs', 'yuidoc:prod', 'build', 'connect', 'mocha', 'mochaTest']);
374369
grunt.registerTask('test:nobuild', ['jshint:test', 'jscs:test', 'connect', 'mocha']);
375370
grunt.registerTask('yui', ['yuidoc:prod', 'minjson']);
376-
grunt.registerTask('yui:dev', ['yuidoc:dev', 'minjson']);
377-
grunt.registerTask('yui:test', ['yuidoc:dev', 'connect', 'mocha:yui']);
371+
grunt.registerTask('yui:test', ['yuidoc:prod', 'connect', 'mocha:yui']);
378372
grunt.registerTask('default', ['test']);
379373
grunt.registerTask('saucetest', ['connect', 'saucelabs-mocha']);
380374
};

docs/preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module.exports.register = function(Handlebars, options) {
143143
// } else {
144144
// return '/'+this.language;
145145
// }
146-
return window.location.pathname+' hi'
146+
return window.location.pathname
147147
});
148148
};
149149

docs/yuidoc-p5-theme/layouts/main.handlebars

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
<meta name="viewport" content="width=device-width">
77
<meta name="description" content="p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.">
88
<title tabindex="1">p5.js | reference</title>
9-
<link rel="stylesheet" href="/assets/css/all.css">
9+
<link rel="stylesheet" href="https://p5js.org/assets/css/all.css">
1010
<link rel="stylesheet" href="{{projectAssets}}/reference.css">
1111
<script type="text/javascript" src="//fast.fonts.net/jsapi/5ace315e-3b19-4568-9e85-5bfcb29004c0.js"></script>
1212

1313
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
14-
<script>window.jQuery || document.write('<script src="{{p5SiteRoot}}/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
15-
<script src='/assets/js/p5.min.js'></script>
16-
<script src='/assets/js/p5.dom.min.js'></script>
17-
<script src='/assets/js/p5.sound.min.js'></script>
14+
<script>window.jQuery || document.write('<script src="https://p5js.org/assets/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
15+
<script src='https://p5js.org/assets/js/p5.min.js'></script>
16+
<script src='https://p5js.org/assets/js/p5.dom.min.js'></script>
17+
<script src='https://p5js.org/assets/js/p5.sound.min.js'></script>
1818
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
1919
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min.js"></script>
2020

21-
<script type="text/javascript" src="/assets/js/vendor/ace-nc/ace.js"></script>
22-
<script type="text/javascript" src="/assets/js/vendor/ace-nc/mode-javascript.js"></script>
23-
<script type="text/javascript" src="/assets/js/vendor/prism.js"></script>
24-
<script type="text/javascript" src="/assets/js/scroll.js"></script>
25-
<script type="text/javascript" src="/assets/js/init.js"></script>
21+
<script type="text/javascript" src="https://p5js.org/assets/js/vendor/ace-nc/ace.js"></script>
22+
<script type="text/javascript" src="https://p5js.org/assets/js/vendor/ace-nc/mode-javascript.js"></script>
23+
<script type="text/javascript" src="https://p5js.org/assets/js/vendor/prism.js"></script>
24+
<script type="text/javascript" src="https://p5js.org/assets/js/scroll.js"></script>
25+
<script type="text/javascript" src="https://p5js.org/assets/js/init.js"></script>
2626

2727
</head>
2828

@@ -42,7 +42,7 @@
4242
<!-- logo -->
4343
<header id="lockup">
4444
<a href="{{p5SiteRoot}}/">
45-
<img src="/assets/img/p5js.svg" alt="link to p5 home page" id="logo_image" class="logo" />
45+
<img src="https://p5js.org/assets/img/p5js.svg" alt="link to p5 home page" id="logo_image" class="logo" />
4646
<div id="p5_logo"></div>
4747
</a>
4848
<p class='tagline' style='display:block !important'>Processing Intuition times JavaScript power</p>
@@ -57,7 +57,7 @@
5757
<li><a href="{{p5SiteRoot}}/get-started/">Start</a></li>
5858
<li><a href="{{p5SiteRoot}}/reference/">Reference</a></li>
5959
<li><a href="{{p5SiteRoot}}/libraries/">Libraries</a></li>
60-
<li><a href="{{p5SiteRoot}}/tutorials/">Tutorials</a></li>
60+
<li><a href="{{p5SiteRoot}}/learn/">Learn</a></li>
6161
<li><a href="{{p5SiteRoot}}/examples/">Examples</a></li>
6262
<li><a href="{{p5SiteRoot}}/books/">Books</a></li>
6363
<li><a href="{{p5SiteRoot}}/community/">Community</a></li>
@@ -96,7 +96,7 @@
9696
<!-- outside of column for footer to go across both -->
9797
<p class="clearfix"> &nbsp; </p>
9898

99-
<object type="image/svg+xml" data="/assets/img/thick-asterisk-alone.svg" id="asterisk-design-element">
99+
<object type="image/svg+xml" data="https://p5js.org/assets/img/thick-asterisk-alone.svg" id="asterisk-design-element">
100100
*<!-- to do: add fallback image in CSS -->
101101
</object>
102102
</div>
@@ -120,8 +120,8 @@
120120
</div>
121121

122122
<script src="{{projectAssets}}/js/require.min.js"></script>
123-
<script src="/assets/js/vendor/prism.js"></script>
124-
<script src="/assets/js/render.js"></script>
123+
<script src="https://p5js.org/assets/js/vendor/prism.js"></script>
124+
<script src="https://p5js.org/assets/js/render.js"></script>
125125
<script src="{{projectAssets}}/js/reference.js"></script>
126126
<script type='text/javascript'>
127127

src/color/creating_reading.js

Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
var p5 = require('../core/core');
1212
var constants = require('../core/constants');
1313
require('./p5.Color');
14+
require('../core/error_helpers');
1415

1516
/**
1617
* Extracts the alpha value from a color or pixel array.
1718
*
1819
* @method alpha
19-
* @param {p5.Color|Number[]} obj p5.Color object or pixel array
20+
* @param {p5.Color|Array} color p5.Color object or pixel array
2021
* @return {Number} the alpha value
2122
* @example
2223
* <div>
@@ -52,18 +53,15 @@ require('./p5.Color');
5253
* deep pink rect on left and grey rect on right, both 35x60.
5354
*/
5455
p5.prototype.alpha = function(c) {
55-
if (c instanceof p5.Color || c instanceof Array) {
56-
return this.color(c)._getAlpha();
57-
} else {
58-
throw new Error('Needs p5.Color or pixel array as argument.');
59-
}
56+
p5._validateParameters('alpha', arguments);
57+
return this.color(c)._getAlpha();
6058
};
6159

6260
/**
6361
* Extracts the blue value from a color or pixel array.
6462
*
6563
* @method blue
66-
* @param {p5.Color|Number[]} obj p5.Color object or pixel array
64+
* @param {p5.Color|Array} color p5.Color object or pixel array
6765
* @return {Number} the blue value
6866
* @example
6967
* <div>
@@ -84,18 +82,15 @@ p5.prototype.alpha = function(c) {
8482
*
8583
*/
8684
p5.prototype.blue = function(c) {
87-
if (c instanceof p5.Color || c instanceof Array) {
88-
return this.color(c)._getBlue();
89-
} else {
90-
throw new Error('Needs p5.Color or pixel array as argument.');
91-
}
85+
p5._validateParameters('blue', arguments);
86+
return this.color(c)._getBlue();
9287
};
9388

9489
/**
9590
* Extracts the HSB brightness value from a color or pixel array.
9691
*
9792
* @method brightness
98-
* @param {p5.Color|Number[]} color p5.Color object or pixel array
93+
* @param {p5.Color|Array} color p5.Color object or pixel array
9994
* @return {Number} the brightness value
10095
* @example
10196
* <div>
@@ -116,11 +111,8 @@ p5.prototype.blue = function(c) {
116111
*
117112
*/
118113
p5.prototype.brightness = function(c) {
119-
if (c instanceof p5.Color || c instanceof Array) {
120-
return this.color(c)._getBrightness();
121-
} else {
122-
throw new Error('Needs p5.Color or pixel array as argument.');
123-
}
114+
p5._validateParameters('brightness', arguments);
115+
return this.color(c)._getBrightness();
124116
};
125117

126118
/**
@@ -282,7 +274,6 @@ p5.prototype.brightness = function(c) {
282274
* Dark blue rect on left and light teal rect on right of canvas, both 45x80.
283275
*
284276
*/
285-
286277
/**
287278
* @method color
288279
* @param {Number} v1 red or hue value relative to
@@ -301,13 +292,17 @@ p5.prototype.brightness = function(c) {
301292
* @param {Number} [alpha]
302293
* @return {p5.Color}
303294
*/
304-
305295
/**
306296
* @method color
307-
* @param {Number[]} values an array containing the red,green,blue &
297+
* @param {Array} values an array containing the red,green,blue &
308298
* and alpha components of the color
309299
* @return {p5.Color}
310300
*/
301+
/**
302+
* @method color
303+
* @param {p5.Color} color
304+
* @return {p5.Color}
305+
*/
311306

312307
p5.prototype.color = function() {
313308
if (arguments[0] instanceof p5.Color) {
@@ -319,6 +314,7 @@ p5.prototype.color = function() {
319314
return new p5.Color(this._renderer, arguments[0]);
320315
}
321316
} else {
317+
p5._validateParameters('color', arguments);
322318
if (this instanceof p5.Renderer) {
323319
return new p5.Color(this, arguments);
324320
} else {
@@ -331,7 +327,7 @@ p5.prototype.color = function() {
331327
* Extracts the green value from a color or pixel array.
332328
*
333329
* @method green
334-
* @param {p5.Color|Number[]} color p5.Color object or pixel array
330+
* @param {p5.Color|Array} color p5.Color object or pixel array
335331
* @return {Number} the green value
336332
* @example
337333
* <div>
@@ -353,11 +349,8 @@ p5.prototype.color = function() {
353349
*/
354350

355351
p5.prototype.green = function(c) {
356-
if (c instanceof p5.Color || c instanceof Array) {
357-
return this.color(c)._getGreen();
358-
} else {
359-
throw new Error('Needs p5.Color or pixel array as argument.');
360-
}
352+
p5._validateParameters('green', arguments);
353+
return this.color(c)._getGreen();
361354
};
362355

363356
/**
@@ -370,7 +363,7 @@ p5.prototype.green = function(c) {
370363
* maximum hue setting for each system is different.)
371364
*
372365
* @method hue
373-
* @param {p5.Color|Number[]} color p5.Color object or pixel array
366+
* @param {p5.Color|Array} color p5.Color object or pixel array
374367
* @return {Number} the hue
375368
* @example
376369
* <div>
@@ -392,11 +385,8 @@ p5.prototype.green = function(c) {
392385
*/
393386

394387
p5.prototype.hue = function(c) {
395-
if (c instanceof p5.Color || c instanceof Array) {
396-
return this.color(c)._getHue();
397-
} else {
398-
throw new Error('Needs p5.Color or pixel array as argument.');
399-
}
388+
p5._validateParameters('hue', arguments);
389+
return this.color(c)._getHue();
400390
};
401391

402392
/**
@@ -443,34 +433,35 @@ p5.prototype.hue = function(c) {
443433
*/
444434

445435
p5.prototype.lerpColor = function(c1, c2, amt) {
436+
p5._validateParameters('lerpColor', arguments);
446437
var mode = this._renderer._colorMode;
447438
var maxes = this._renderer._colorMaxes;
448439
var l0, l1, l2, l3;
449440
var fromArray, toArray;
450441

451442
if (mode === constants.RGB) {
452-
fromArray = c1.levels.map(function(level) {
443+
fromArray = arguments[0].levels.map(function(level) {
453444
return level / 255;
454445
});
455-
toArray = c2.levels.map(function(level) {
446+
toArray = arguments[1].levels.map(function(level) {
456447
return level / 255;
457448
});
458449
} else if (mode === constants.HSB) {
459-
c1._getBrightness(); // Cache hsba so it definitely exists.
460-
c2._getBrightness();
461-
fromArray = c1.hsba;
462-
toArray = c2.hsba;
450+
arguments[0]._getBrightness(); // Cache hsba so it definitely exists.
451+
arguments[1]._getBrightness();
452+
fromArray = arguments[0].hsba;
453+
toArray = arguments[1].hsba;
463454
} else if (mode === constants.HSL) {
464-
c1._getLightness(); // Cache hsla so it definitely exists.
465-
c2._getLightness();
466-
fromArray = c1.hsla;
467-
toArray = c2.hsla;
455+
arguments[0]._getLightness(); // Cache hsla so it definitely exists.
456+
arguments[1]._getLightness();
457+
fromArray = arguments[0].hsla;
458+
toArray = arguments[1].hsla;
468459
} else {
469460
throw new Error (mode + 'cannot be used for interpolation.');
470461
}
471462

472463
// Prevent extrapolation.
473-
amt = Math.max(Math.min(amt, 1), 0);
464+
amt = Math.max(Math.min(arguments[2], 1), 0);
474465

475466
// Define lerp here itself if user isn't using math module.
476467
// Maintains the definition as found in math/calculation.js
@@ -499,7 +490,7 @@ p5.prototype.lerpColor = function(c1, c2, amt) {
499490
* Extracts the HSL lightness value from a color or pixel array.
500491
*
501492
* @method lightness
502-
* @param {p5.Color|Number[]} color p5.Color object or pixel array
493+
* @param {p5.Color|Array} color p5.Color object or pixel array
503494
* @return {Number} the lightness
504495
* @example
505496
* <div>
@@ -520,18 +511,15 @@ p5.prototype.lerpColor = function(c1, c2, amt) {
520511
*
521512
*/
522513
p5.prototype.lightness = function(c) {
523-
if (c instanceof p5.Color || c instanceof Array) {
524-
return this.color(c)._getLightness();
525-
} else {
526-
throw new Error('Needs p5.Color or pixel array as argument.');
527-
}
514+
p5._validateParameters('lightness', arguments);
515+
return this.color(c)._getLightness();
528516
};
529517

530518
/**
531519
* Extracts the red value from a color or pixel array.
532520
*
533521
* @method red
534-
* @param {p5.Color|Number[]} obj p5.Color object or pixel array
522+
* @param {p5.Color|Array} color p5.Color object or pixel array
535523
* @return {Number} the red value
536524
* @example
537525
* <div>
@@ -562,11 +550,8 @@ p5.prototype.lightness = function(c) {
562550
* grey canvas
563551
*/
564552
p5.prototype.red = function(c) {
565-
if (c instanceof p5.Color || c instanceof Array) {
566-
return this.color(c)._getRed();
567-
} else {
568-
throw new Error('Needs p5.Color or pixel array as argument.');
569-
}
553+
p5._validateParameters('red', arguments);
554+
return this.color(c)._getRed();
570555
};
571556

572557
/**
@@ -578,8 +563,8 @@ p5.prototype.red = function(c) {
578563
* HSL saturation otherwise.
579564
*
580565
* @method saturation
581-
* @param {p5.Color|Number[]} color p5.Color object or pixel array
582-
* @return {Number} the saturation
566+
* @param {p5.Color|Array} color p5.Color object or pixel array
567+
* @return {Number} the saturation value
583568
* @example
584569
* <div>
585570
* <code>
@@ -600,11 +585,8 @@ p5.prototype.red = function(c) {
600585
*/
601586

602587
p5.prototype.saturation = function(c) {
603-
if (c instanceof p5.Color || c instanceof Array) {
604-
return this.color(c)._getSaturation();
605-
} else {
606-
throw new Error('Needs p5.Color or pixel array as argument.');
607-
}
588+
p5._validateParameters('saturation', arguments);
589+
return this.color(c)._getSaturation();
608590
};
609591

610592
module.exports = p5;

0 commit comments

Comments
 (0)