Skip to content

Commit

Permalink
Merge pull request #6557 from Jaivignesh-afk/enhancement-rendering-re…
Browse files Browse the repository at this point in the history
…fact

Refactored the createGraphics function in rendering.js
  • Loading branch information
davepagurek authored Nov 21, 2023
2 parents cab0ff1 + 3485168 commit bfb4c56
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,17 @@ p5.prototype.noCanvas = function() {
* @param {HTMLCanvasElement} [canvas]
* @return {p5.Graphics} offscreen graphics buffer
*/
p5.prototype.createGraphics = function(w, h, renderer, canvas) {
if (arguments[2] instanceof HTMLCanvasElement) {
renderer = constants.P2D;
canvas = arguments[2];
p5.prototype.createGraphics = function(w, h, ...args) {
/**
* args[0] is expected to be renderer
* args[1] is expected to be canvas
*/
if (args[0] instanceof HTMLCanvasElement) {
args[1] = args[0];
args[0] = constants.P2D;
}
p5._validateParameters('createGraphics', arguments);
return new p5.Graphics(w, h, renderer, this, canvas);
return new p5.Graphics(w, h, args[0], this, args[1]);
};

/**
Expand Down

0 comments on commit bfb4c56

Please sign in to comment.