Skip to content

Commit d815160

Browse files
committed
Merge branch 'dev-2.0' into compute-shaders
2 parents 4704868 + 908b89b commit d815160

File tree

16 files changed

+485
-232
lines changed

16 files changed

+485
-232
lines changed

docs/parameterData.json

Lines changed: 161 additions & 149 deletions
Large diffs are not rendered by default.

src/color/p5.Color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ class Color {
727727
if(!Array.isArray(v)){
728728
return [0, v];
729729
}else{
730-
return v
730+
return v;
731731
}
732732
});
733733

src/color/setting.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ function setting(p5, fn){
580580
* @chainable
581581
*/
582582
fn.background = function(...args) {
583-
this._renderer.background(...args);
584-
return this;
583+
return this._renderer.background(...args);
585584
};
586585

587586
/**
@@ -1096,6 +1095,8 @@ function setting(p5, fn){
10961095
* or `HSLA` colors, depending on the current <a href="#/p5/colorMode">colorMode()</a>. The last parameter
10971096
* sets the alpha (transparency) value.
10981097
*
1098+
* Calling `fill()` without an argument returns the current fill as a <a href="#/p5.Color">p5.Color</a> object.
1099+
*
10991100
* @method fill
11001101
* @param {Number} v1 red value if color mode is RGB or hue value if color mode is HSB.
11011102
* @param {Number} v2 green value if color mode is RGB or saturation value if color mode is HSB.
@@ -1284,9 +1285,12 @@ function setting(p5, fn){
12841285
* @param {p5.Color} color the fill color.
12851286
* @chainable
12861287
*/
1288+
/**
1289+
* @method fill
1290+
* @return {p5.Color} the current fill color.
1291+
*/
12871292
fn.fill = function(...args) {
1288-
this._renderer.fill(...args);
1289-
return this;
1293+
return this._renderer.fill(...args);
12901294
};
12911295

12921296
/**
@@ -1415,6 +1419,8 @@ function setting(p5, fn){
14151419
* or HSLA colors, depending on the current `colorMode()`. The last parameter
14161420
* sets the alpha (transparency) value.
14171421
*
1422+
* Calling `stroke()` without an argument returns the current stroke as a <a href="#/p5.Color">p5.Color</a> object.
1423+
*
14181424
* @method stroke
14191425
* @param {Number} v1 red value if color mode is RGB or hue value if color mode is HSB.
14201426
* @param {Number} v2 green value if color mode is RGB or saturation value if color mode is HSB.
@@ -1601,9 +1607,12 @@ function setting(p5, fn){
16011607
* @param {p5.Color} color the stroke color.
16021608
* @chainable
16031609
*/
1610+
/**
1611+
* @method stroke
1612+
* @return {p5.Color} the current stroke color.
1613+
*/
16041614
fn.stroke = function(...args) {
1605-
this._renderer.stroke(...args);
1606-
return this;
1615+
return this._renderer.stroke(...args);
16071616
};
16081617

16091618
/**
@@ -1768,6 +1777,8 @@ function setting(p5, fn){
17681777
* EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,
17691778
* SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT
17701779
*
1780+
* Calling `blendMode()` without an argument returns the current blendMode.
1781+
*
17711782
* @example
17721783
* function setup() {
17731784
* createCanvas(100, 100);
@@ -2136,6 +2147,10 @@ function setting(p5, fn){
21362147
* describe('A yellow line and a turquoise line form an X on a gray background. The area where they overlap is green.');
21372148
* }
21382149
*/
2150+
/**
2151+
* @method blendMode
2152+
* @return {(BLEND|DARKEST|LIGHTEST|DIFFERENCE|MULTIPLY|EXCLUSION|SCREEN|REPLACE|OVERLAY|HARD_LIGHT|SOFT_LIGHT|DODGE|BURN|ADD|REMOVE|SUBTRACT)} the current blend mode.
2153+
*/
21392154
fn.blendMode = function (mode) {
21402155
// p5._validateParameters('blendMode', arguments);
21412156
if (mode === constants.NORMAL) {
@@ -2145,7 +2160,7 @@ function setting(p5, fn){
21452160
);
21462161
mode = constants.BLEND;
21472162
}
2148-
this._renderer.blendMode(mode);
2163+
return this._renderer.blendMode(mode);
21492164
};
21502165
}
21512166

