Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions src/core/p5.Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ import * as constants from './constants';
* @param {Number} h height
* @param {Constant} renderer the renderer to use, either P2D or WEBGL
* @param {p5} [pInst] pointer to p5 instance
* @param {Object} canvas existing html canvas element
*/
p5.Graphics = function(w, h, renderer, pInst) {
p5.Graphics = function(w, h, renderer, pInst, canvas) {
const r = renderer || constants.P2D;

this.canvas = document.createElement('canvas');
if(canvas){
this.canvas = canvas;
}else {
this.canvas = document.createElement('canvas');
}

const node = pInst._userNode || document.body;
node.appendChild(this.canvas);
if(!canvas) {
node.appendChild(this.canvas);
}

p5.Element.call(this, this.canvas, pInst);

Expand Down
5 changes: 3 additions & 2 deletions src/core/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ p5.prototype.noCanvas = function() {
* @param {Number} h height of the offscreen graphics buffer
* @param {Constant} [renderer] either P2D or WEBGL
* undefined defaults to p2d
@param {Object} canvas existing html canvas element
* @return {p5.Graphics} offscreen graphics buffer
* @example
* <div>
Expand All @@ -224,9 +225,9 @@ p5.prototype.noCanvas = function() {
* 4 grey squares alternating light and dark grey. White quarter circle mid-left.
*
*/
p5.prototype.createGraphics = function(w, h, renderer) {
p5.prototype.createGraphics = function(w, h, renderer, canvas) {
p5._validateParameters('createGraphics', arguments);
return new p5.Graphics(w, h, renderer, this);
return new p5.Graphics(w, h, renderer, this, canvas);
};

/**
Expand Down