Skip to content

Commit c642613

Browse files
authored
Merge pull request #2 from processing/master
update
2 parents 313bf91 + e385aea commit c642613

File tree

18 files changed

+327
-189
lines changed

18 files changed

+327
-189
lines changed

Gruntfile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ module.exports = function(grunt) {
187187
// Watch the codebase for doc updates
188188
// launch with 'grunt requirejs connect watch:yui'
189189
yui: {
190-
files: ['src/**/*.js', 'lib/addons/*.js'],
190+
files: [
191+
'src/**/*.js',
192+
'lib/addons/*.js',
193+
'src/**/*.frag',
194+
'src/**/*.vert'
195+
],
191196
tasks: ['browserify', 'yuidoc:prod', 'minjson', 'uglify'],
192197
options: {
193198
livereload: true

docs/preprocessor.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ function mergeOverloadedMethods(data) {
4141
return false;
4242
}
4343

44+
var itemClass = data.classes[classitem.class];
45+
if (!itemClass || itemClass.private) {
46+
return false;
47+
}
48+
4449
var methodConsts = {};
4550

4651
var fullName, method;

docs/yuidoc-p5-theme-src/scripts/views/listView.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ define([
3131
// module === group
3232
this.groups = {};
3333
_.each(items, function (item, i) {
34-
if (item.file.indexOf('addons') === -1) { //addons don't get displayed on main page
34+
35+
if (!item.private && item.file.indexOf('addons') === -1) { //addons don't get displayed on main page
3536

3637
var group = item.module || '_';
3738
var subgroup = item.submodule || '_';
@@ -54,13 +55,13 @@ define([
5455
name: subgroup.replace('_', ' '),
5556
items: []
5657
};
57-
}
58-
59-
// hide the un-interesting constants
60-
if (group === 'Constants' && !item.example)
61-
return;
58+
}
59+
60+
// hide the un-interesting constants
61+
if (group === 'Constants' && !item.example)
62+
return;
6263

63-
if (item.file.indexOf('p5.') === -1) {
64+
if (item.class === 'p5') {
6465

6566
self.groups[group].subgroups[subgroup].items.push(item);
6667

lib/addons/p5.dom.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,45 @@
22562256
* @param {Number} [time] time to jump to (in seconds)
22572257
* @return {Number|Object|p5.MediaElement} current time (in seconds)
22582258
* or p5.MediaElement
2259+
* @example
2260+
* <div><code>
2261+
* var ele;
2262+
* var beginning = true;
2263+
* function setup() {
2264+
* //p5.MediaElement objects are usually created
2265+
* //by calling the createAudio(), createVideo(),
2266+
* //and createCapture() functions.
2267+
*
2268+
* //In this example we create
2269+
* //a new p5.MediaElement via createAudio().
2270+
* ele = createAudio('assets/lucky_dragons_-_power_melody.mp3');
2271+
* background(250);
2272+
* textAlign(CENTER);
2273+
* text('start at beginning', width / 2, height / 2);
2274+
* }
2275+
*
2276+
* // this function fires with click anywhere
2277+
* function mousePressed() {
2278+
* if (beginning === true) {
2279+
* // here we start the sound at the beginning
2280+
* // time(0) is not necessary here
2281+
* // as this produces the same result as
2282+
* // play()
2283+
* ele.play().time(0);
2284+
* background(200);
2285+
* text('jump 2 sec in', width / 2, height / 2);
2286+
* beginning = false;
2287+
* } else {
2288+
* // here we jump 2 seconds into the sound
2289+
* ele.play().time(2);
2290+
* background(250);
2291+
* text('start at beginning', width / 2, height / 2);
2292+
* beginning = true;
2293+
* }
2294+
* }
2295+
* </code></div>
22592296
*/
2297+
22602298
p5.MediaElement.prototype.time = function(val) {
22612299
if (typeof val === 'undefined') {
22622300
return this.elt.currentTime;
@@ -2483,6 +2521,26 @@
24832521
* Show the default MediaElement controls, as determined by the web browser.
24842522
*
24852523
* @method showControls
2524+
* @example
2525+
* <div><code>
2526+
* var ele;
2527+
* function setup() {
2528+
* //p5.MediaElement objects are usually created
2529+
* //by calling the createAudio(), createVideo(),
2530+
* //and createCapture() functions.
2531+
* //In this example we create
2532+
* //a new p5.MediaElement via createAudio()
2533+
* ele = createAudio('assets/lucky_dragons_-_power_melody.mp3');
2534+
* background(200);
2535+
* textAlign(CENTER);
2536+
* text('Click to Show Controls!', 10, 25, 70, 80);
2537+
* }
2538+
* function mousePressed() {
2539+
* ele.showControls();
2540+
* background(200);
2541+
* text('Controls Shown', width / 2, height / 2);
2542+
* }
2543+
* </code></div>
24862544
*/
24872545
p5.MediaElement.prototype.showControls = function() {
24882546
// must set style for the element to show on the page

src/core/constants.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,31 @@ module.exports = {
125125
*/
126126
TWO_PI: PI * 2,
127127
/**
128+
* Constant to be used with angleMode() function, to set the mode which
129+
* p5.js interprates and calculates angles (either DEGREES or RADIANS).
128130
* @property {String} DEGREES
129131
* @final
132+
*
133+
* @example
134+
* <div class='norender'><code>
135+
* function setup() {
136+
* angleMode(DEGREES);
137+
* }
138+
* </code></div>
130139
*/
131140
DEGREES: 'degrees',
132141
/**
142+
* Constant to be used with angleMode() function, to set the mode which
143+
* p5.js interprates and calculates angles (either RADIANS or DEGREES).
133144
* @property {String} RADIANS
134145
* @final
146+
*
147+
* @example
148+
* <div class='norender'><code>
149+
* function setup() {
150+
* angleMode(RADIANS);
151+
* }
152+
* </code></div>
135153
*/
136154
RADIANS: 'radians',
137155
DEG_TO_RAD: PI / 180.0,

src/core/rendering.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ p5.prototype.createCanvas = function(w, h, renderer) {
5757
if (c) {
5858
//if defaultCanvas already exists
5959
c.parentNode.removeChild(c); //replace the existing defaultCanvas
60+
var thisRenderer = this._renderer;
6061
this._elements = this._elements.filter(function(e) {
61-
return e !== this._renderer;
62+
return e !== thisRenderer;
6263
});
6364
}
6465
c = document.createElement('canvas');
@@ -149,7 +150,11 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) {
149150
this._renderer.resize(w, h);
150151
// reset canvas properties
151152
for (var savedKey in props) {
152-
this.drawingContext[savedKey] = props[savedKey];
153+
try {
154+
this.drawingContext[savedKey] = props[savedKey];
155+
} catch (err) {
156+
// ignore read-only property errors
157+
}
153158
}
154159
if (!noRedraw) {
155160
this.redraw();

src/webgl/light.js

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,30 @@ var p5 = require('../core/core');
6262
* @chainable
6363
*/
6464
p5.prototype.ambientLight = function(v1, v2, v3, a) {
65-
if (!this._renderer.curFillShader.isLightShader()) {
66-
this._renderer.setFillShader(this._renderer._getLightShader());
67-
}
65+
var color = this.color.apply(this, arguments);
6866

69-
var color = this._renderer._pInst.color.apply(
70-
this._renderer._pInst,
71-
arguments
72-
);
67+
var shader = this._renderer._useLightShader();
7368

7469
//@todo this is a bit icky. array uniforms have
7570
//to be multiples of the type 3(rgb) in this case.
7671
//a preallocated Float32Array(24) that we copy into
7772
//would be better
78-
var colors = new Float32Array(color._array.slice(0, 3));
79-
this._renderer.curFillShader.setUniform('uAmbientColor', colors);
80-
this._renderer.curFillShader.setUniform('uUseLighting', true);
81-
this._renderer.ambientLightCount++;
73+
shader.setUniform('uUseLighting', true);
8274
//in case there's no material color for the geometry
83-
this._renderer.curFillShader.setUniform(
84-
'uMaterialColor',
85-
this._renderer.curFillColor
75+
shader.setUniform('uMaterialColor', this._renderer.curFillColor);
76+
77+
this._renderer.ambientLightColors.push(
78+
color._array[0],
79+
color._array[1],
80+
color._array[2]
8681
);
87-
this._renderer.curFillShader.setUniform(
82+
shader.setUniform('uAmbientColor', this._renderer.ambientLightColors);
83+
84+
shader.setUniform(
8885
'uAmbientLightCount',
89-
this._renderer.ambientLightCount
86+
this._renderer.ambientLightColors.length / 3
9087
);
88+
9189
return this;
9290
};
9391

@@ -152,19 +150,10 @@ p5.prototype.ambientLight = function(v1, v2, v3, a) {
152150
*
153151
*/
154152
p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
155-
if (!this._renderer.curFillShader.isLightShader()) {
156-
this._renderer.setFillShader(this._renderer._getLightShader());
157-
}
153+
var shader = this._renderer._useLightShader();
158154

159155
//@TODO: check parameters number
160-
var color = this._renderer._pInst.color.apply(this._renderer._pInst, [
161-
v1,
162-
v2,
163-
v3
164-
]);
165-
166-
var colors = new Float32Array(color._array.slice(0, 3));
167-
this._renderer.curFillShader.setUniform('uDirectionalColor', colors);
156+
var color = this.color.apply(this, [v1, v2, v3]);
168157

169158
var _x, _y, _z;
170159

@@ -177,26 +166,32 @@ p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
177166
_y = args[args.length - 2];
178167
_z = args[args.length - 1];
179168
} else {
180-
try {
181-
_x = args[args.length - 1].x;
182-
_y = args[args.length - 1].y;
183-
_z = args[args.length - 1].z;
184-
} catch (error) {
185-
throw error;
186-
}
169+
_x = args[args.length - 1].x;
170+
_y = args[args.length - 1].y;
171+
_z = args[args.length - 1].z;
187172
}
188-
this._renderer.curFillShader.setUniform('uUseLighting', true);
173+
shader.setUniform('uUseLighting', true);
189174
//in case there's no material color for the geometry
190-
this._renderer.curFillShader.setUniform(
191-
'uMaterialColor',
192-
this._renderer.curFillColor
175+
shader.setUniform('uMaterialColor', this._renderer.curFillColor);
176+
177+
this._renderer.directionalLightDirections.push(_x, _y, _z);
178+
shader.setUniform(
179+
'uLightingDirection',
180+
this._renderer.directionalLightDirections
181+
);
182+
183+
this._renderer.directionalLightColors.push(
184+
color._array[0],
185+
color._array[1],
186+
color._array[2]
193187
);
194-
this._renderer.curFillShader.setUniform('uLightingDirection', [_x, _y, _z]);
195-
this._renderer.directionalLightCount++;
196-
this._renderer.curFillShader.setUniform(
188+
shader.setUniform('uDirectionalColor', this._renderer.directionalLightColors);
189+
190+
shader.setUniform(
197191
'uDirectionalLightCount',
198-
this._renderer.directionalLightCount
192+
this._renderer.directionalLightColors.length / 3
199193
);
194+
200195
return this;
201196
};
202197

@@ -267,19 +262,13 @@ p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
267262
* @chainable
268263
*/
269264
p5.prototype.pointLight = function(v1, v2, v3, x, y, z) {
270-
if (!this._renderer.curFillShader.isLightShader()) {
271-
this._renderer.setFillShader(this._renderer._getLightShader());
272-
}
273265
//@TODO: check parameters number
274266
var color = this._renderer._pInst.color.apply(this._renderer._pInst, [
275267
v1,
276268
v2,
277269
v3
278270
]);
279271

280-
var colors = new Float32Array(color._array.slice(0, 3));
281-
this._renderer.curFillShader.setUniform('uPointLightColor', colors);
282-
283272
var _x, _y, _z;
284273

285274
var args = new Array(arguments.length);
@@ -291,26 +280,31 @@ p5.prototype.pointLight = function(v1, v2, v3, x, y, z) {
291280
_y = args[args.length - 2];
292281
_z = args[args.length - 1];
293282
} else {
294-
try {
295-
_x = args[args.length - 1].x;
296-
_y = args[args.length - 1].y;
297-
_z = args[args.length - 1].z;
298-
} catch (error) {
299-
throw error;
300-
}
283+
_x = args[args.length - 1].x;
284+
_y = args[args.length - 1].y;
285+
_z = args[args.length - 1].z;
301286
}
302-
this._renderer.curFillShader.setUniform('uUseLighting', true);
287+
288+
var shader = this._renderer._useLightShader();
289+
shader.setUniform('uUseLighting', true);
303290
//in case there's no material color for the geometry
304-
this._renderer.curFillShader.setUniform(
305-
'uMaterialColor',
306-
this._renderer.curFillColor
291+
shader.setUniform('uMaterialColor', this._renderer.curFillColor);
292+
293+
this._renderer.pointLightPositions.push(_x, _y, _z);
294+
shader.setUniform('uPointLightLocation', this._renderer.pointLightPositions);
295+
296+
this._renderer.pointLightColors.push(
297+
color._array[0],
298+
color._array[1],
299+
color._array[2]
307300
);
308-
this._renderer.curFillShader.setUniform('uPointLightLocation', [_x, _y, _z]);
309-
this._renderer.pointLightCount++;
310-
this._renderer.curFillShader.setUniform(
301+
shader.setUniform('uPointLightColor', this._renderer.pointLightColors);
302+
303+
shader.setUniform(
311304
'uPointLightCount',
312-
this._renderer.pointLightCount
305+
this._renderer.pointLightColors.length / 3
313306
);
307+
314308
return this;
315309
};
316310

0 commit comments

Comments
 (0)