Skip to content

Commit 7a61e51

Browse files
author
Lauren McCarthy
committed
simplifying print function closes #2206
1 parent 0c14b3d commit 7a61e51

File tree

5 files changed

+60
-85
lines changed

5 files changed

+60
-85
lines changed

src/core/environment.js

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,33 @@ p5.prototype._targetFrameRate = 60;
1919

2020
var _windowPrint = window.print;
2121

22-
23-
if (window.console && console.log) {
24-
/**
25-
* The print() function writes to the console area of your browser.
26-
* This function is often helpful for looking at the data a program is
27-
* producing. This function creates a new line of text for each call to
28-
* the function. Individual elements can be
29-
* separated with quotes ("") and joined with the addition operator (+).
30-
* <br><br>
31-
* While print() is similar to console.log(), it does not directly map to
32-
* it in order to simulate easier to understand behavior than
33-
* console.log(). Due to this, it is slower. For fastest results, use
34-
* console.log().
35-
*
36-
* @method print
37-
* @param {Any} contents any combination of Number, String, Object, Boolean,
38-
* Array to print
39-
* @example
40-
* <div><code class='norender'>
41-
* var x = 10;
42-
* print("The value of x is " + x);
43-
* // prints "The value of x is 10"
44-
* </code></div>
45-
* @alt
46-
* default grey canvas
47-
*/
48-
// Converts passed args into a string and then parses that string to
49-
// simulate synchronous behavior. This is a hack and is gross.
50-
// Since this will not work on all objects, particularly circular
51-
// structures, simply console.log() on error.
52-
p5.prototype.print = function(args) {
53-
try {
54-
if (arguments.length === 0) {
55-
_windowPrint();
56-
}
57-
else if (arguments.length > 1) {
58-
console.log.apply(console, arguments);
59-
} else {
60-
var newArgs = JSON.parse(JSON.stringify(args));
61-
if (JSON.stringify(newArgs)==='{}'){
62-
console.log(args);
63-
} else {
64-
console.log(newArgs);
65-
}
66-
}
67-
} catch(err) {
68-
console.log(args);
69-
}
70-
};
71-
} else {
72-
p5.prototype.print = function() {};
73-
}
22+
/**
23+
* The print() function writes to the console area of your browser.
24+
* This function is often helpful for looking at the data a program is
25+
* producing. This function creates a new line of text for each call to
26+
* the function. Individual elements can be
27+
* separated with quotes ("") and joined with the addition operator (+).
28+
*
29+
* @method print
30+
* @param {Any} contents any combination of Number, String, Object, Boolean,
31+
* Array to print
32+
* @example
33+
* <div><code class='norender'>
34+
* var x = 10;
35+
* print("The value of x is " + x);
36+
* // prints "The value of x is 10"
37+
* </code></div>
38+
* @alt
39+
* default grey canvas
40+
*/
41+
p5.prototype.print = function(args) {
42+
if (arguments.length === 0) {
43+
_windowPrint();
44+
}
45+
else {
46+
console.log.apply(console, arguments);
47+
}
48+
};
7449

7550

