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

Commit 9361f05

Browse files
MaxPleanerPWhiddy
authored andcommitted
Make p5.js target work with standalone P5
P5 functions are available as globals in their web editor but not necessary the case in all P5 environments. Modify the P5 draw function to make it work in environments where those functions aren't global.
1 parent b09bde1 commit 9361f05

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎targets/p5.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function createRenderer(target, {
9696
);
9797
}
9898

99-
const gl = window._renderer.GL;
99+
const gl = target._renderer.GL;
100100
const faceCullingEnabled = gl.isEnabled(gl.CULL_FACE);
101101
const cullFaceMode = gl.getParameter(gl.CULL_FACE_MODE);
102102
gl.enable(gl.CULL_FACE);
@@ -105,7 +105,7 @@ function createRenderer(target, {
105105
target.push();
106106
target.noStroke();
107107
target.shader(output.shader);
108-
output.shader.setUniform('time', millis() / 1000);
108+
output.shader.setUniform('time', target.millis() / 1000);
109109
output.shader.setUniform('opacity', 1);
110110
output.shader.setUniform(
111111
'mouse',
@@ -119,15 +119,15 @@ function createRenderer(target, {
119119
output.shader.setUniform('stepSize', 0.85);
120120
output.shader.setUniform(
121121
'resolution',
122-
[width * target.pixelDensity(), height * target.pixelDensity()]
122+
[target.width * target.pixelDensity(), target.height * target.pixelDensity()]
123123
);
124124
drawGeometry();
125125
if (!faceCullingEnabled) {
126126
gl.disable(gl.CULL_FACE);
127127
} else {
128128
gl.cullFace(cullFaceMode);
129129
}
130-
pop();
130+
target.pop();
131131
},
132132
};
133133

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /