Skip to content

Commit

Permalink
Merge branch 'master' of github.com:processing/p5.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Saksham Saxena committed Aug 25, 2017
2 parents 61f9ce4 + 5d72b2d commit 9750cb7
Show file tree
Hide file tree
Showing 31 changed files with 1,039 additions and 186 deletions.
16 changes: 5 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
* served from the /reference/ folder of the p5js
* website (https://github.com/processing/p5.js-website).
*
* grunt yui:dev - This will build the inline documentation but linking to
* remote JS/CSS and assets so pages look correct in local
* testing. The generated documentation is assumed
* to be served from a development web server running
* at the root of the repository. "grunt yui" should
* be run to build docs ready for production.
*
* grunt test - This rebuilds the source and runs the automated tests on
* both the minified and unminified code. If you need to debug
* a test suite in a browser, `grunt test --keepalive` will
Expand Down Expand Up @@ -64,6 +57,8 @@ function getYuidocOptions() {
}
};

// note dev is no longer used, prod is used to build both testing and production ready docs

var o = {
prod: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS)),
dev: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS))
Expand Down Expand Up @@ -212,7 +207,7 @@ module.exports = function(grunt) {
run: true,
log: true,
logErrors: true,
timeout: 5000
timeout: 100000
}
}
},
Expand Down Expand Up @@ -370,11 +365,10 @@ module.exports = function(grunt) {

// Create the multitasks.
grunt.registerTask('build', ['browserify', 'uglify', 'requirejs']);
grunt.registerTask('test', ['jshint', 'jscs', 'build', 'yuidoc:dev', 'connect', 'mocha', 'mochaTest']);
grunt.registerTask('test', ['jshint', 'jscs', 'yuidoc:prod', 'build', 'connect', 'mocha', 'mochaTest']);
grunt.registerTask('test:nobuild', ['jshint:test', 'jscs:test', 'connect', 'mocha']);
grunt.registerTask('yui', ['yuidoc:prod', 'minjson']);
grunt.registerTask('yui:dev', ['yuidoc:dev', 'minjson']);
grunt.registerTask('yui:test', ['yuidoc:dev', 'connect', 'mocha:yui']);
grunt.registerTask('yui:test', ['yuidoc:prod', 'connect', 'mocha:yui']);
grunt.registerTask('default', ['test']);
grunt.registerTask('saucetest', ['connect', 'saucelabs-mocha']);
};
2 changes: 1 addition & 1 deletion docs/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module.exports.register = function(Handlebars, options) {
// } else {
// return '/'+this.language;
// }
return window.location.pathname+' hi'
return window.location.pathname
});
};

30 changes: 15 additions & 15 deletions docs/yuidoc-p5-theme/layouts/main.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
<meta name="viewport" content="width=device-width">
<meta name="description" content="p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.">
<title tabindex="1">p5.js | reference</title>
<link rel="stylesheet" href="/assets/css/all.css">
<link rel="stylesheet" href="https://p5js.org/assets/css/all.css">
<link rel="stylesheet" href="{{projectAssets}}/reference.css">
<script type="text/javascript" src="//fast.fonts.net/jsapi/5ace315e-3b19-4568-9e85-5bfcb29004c0.js"></script>

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

<script type="text/javascript" src="/assets/js/vendor/ace-nc/ace.js"></script>
<script type="text/javascript" src="/assets/js/vendor/ace-nc/mode-javascript.js"></script>
<script type="text/javascript" src="/assets/js/vendor/prism.js"></script>
<script type="text/javascript" src="/assets/js/scroll.js"></script>
<script type="text/javascript" src="/assets/js/init.js"></script>
<script type="text/javascript" src="https://p5js.org/assets/js/vendor/ace-nc/ace.js"></script>
<script type="text/javascript" src="https://p5js.org/assets/js/vendor/ace-nc/mode-javascript.js"></script>
<script type="text/javascript" src="https://p5js.org/assets/js/vendor/prism.js"></script>
<script type="text/javascript" src="https://p5js.org/assets/js/scroll.js"></script>
<script type="text/javascript" src="https://p5js.org/assets/js/init.js"></script>