src/core/environment.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ function environment(p5, fn, lifecycles){
215215
* cursor, `x` and `y` set the location pointed to within the image. They are
216216
* both 0 by default, so the cursor points to the image's top-left corner. `x`
217217
* and `y` must be less than the image's width and height, respectively.
218+
*
219+
* Calling `cursor()` without an argument returns the current cursor type as a string.
218220
*
219221
* @method cursor
220222
* @param {(ARROW|CROSS|HAND|MOVE|TEXT|WAIT|String)} type Built-in: either ARROW, CROSS, HAND, MOVE, TEXT, or WAIT.
@@ -281,9 +283,17 @@ function environment(p5, fn, lifecycles){
281283
* }
282284
* }
283285
*/
286+
/**
287+
* @method cursor
288+
* @return {(ARROW|CROSS|HAND|MOVE|TEXT|WAIT|String)} the current cursor type
289+
*/
284290
fn.cursor = function(type, x, y) {
285291
let cursor = 'auto';
286292
const canvas = this._curElement.elt;
293+
if (typeof type === 'undefined') {
294+
let curstr = canvas.style.cursor;
295+
return curstr.length ? curstr : 'default';
296+
}
287297
if (standardCursors.includes(type)) {
288298
// Standard css cursor
289299
cursor = type;

src/core/p5.Renderer.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,20 @@ class Renderer {
4545
rectMode: constants.CORNER,
4646
ellipseMode: constants.CENTER,
4747
strokeWeight: 1,
48+
bezierOrder: 3,
49+
splineProperties: new ClonableObject({
50+
ends: constants.INCLUDE,
51+
tightness: 0
52+
}),
4853

4954
textFont: { family: 'sans-serif' },
5055
textLeading: 15,
5156
leadingSet: false,
5257
textSize: 12,
5358
textAlign: constants.LEFT,
5459
textBaseline: constants.BASELINE,
55-
bezierOrder: 3,
56-
splineProperties: new ClonableObject({
57-
ends: constants.INCLUDE,
58-
tightness: 0
59-
}),
6060
textWrap: constants.WORD,
61-
62-
// added v2.0
63-
fontStyle: constants.NORMAL, // v1: textStyle
61+
fontStyle: constants.NORMAL, // v1: was textStyle
6462
fontStretch: constants.NORMAL,
6563
fontWeight: constants.NORMAL,
6664
lineHeight: constants.NORMAL,
@@ -330,24 +328,29 @@ class Renderer {
330328
}
331329

332330
fill(...args) {
333-
this.states.setValue('fillSet', true);
334-
this.states.setValue('fillColor', this._pInst.color(...args));
335-
this.updateShapeVertexProperties();
331+
if (args.length > 0) {
332+
this.states.setValue('fillSet', true);
333+
this.states.setValue('fillColor', this._pInst.color(...args));
334+
this.updateShapeVertexProperties();
335+
}
336+
return this.states.fillColor;
336337
}
337338

338339
noFill() {
339340
this.states.setValue('fillColor', null);
340341
}
341342

342343
strokeWeight(w) {
343-
if (w === undefined) {
344+
if (typeof w === 'undefined') {
344345
return this.states.strokeWeight;
345-
} else {
346-
this.states.setValue('strokeWeight', w);
347346
}
347+
this.states.setValue('strokeWeight', w);
348348
}
349349

350350
stroke(...args) {
351+
if (args.length === 0) {
352+
return this.states.strokeColor;
353+
}
351354
this.states.setValue('strokeSet', true);
352355
this.states.setValue('strokeColor', this._pInst.color(...args));
353356
this.updateShapeVertexProperties();

src/core/p5.Renderer2D.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,18 @@ class Renderer2D extends Renderer {
166166
//////////////////////////////////////////////
167167

168168
background(...args) {
169+
if (args.length === 0) {
170+
return this;// setter with no args does nothing
171+
}
169172
this.push();
170173
this.resetMatrix();
171-
172174
if (args[0] instanceof Image) {
175+
const img = args[0];
173176
if (args[1] >= 0) {
174177
// set transparency of background
175-
const img = args[0];
176178
this.drawingContext.globalAlpha = args[1] / 255;
177-
this._pInst.image(img, 0, 0, this.width, this.height);
178-
} else {
179-
this._pInst.image(args[0], 0, 0, this.width, this.height);
180179
}
180+
this._pInst.image(img, 0, 0, this.width, this.height);
181181
} else {
182182
// create background rect
183183
const color = this._pInst.color(...args);
@@ -202,6 +202,8 @@ class Renderer2D extends Renderer {
202202
}
203203
}
204204
this.pop();
205+
206+
return this;
205207
}
206208

207209
clear() {
@@ -214,6 +216,9 @@ class Renderer2D extends Renderer {
214216
fill(...args) {
215217
super.fill(...args);
216218
const color = this.states.fillColor;
219+
if (args.length === 0) {
220+
return color; // getter
221+
}
217222
this._setFill(color.toString());
218223

219224
// Add accessible outputs if the method exists; on success,
@@ -226,6 +231,9 @@ class Renderer2D extends Renderer {
226231
stroke(...args) {
227232
super.stroke(...args);
228233
const color = this.states.strokeColor;
234+
if (args.length === 0) {
235+
return color; // getter
236+
}
229237
this._setStroke(color.toString());
230238

231239
// Add accessible outputs if the method exists; on success,
@@ -484,6 +492,9 @@ class Renderer2D extends Renderer {
484492
//////////////////////////////////////////////
485493

486494
blendMode(mode) {
495+
if (typeof mode === 'undefined') { // getter
496+
return this._cachedBlendMode;
497+
}
487498
if (mode === constants.SUBTRACT) {
488499
console.warn('blendMode(SUBTRACT) only works in WEBGL mode.');
489500
} else if (
@@ -1004,6 +1015,9 @@ class Renderer2D extends Renderer {
10041015
//////////////////////////////////////////////
10051016

10061017
strokeCap(cap) {
1018+
if (typeof cap === 'undefined') { // getter
1019+
return this.drawingContext.lineCap;
1020+
}
10071021
if (
10081022
cap === constants.ROUND ||
10091023
cap === constants.SQUARE ||
@@ -1015,6 +1029,9 @@ class Renderer2D extends Renderer {
10151029
}
10161030

10171031
strokeJoin(join) {
1032+
if (typeof join === 'undefined') { // getter
1033+
return this.drawingContext.lineJoin;
1034+
}
10181035
if (
10191036
join === constants.ROUND ||
10201037
join === constants.BEVEL ||
@@ -1027,7 +1044,10 @@ class Renderer2D extends Renderer {
10271044

10281045
strokeWeight(w) {
10291046
super.strokeWeight(w);
1030-
if (typeof w === 'undefined' || w === 0) {
1047+
if (typeof w === 'undefined') {
1048+
return this.states.strokeWeight;
1049+
}
1050+
if (w === 0) {
10311051
// hack because lineWidth 0 doesn't work
10321052
this.drawingContext.lineWidth = 0.0001;
10331053
} else {
@@ -1090,16 +1110,22 @@ class Renderer2D extends Renderer {
10901110

10911111
rotate(rad) {
10921112
this.drawingContext.rotate(rad);
1113+
return this;
10931114
}
10941115

10951116
scale(x, y) {
1117+
// support passing objects with x,y properties (including p5.Vector)
1118+
if (typeof x === 'object' && 'x' in x && 'y' in x) {
1119+
y = x.y;
1120+
x = x.x;
1121+
}
10961122
this.drawingContext.scale(x, y);
10971123
return this;
10981124
}
10991125

11001126
translate(x, y) {
1101-
// support passing a vector as the 1st parameter
1102-
if (x instanceof p5.Vector) {
1127+
// support passing objects with x,y properties (including p5.Vector)
1128+
if (typeof x === 'object' && 'x' in x && 'y' in x) {
11031129
y = x.y;
11041130
x = x.x;
11051131
}

src/core/p5.Renderer3D.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class Renderer3D extends Renderer {
137137
this.states._useShininess = 1;
138138
this.states._useMetalness = 0;
139139

140-
this.states.tint = [255, 255, 255, 255];
140+
this.states.tint = new Color([1, 1, 1, 1]);
141141

142142
this.states.constantAttenuation = 1;
143143
this.states.linearAttenuation = 0;
@@ -726,10 +726,10 @@ export class Renderer3D extends Renderer {
726726
this.states.setValue("enableLighting", false);
727727

728728
//reset tint value for new frame
729-
this.states.setValue("tint", [255, 255, 255, 255]);
729+
this.states.setValue("tint", new Color([1,1,1,1]));
730730

731731
//Clear depth every frame
732-
this._resetBuffersBeforeDraw()
732+
this._resetBuffersBeforeDraw();
733733
}
734734

735735
background(...args) {
@@ -1491,7 +1491,7 @@ export class Renderer3D extends Renderer {
14911491
// works differently and is global p5 state. If the p5 state has
14921492
// been cleared, we also need to clear the value in uSampler to match.
14931493
fillShader.setUniform("uSampler", this.states._tex || empty);
1494-
fillShader.setUniform("uTint", this.states.tint);
1494+
fillShader.setUniform("uTint", this.states.tint._getRGBA([255, 255, 255, 255]));
14951495

14961496
fillShader.setUniform("uHasSetAmbient", this.states._hasSetAmbient);
14971497
fillShader.setUniform("uAmbientMatColor", this.states.curAmbientColor);

0 commit comments

Comments
 (0)