Skip to content

Commit bbbcedd

Browse files
authored
Merge pull request #7836 from limzykenneth/sketch-id
Make default sketch canvas ID autoincrement
2 parents 38d522b + 37fd403 commit bbbcedd

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/core/main.js

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

src/core/p5.Renderer2D.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import { Matrix } from '../math/p5.Matrix';
1111
import { PrimitiveToPath2DConverter } from '../shape/custom_shapes';
1212
import { DefaultFill, textCoreConstants } from '../type/textCore';
1313

14-
1514
const styleEmpty = 'rgba(0,0,0,0)';
16-
// const alphaThreshold = 0.00125; // minimum visible
1715

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

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

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

0 commit comments

Comments
 (0)