</head>

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

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

<script src="{{projectAssets}}/js/require.min.js"></script>
<script src="/assets/js/vendor/prism.js"></script>
<script src="/assets/js/render.js"></script>
<script src="https://p5js.org/assets/js/vendor/prism.js"></script>
<script src="https://p5js.org/assets/js/render.js"></script>
<script src="{{projectAssets}}/js/reference.js"></script>
<script type='text/javascript'>
Expand Down
108 changes: 45 additions & 63 deletions src/color/creating_reading.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
var p5 = require('../core/core');
var constants = require('../core/constants');
require('./p5.Color');
require('../core/error_helpers');

/**
* Extracts the alpha value from a color or pixel array.
*
* @method alpha
* @param {p5.Color|Number[]} obj p5.Color object or pixel array
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the alpha value
* @example
* <div>
Expand Down Expand Up @@ -52,18 +53,15 @@ require('./p5.Color');
* deep pink rect on left and grey rect on right, both 35x60.
*/
p5.prototype.alpha = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getAlpha();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('alpha', arguments);
return this.color(c)._getAlpha();
};

/**
* Extracts the blue value from a color or pixel array.
*
* @method blue
* @param {p5.Color|Number[]} obj p5.Color object or pixel array
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the blue value
* @example
* <div>
Expand All @@ -84,18 +82,15 @@ p5.prototype.alpha = function(c) {
*
*/
p5.prototype.blue = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getBlue();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('blue', arguments);
return this.color(c)._getBlue();
};

/**
* Extracts the HSB brightness value from a color or pixel array.
*
* @method brightness
* @param {p5.Color|Number[]} color p5.Color object or pixel array
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the brightness value
* @example
* <div>
Expand All @@ -116,11 +111,8 @@ p5.prototype.blue = function(c) {
*
*/
p5.prototype.brightness = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getBrightness();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('brightness', arguments);
return this.color(c)._getBrightness();
};

/**
Expand Down Expand Up @@ -282,7 +274,6 @@ p5.prototype.brightness = function(c) {
* Dark blue rect on left and light teal rect on right of canvas, both 45x80.
*
*/

/**
* @method color
* @param {Number} v1 red or hue value relative to
Expand All @@ -301,13 +292,17 @@ p5.prototype.brightness = function(c) {
* @param {Number} [alpha]
* @return {p5.Color}
*/

/**
* @method color
* @param {Number[]} values an array containing the red,green,blue &
* @param {Array} values an array containing the red,green,blue &
* and alpha components of the color
* @return {p5.Color}
*/
/**
* @method color
* @param {p5.Color} color
* @return {p5.Color}
*/