7651
/**

src/webgl/light.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ p5.prototype.ambientLight = function(v1, v2, v3, a){
9292
* @param {Number|Array|String|p5.Color} v1 gray value,
9393
* red or hue value (depending on the current color mode),
9494
* or color Array, or CSS color string
95-
* @param {Number} [v2] optional: green or saturation value
96-
* @param {Number} [v3] optional: blue or brightness value
97-
* @param {Number} [a] optional: opacity
95+
* @param {Number} [v2] green or saturation value
96+
* @param {Number} [v3] blue or brightness value
97+
* @param {Number} [a] opacity
9898
* @param {Number|p5.Vector} x x axis direction or a p5.Vector
99-
* @param {Number} [y] optional: y axis direction
100-
* @param {Number} [z] optional: z axis direction
99+
* @param {Number} [y] y axis direction
100+
* @param {Number} [z] z axis direction
101101
* @chainable
102102
* @example
103103
* <div>
@@ -121,7 +121,7 @@ p5.prototype.ambientLight = function(v1, v2, v3, a){
121121
* light source on canvas changeable with mouse position
122122
*
123123
*/
124-
p5.prototype.directionalLight = function(v1, v2, v3, a, x, y, z) {
124+
p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
125125
if (! this._renderer.curFillShader.isLightShader()) {
126126
this._renderer.setFillShader(this._renderer._getLightShader());
127127
}
@@ -171,12 +171,12 @@ p5.prototype.directionalLight = function(v1, v2, v3, a, x, y, z) {
171171
* @param {Number|Array|String|p5.Color} v1 gray value,
172172
* red or hue value (depending on the current color mode),
173173
* or color Array, or CSS color string
174-
* @param {Number} [v2] optional: green or saturation value
175-
* @param {Number} [v3] optional: blue or brightness value
176-
* @param {Number} [a] optional: opacity
174+
* @param {Number} [v2] green or saturation value
175+
* @param {Number} [v3] blue or brightness value
176+
* @param {Number} [a] opacity
177177
* @param {Number|p5.Vector} x x axis position or a p5.Vector
178-
* @param {Number} [y] optional: y axis position
179-
* @param {Number} [z] optional: z axis position
178+
* @param {Number} [y] y axis position
179+
* @param {Number} [z] z axis position
180180
* @chainable
181181
* @example
182182
* <div>

src/webgl/material.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ p5.prototype.texture = function(){
215215
* @param {Number|Array|String|p5.Color} v1 gray value,
216216
* red or hue value (depending on the current color mode),
217217
* or color Array, or CSS color string
218-
* @param {Number} [v2] optional: green or saturation value
219-
* @param {Number} [v3] optional: blue or brightness value
220-
* @param {Number} [a] optional: opacity
218+
* @param {Number} [v2] green or saturation value
219+
* @param {Number} [v3] blue or brightness value
220+
* @param {Number} [a] opacity
221221
* @chainable
222222
* @example
223223
* <div>
@@ -258,9 +258,9 @@ p5.prototype.ambientMaterial = function(v1, v2, v3, a) {
258258
* @param {Number|Array|String|p5.Color} v1 gray value,
259259
* red or hue value (depending on the current color mode),
260260
* or color Array, or CSS color string
261-
* @param {Number} [v2] optional: green or saturation value
262-
* @param {Number} [v3] optional: blue or brightness value
263-
* @param {Number} [a] optional: opacity
261+
* @param {Number} [v2] green or saturation value
262+
* @param {Number} [v3] blue or brightness value
263+
* @param {Number} [a] opacity
264264
* @chainable
265265
* @example
266266
* <div>

src/webgl/p5.RendererGL.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ p5.RendererGL.prototype.background = function() {
355355
* @param {Number|Array|String|p5.Color} v1 gray value,
356356
* red or hue value (depending on the current color mode),
357357
* or color Array, or CSS color string
358-
* @param {Number} [v2] optional: green or saturation value
359-
* @param {Number} [v3] optional: blue or brightness value
360-
* @param {Number} [a] optional: opacity
358+
* @param {Number} [v2] green or saturation value
359+
* @param {Number} [v3] blue or brightness value
360+
* @param {Number} [a] opacity
361361
* @return {p5} the p5 object
362362
* @example
363363
* <div>
@@ -463,9 +463,9 @@ p5.RendererGL.prototype.noStroke = function() {
463463
* @param {Number|Array|String|p5.Color} v1 gray value,
464464
* red or hue value (depending on the current color mode),
465465
* or color Array, or CSS color string
466-
* @param {Number} [v2] optional: green or saturation value
467-
* @param {Number} [v3] optional: blue or brightness value
468-
* @param {Number} [a] optional: opacity
466+
* @param {Number} [v2] green or saturation value
467+
* @param {Number} [v3] blue or brightness value
468+
* @param {Number} [a] opacity
469469
* @example
470470
* <div>
471471
* <code>

src/webgl/primitives.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ p5.prototype.box = function(){
191191
* Draw a sphere with given radius
192192
* @method sphere
193193
* @param {Number} radius radius of circle
194-
* @param {Number} [detailX] optional: number of segments,
194+
* @param {Number} [detailX] number of segments,
195195
* the more segments the smoother geometry
196196
* default is 24
197-
* @param {Number} [detailY] optional: number of segments,
197+
* @param {Number} [detailY] number of segments,
198198
* the more segments the smoother geometry
199199
* default is 16
200200
* @chainable
@@ -345,10 +345,10 @@ var _truncatedCone = function(
345345
* @method cylinder
346346
* @param {Number} radius radius of the surface
347347
* @param {Number} height height of the cylinder
348-
* @param {Number} [detailX] optional: number of segments,
348+
* @param {Number} [detailX] number of segments,
349349
* the more segments the smoother geometry
350350
* default is 24
351-
* @param {Number} [detailY] optional: number of segments in y-dimension,
351+
* @param {Number} [detailY] number of segments in y-dimension,
352352
* the more segments the smoother geometry
353353
* default is 16
354354
* @chainable
@@ -411,10 +411,10 @@ p5.prototype.cylinder = function(){
411411
* @method cone
412412
* @param {Number} radius radius of the bottom surface
413413
* @param {Number} height height of the cone
414-
* @param {Number} [detailX] optional: number of segments,
414+
* @param {Number} [detailX] number of segments,
415415
* the more segments the smoother geometry
416416
* default is 24
417-
* @param {Number} [detailY] optional: number of segments,
417+
* @param {Number} [detailY] number of segments,
418418
* the more segments the smoother geometry
419419
* default is 16
420420
* @chainable
@@ -478,11 +478,11 @@ p5.prototype.cone = function(){
478478
* @param {Number} radiusx xradius of circle
479479
* @param {Number} radiusy yradius of circle
480480
* @param {Number} radiusz zradius of circle
481-
* @param {Number} [detailX] optional: number of segments,
481+
* @param {Number} [detailX] number of segments,
482482
* the more segments the smoother geometry
483483
* default is 24. Avoid detail number above
484484
* 150, it may crash the browser.
485-
* @param {Number} [detailY] optional: number of segments,
485+
* @param {Number} [detailY] number of segments,
486486
* the more segments the smoother geometry
487487
* default is 16. Avoid detail number above
488488
* 150, it may crash the browser.
@@ -558,10 +558,10 @@ p5.prototype.ellipsoid = function(){
558558
* @method torus
559559
* @param {Number} radius radius of the whole ring
560560
* @param {Number} tubeRadius radius of the tube
561-
* @param {Number} [detailX] optional: number of segments in x-dimension,
561+
* @param {Number} [detailX] number of segments in x-dimension,
562562
* the more segments the smoother geometry
563563
* default is 24
564-
* @param {Number} [detailY] optional: number of segments in y-dimension,
564+
* @param {Number} [detailY] number of segments in y-dimension,
565565
* the more segments the smoother geometry
566566
* default is 16
567567
* @chainable

0 commit comments

Comments
 (0)