Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
psicomante committed Dec 9, 2024
1 parent 2bdb073 commit 94702e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/p5.RendererSVG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default function (p5: P5SVG) {
}
})

p5.Renderer2D.call(this, elt, pInstProxy, isMainCanvas)
// fix: [email protected]+ (zenozeng#254,zenozeng#255,zenozeng#258) by nkymut
Object.assign(this, p5.Renderer2D.call(this, elt, pInstProxy, isMainCanvas))

this.isSVG = true
this.svg = svg
Expand Down
16 changes: 8 additions & 8 deletions src/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ export default function (p5: P5SVG) {
const _graphics = p5.Graphics
p5.Graphics = function (w: number, h: number, renderer: any, pInst: p5SVG) {
const isSVG = renderer === constants.SVG
_graphics.apply(this, [w, h, isSVG ? pInst.P2D : renderer, pInst])
const pg = new _graphics(w, h, isSVG ? pInst.P2D : renderer, pInst)
if (isSVG) {
// replace <canvas> with <svg>
let c = this._renderer.elt
this._renderer = new p5.RendererSVG(c, this, false) // replace renderer
c = this._renderer.elt
this.elt = c // replace this.elt
const svgRenderer = new p5.RendererSVG(pg.elt, pg, false)
pg._renderer = svgRenderer
pg.elt = svgRenderer.elt

// do default again
this._renderer.resize(w, h)
this._renderer._applyDefaults()
pg._renderer.resize(w, h)
pg._renderer._applyDefaults()
}
return this
return pg
}
p5.Graphics.prototype = _graphics.prototype

Expand Down

0 comments on commit 94702e3

Please sign in to comment.