-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored the createGraphics function in rendering.js #6557
Changes from 4 commits
25ce601
5e43969
3b3a7e6
e9f4f6d
e0c0498
d20e86b
3485168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
p5._validateParameters('createGraphics', [w, h, ...args]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One last thing, I think we might want to leave this one as |
||
return new p5.Graphics(w, h, args[0], this, args[1]); | ||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is a bug:
args[1]
will also beconstants.P2D
because you are setting it equal toargs[0]
after resetting that to beconstants.P2D
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! I was thinking the same. Maybe using a temporary variable could do the trick? What do you reckon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work, or alternatively just setting
args[1]
beforeargs[0]
.