Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Resolves #8278#8328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dhowe wants to merge5 commits intoprocessing:dev-2.0
base:dev-2.0
Choose a base branch
Loading
fromdhowe:ticket8278
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
update parameter json, add tests for getters
  • Loading branch information
@dhowe
dhowe committedDec 10, 2025
commit039ef43bc08ddf32981092fc93c88508ba6c6c8f
52 changes: 37 additions & 15 deletionsdocs/parameterData.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -162,6 +162,7 @@
},
"background": {
"overloads": [
[],
[
"p5.Color"
],
Expand DownExpand Up@@ -201,6 +202,7 @@
},
"colorMode": {
"overloads": [
[],
[
"RGB|HSB|HSL|RGBHDR|HWB|LAB|LCH|OKLAB|OKLCH",
"Number?"
Expand All@@ -217,6 +219,7 @@
},
"fill": {
"overloads": [
[],
[
"Number",
"Number",
Expand DownExpand Up@@ -250,6 +253,7 @@
},
"stroke": {
"overloads": [
[],
[
"Number",
"Number",
Expand DownExpand Up@@ -286,6 +290,7 @@
},
"blendMode": {
"overloads": [
[],
[
"BLEND|DARKEST|LIGHTEST|DIFFERENCE|MULTIPLY|EXCLUSION|SCREEN|REPLACE|OVERLAY|HARD_LIGHT|SOFT_LIGHT|DODGE|BURN|ADD|REMOVE|SUBTRACT"
]
Expand All@@ -303,6 +308,7 @@
},
"cursor": {
"overloads": [
[],
[
"ARROW|CROSS|HAND|MOVE|TEXT|WAIT|String",
"Number?",
Expand DownExpand Up@@ -528,28 +534,32 @@
[
"Number",
"p5.Vector|Number[]?"
]
],
[]
]
},
"rotateX": {
"overloads": [
[
"Number"
]
],
[]
]
},
"rotateY": {
"overloads": [
[
"Number"
]
],
[]
]
},
"rotateZ": {
"overloads": [
[
"Number"
]
],
[]
]
},
"scale": {
Expand All@@ -561,21 +571,24 @@
],
[
"p5.Vector|Number[]"
]
],
[]
]
},
"shearX": {
"overloads": [
[
"Number"
]
],
[]
]
},
"shearY": {
"overloads": [
[
"Number"
]
],
[]
]
},
"translate": {
Expand All@@ -587,7 +600,8 @@
],
[
"p5.Vector"
]
],
[]
]
},
"push": {
Expand DownExpand Up@@ -1014,7 +1028,8 @@
],
[
"p5.Color"
]
],
[]
]
},
"noTint": {
Expand All@@ -1026,7 +1041,8 @@
"overloads": [
[
"CORNER|CORNERS|CENTER"
]
],
[]
]
},
"blend": {
Expand DownExpand Up@@ -1748,7 +1764,8 @@
"overloads": [
[
"CENTER|RADIUS|CORNER|CORNERS"
]
],
[]
]
},
"noSmooth": {
Expand All@@ -1758,6 +1775,7 @@
},
"rectMode": {
"overloads": [
[],
[
"CENTER|RADIUS|CORNER|CORNERS"
]
Expand All@@ -1772,21 +1790,24 @@
"overloads": [
[
"ROUND|SQUARE|PROJECT"
]
],
[]
]
},
"strokeJoin": {
"overloads": [
[
"MITER|BEVEL|ROUND"
]
],
[]
]
},
"strokeWeight": {
"overloads": [
[
"Number"
]
],
[]
]
},
"bezier": {
Expand DownExpand Up@@ -2108,7 +2129,8 @@
[
"LEFT|CENTER|RIGHT?",
"TOP|BOTTOM|CENTER|BASELINE?"
]
],
[]
]
},
"textAscent": {
Expand Down
14 changes: 8 additions & 6 deletionssrc/core/p5.Renderer2D.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,20 +165,20 @@ class Renderer2D extends Renderer {
//////////////////////////////////////////////

background(...args) {
this.push();
this.resetMatrix();
if (args.length === 0) {
// getter (#8278)
return this.states.background;
return this.states.background; // getter (#8278)
}
let bgForState = null;
this.push();
this.resetMatrix();
if (args[0] instanceof Image) {
const img = args[0];
if (args[1] >= 0) {
// set transparency of background
this.drawingContext.globalAlpha = args[1] / 255;
}
this._pInst.image(img, 0, 0, this.width, this.height);
this.states.background = img; // save for getter (#8278)
bgForState = img; // save for getter (#8278)
} else {
// create background rect
const color = this._pInst.color(...args);
Expand All@@ -201,9 +201,11 @@ class Renderer2D extends Renderer {
if (this._isErasing) {
this._pInst.erase();
}
this.states.background = color; // save for getter (#8278)
bgForState = color; // save for getter (#8278)
}
this.pop();

this.states.setValue('background', bgForState); // set state (#8278)
}

clear() {
Expand Down
2 changes: 1 addition & 1 deletionsrc/shape/attributes.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -290,7 +290,7 @@ function attributes(p5, fn){
fn.rectMode = function(m) {
// p5._validateParameters('rectMode', arguments);
if (typeof m === 'undefined') { // getter
return this._renderer?.states.ellipseMode;
return this._renderer?.states.rectMode;
}
if (
m === constants.CORNER ||
Expand Down
69 changes: 69 additions & 0 deletionstest/unit/core/properties.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import p5 from '../../../src/app.js';

suite('Set/get properties', function() {

let p = new p5(function (sketch) {
sketch.setup = function () { };
sketch.draw = function () { };
});

/*beforeEach(function () {
myp5 = new p5(function (p) {
p.setup = function () { };
p.draw = function () { };
});
});
afterEach(function () {
myp5.remove();
});*/

let getters = {
background: new p5.Color([100, 100, 50]),
fill: new p5.Color([100, 200, 50]),
stroke: new p5.Color([200, 100, 50, 100]),
tint: new p5.Color([100, 140, 50]),

rectMode: p.CENTER,
colorMode: p.HSB,
blendMode: 'source-over',
imageMode: p.CORNER,
ellipseMode: p.CORNER,

strokeWeight: 6,
strokeCap: p.ROUND,
strokeJoin: p.MITER,
pixelDensity: 1,
cursor: 'pointer',

rotate: p.PI,
translate: { x: 1, y: 2 },
scale: { x: 1, y: 2 },

textAlign: { horizontal: p.CENTER, vertical: p.CENTER },
textLeading: 18,
textFont: 'arial',
textSize: 1,
textStyle: 1,
textWrap: p.WORD,
textDirection: 1,
textWeight: 1
};

Object.keys(getters).forEach(prop => {
let arg = getters[prop];
test(`${prop}()`, function() {
// setter
if (typeof arg === 'object' && !(arg instanceof p5.Color)) {
p[prop](...Object.values(arg)); // set with object
}
else if (Array.isArray(arg)) {
p[prop](...arg); // set with array
}
else {
p[prop](arg); // set with primitive
}
// getter
assert.strictEqual(p[prop]().toString(), arg.toString(), `${arg.toString()}`);
});
});
});

[8]ページ先頭

©2009-2025 Movatter.jp