Skip to content

Commit d76f26a

Browse files
committed
Make default sketch canvas ID autoincrement
1 parent 53d6aa8 commit d76f26a

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/core/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class p5 {
3535
// This is a pointer to our global mode p5 instance, if we're in
3636
// global mode.
3737
static instance = null;
38+
static sketchCount = 0;
3839
static lifecycleHooks = {
3940
presetup: [],
4041
postsetup: [],

src/core/p5.Renderer2D.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import FilterRenderer2D from '../image/filterRenderer2D';
1010
import { Matrix } from '../math/p5.Matrix';
1111
import { PrimitiveToPath2DConverter } from '../shape/custom_shapes';
1212

13-
1413
const styleEmpty = 'rgba(0,0,0,0)';
15-
// const alphaThreshold = 0.00125; // minimum visible
1614

1715
class Renderer2D extends Renderer {
1816
constructor(pInst, w, h, isMainCanvas, elt, attributes = {}) {
@@ -29,7 +27,9 @@ class Renderer2D extends Renderer {
2927
this.canvas.style.display = 'none';
3028
}
3129

32-
this.elt.id = 'defaultCanvas0';
30+
if(!this.elt.id){
31+
this.elt.id = `defaultCanvas${p5.sketchCount++}`;
32+
}
3333
this.elt.classList.add('p5Canvas');
3434

3535
// Extend renderer with methods of p5.Element with getters

src/webgl/p5.RendererGL.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ class RendererGL extends Renderer {
136136
// hide if offscreen buffer by default
137137
this.canvas.style.display = "none";
138138
}
139-
this.elt.id = "defaultCanvas0";
139+
140+
if(!this.elt.id){
141+
this.elt.id = `defaultCanvas${p5.sketchCount++}`;
142+
}
140143
this.elt.classList.add("p5Canvas");
141144

142145
// Set and return p5.Element

0 commit comments

Comments
 (0)