p5.prototype.color = function() {
if (arguments[0] instanceof p5.Color) {
Expand All @@ -319,6 +314,7 @@ p5.prototype.color = function() {
return new p5.Color(this._renderer, arguments[0]);
}
} else {
p5._validateParameters('color', arguments);
if (this instanceof p5.Renderer) {
return new p5.Color(this, arguments);
} else {
Expand All @@ -331,7 +327,7 @@ p5.prototype.color = function() {
* Extracts the green value from a color or pixel array.
*
* @method green
* @param {p5.Color|Number[]} color p5.Color object or pixel array
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the green value
* @example
* <div>
Expand All @@ -353,11 +349,8 @@ p5.prototype.color = function() {
*/

p5.prototype.green = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getGreen();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('green', arguments);
return this.color(c)._getGreen();
};

/**
Expand All @@ -370,7 +363,7 @@ p5.prototype.green = function(c) {
* maximum hue setting for each system is different.)
*
* @method hue
* @param {p5.Color|Number[]} color p5.Color object or pixel array
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the hue
* @example
* <div>
Expand All @@ -392,11 +385,8 @@ p5.prototype.green = function(c) {
*/

p5.prototype.hue = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getHue();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('hue', arguments);
return this.color(c)._getHue();
};

/**
Expand Down Expand Up @@ -443,34 +433,35 @@ p5.prototype.hue = function(c) {
*/

p5.prototype.lerpColor = function(c1, c2, amt) {
p5._validateParameters('lerpColor', arguments);
var mode = this._renderer._colorMode;
var maxes = this._renderer._colorMaxes;
var l0, l1, l2, l3;
var fromArray, toArray;

if (mode === constants.RGB) {
fromArray = c1.levels.map(function(level) {
fromArray = arguments[0].levels.map(function(level) {
return level / 255;
});
toArray = c2.levels.map(function(level) {
toArray = arguments[1].levels.map(function(level) {
return level / 255;
});
} else if (mode === constants.HSB) {
c1._getBrightness(); // Cache hsba so it definitely exists.
c2._getBrightness();
fromArray = c1.hsba;
toArray = c2.hsba;
arguments[0]._getBrightness(); // Cache hsba so it definitely exists.
arguments[1]._getBrightness();
fromArray = arguments[0].hsba;
toArray = arguments[1].hsba;
} else if (mode === constants.HSL) {
c1._getLightness(); // Cache hsla so it definitely exists.
c2._getLightness();
fromArray = c1.hsla;
toArray = c2.hsla;
arguments[0]._getLightness(); // Cache hsla so it definitely exists.
arguments[1]._getLightness();
fromArray = arguments[0].hsla;
toArray = arguments[1].hsla;
} else {
throw new Error (mode + 'cannot be used for interpolation.');
}

// Prevent extrapolation.
amt = Math.max(Math.min(amt, 1), 0);
amt = Math.max(Math.min(arguments[2], 1), 0);

// Define lerp here itself if user isn't using math module.
// Maintains the definition as found in math/calculation.js
Expand Down Expand Up @@ -499,7 +490,7 @@ p5.prototype.lerpColor = function(c1, c2, amt) {
* Extracts the HSL lightness value from a color or pixel array.
*
* @method lightness
* @param {p5.Color|Number[]} color p5.Color object or pixel array
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the lightness
* @example
* <div>
Expand All @@ -520,18 +511,15 @@ p5.prototype.lerpColor = function(c1, c2, amt) {
*
*/
p5.prototype.lightness = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getLightness();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('lightness', arguments);
return this.color(c)._getLightness();
};

/**
* Extracts the red value from a color or pixel array.
*
* @method red
* @param {p5.Color|Number[]} obj p5.Color object or pixel array
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the red value
* @example
* <div>
Expand Down Expand Up @@ -562,11 +550,8 @@ p5.prototype.lightness = function(c) {
* grey canvas
*/
p5.prototype.red = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getRed();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('red', arguments);
return this.color(c)._getRed();
};

/**
Expand All @@ -578,8 +563,8 @@ p5.prototype.red = function(c) {
* HSL saturation otherwise.
*
* @method saturation
* @param {p5.Color|Number[]} color p5.Color object or pixel array
* @return {Number} the saturation
* @param {p5.Color|Array} color p5.Color object or pixel array
* @return {Number} the saturation value
* @example
* <div>
* <code>
Expand All @@ -600,11 +585,8 @@ p5.prototype.red = function(c) {
*/

p5.prototype.saturation = function(c) {
if (c instanceof p5.Color || c instanceof Array) {
return this.color(c)._getSaturation();
} else {
throw new Error('Needs p5.Color or pixel array as argument.');
}
p5._validateParameters('saturation', arguments);
return this.color(c)._getSaturation();
};

module.exports = p5;
Loading

0 comments on commit 9750cb7

Please sign in to comment.