Skip to content

Standardize all parameter types #7179

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

Merged
merged 1 commit into from
Aug 16, 2024
Merged
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
24 changes: 12 additions & 12 deletions src/core/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const renderers = p5.renderers = {
* @method createCanvas
* @param {Number} [width] width of the canvas. Defaults to 100.
* @param {Number} [height] height of the canvas. Defaults to 100.
* @param {Constant} [renderer] either P2D or WEBGL. Defaults to `P2D`.
* @param {(P2D|WEBGL)} [renderer] either P2D or WEBGL. Defaults to `P2D`.
* @param {HTMLCanvasElement} [canvas] existing canvas element that should be used for the sketch.
* @return {p5.Renderer} new `p5.Renderer` that holds the canvas.
*
Expand Down Expand Up @@ -129,7 +129,7 @@ const renderers = p5.renderers = {
* @param {HTMLCanvasElement} [canvas]
* @return {p5.Renderer}
*/
p5.prototype.createCanvas = function(w, h, renderer, canvas) {
p5.prototype.createCanvas = function (w, h, renderer, canvas) {
p5._validateParameters('createCanvas', arguments);
//optional: renderer, otherwise defaults to p2d

Expand Down Expand Up @@ -314,7 +314,7 @@ p5.prototype.createCanvas = function(w, h, renderer, canvas) {
* </code>
* </div>
*/
p5.prototype.resizeCanvas = function(w, h, noRedraw) {
p5.prototype.resizeCanvas = function (w, h, noRedraw) {
p5._validateParameters('resizeCanvas', arguments);
if (this._renderer) {
// save canvas properties
Expand Down Expand Up @@ -372,7 +372,7 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) {
* </code>
* </div>
*/
p5.prototype.noCanvas = function() {
p5.prototype.noCanvas = function () {
if (this.canvas) {
this.canvas.parentNode.removeChild(this.canvas);
}
Expand Down Expand Up @@ -490,11 +490,11 @@ p5.prototype.noCanvas = function() {
* @param {HTMLCanvasElement} [canvas]
* @return {p5.Graphics}
*/
p5.prototype.createGraphics = function(w, h, ...args) {
/**
* args[0] is expected to be renderer
* args[1] is expected to be canvas
*/
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;
Expand Down Expand Up @@ -639,7 +639,7 @@ p5.prototype.createGraphics = function(w, h, ...args) {
* </code>
* </div>
*/
p5.prototype.createFramebuffer = function(options) {
p5.prototype.createFramebuffer = function (options) {
return new p5.Framebuffer(this, options);
};

Expand Down Expand Up @@ -723,7 +723,7 @@ p5.prototype.createFramebuffer = function(options) {
* </code>
* </div>
*/
p5.prototype.clearDepth = function(depth) {
p5.prototype.clearDepth = function (depth) {
this._assert3d('clearDepth');
this._renderer.clearDepth(depth);
};
Expand Down Expand Up @@ -1192,7 +1192,7 @@ p5.prototype.clearDepth = function(depth) {
* </code>
* </div>
*/
p5.prototype.blendMode = function(mode) {
p5.prototype.blendMode = function (mode) {
p5._validateParameters('blendMode', arguments);
if (mode === constants.NORMAL) {
// Warning added 3/26/19, can be deleted in future (1.0 release?)
Expand Down
46 changes: 23 additions & 23 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ p5.prototype._wrapElement = function (elt) {
const children = Array.prototype.slice.call(elt.children);
if (elt.tagName === 'INPUT' && elt.type === 'checkbox') {
let converted = new p5.Element(elt, this);
converted.checked = function(...args) {
converted.checked = function (...args) {
if (args.length === 0) {
return this.elt.checked;
} else if (args[0]) {
Expand Down Expand Up @@ -1020,7 +1020,7 @@ p5.prototype.createButton = function (label, value) {
*
* @method createCheckbox
* @param {String} [label] label displayed after the checkbox.
* @param {boolean} [value] value of the checkbox. Checked is `true` and unchecked is `false`.
* @param {Boolean} [value] value of the checkbox. Checked is `true` and unchecked is `false`.
* @return {p5.Element} new <a href="#/p5.Element">p5.Element</a> object.
*
* @example
Expand Down Expand Up @@ -1101,7 +1101,7 @@ p5.prototype.createButton = function (label, value) {
* </code>
* </div>
*/
p5.prototype.createCheckbox = function(...args) {
p5.prototype.createCheckbox = function (...args) {
p5._validateParameters('createCheckbox', args);

// Create a container element
Expand All @@ -1121,7 +1121,7 @@ p5.prototype.createCheckbox = function(...args) {
//checkbox must be wrapped in p5.Element before label so that label appears after
const self = addElement(elt, this);

self.checked = function(...args) {
self.checked = function (...args) {
const cb = self.elt.firstElementChild.getElementsByTagName('input')[0];
if (cb) {
if (args.length === 0) {
Expand Down Expand Up @@ -1178,7 +1178,7 @@ p5.prototype.createCheckbox = function(...args) {
* - `mySelect.enable(option)` marks a given option as enabled.
*
* @method createSelect
* @param {boolean} [multiple] support multiple selections.
* @param {Boolean} [multiple] support multiple selections.
* @return {p5.Element} new <a href="#/p5.Element">p5.Element</a> object.
*
* @example
Expand Down Expand Up @@ -1328,7 +1328,7 @@ p5.prototype.createCheckbox = function(...args) {
* @return {p5.Element}
*/

p5.prototype.createSelect = function(...args) {
p5.prototype.createSelect = function (...args) {
p5._validateParameters('createSelect', args);
let self;
let arg = args[0];
Expand Down Expand Up @@ -1580,7 +1580,7 @@ p5.prototype.createSelect = function(...args) {
* @method createRadio
* @return {p5.Element} new <a href="#/p5.Element">p5.Element</a> object.
*/
p5.prototype.createRadio = function(...args) {
p5.prototype.createRadio = function (...args) {
// Creates a div, adds each option as an individual input inside it.
// If already given with a containerEl, will search for all input[radio]
// it, create a p5.Element out of it, add options to it and return the p5.Element.
Expand Down Expand Up @@ -2394,7 +2394,7 @@ if (navigator.mediaDevices.getUserMedia === undefined) {
* </code>
* </div>
*/
p5.prototype.createCapture = function(...args) {
p5.prototype.createCapture = function (...args) {
p5._validateParameters('createCapture', args);

// return if getUserMedia is not supported by the browser
Expand Down Expand Up @@ -2436,7 +2436,7 @@ p5.prototype.createCapture = function(...args) {
domElement.src = window.URL.createObjectURL(stream);
}
}
catch(err) {
catch (err) {
domElement.src = stream;
}
}).catch(e => {
Expand Down Expand Up @@ -2467,7 +2467,7 @@ p5.prototype.createCapture = function(...args) {

if (callback) callback(domElement.srcObject);
});
videoEl.flipped=flipped;
videoEl.flipped = flipped;
return videoEl;
};

Expand Down Expand Up @@ -2944,10 +2944,10 @@ p5.Element.prototype.center = function (align) {
/**
* @method html
* @param {String} [html] the HTML to be placed inside the element
* @param {boolean} [append] whether to append HTML to existing
* @param {Boolean} [append] whether to append HTML to existing
* @chainable
*/
p5.Element.prototype.html = function(...args) {
p5.Element.prototype.html = function (...args) {
if (args.length === 0) {
return this.elt.innerHTML;
} else if (args[1]) {
Expand Down Expand Up @@ -3017,7 +3017,7 @@ p5.Element.prototype.html = function(...args) {
* @param {String} [positionType] it can be static, fixed, relative, sticky, initial or inherit (optional)
* @chainable
*/
p5.Element.prototype.position = function(...args) {
p5.Element.prototype.position = function (...args) {
if (args.length === 0) {
return { x: this.elt.offsetLeft, y: this.elt.offsetTop };
} else {
Expand All @@ -3042,7 +3042,7 @@ p5.Element.prototype.position = function(...args) {
};

/* Helper method called by p5.Element.style() */
p5.Element.prototype._translate = function(...args) {
p5.Element.prototype._translate = function (...args) {
this.elt.style.position = 'absolute';
// save out initial non-translate transform styling
let transform = '';
Expand Down Expand Up @@ -3074,7 +3074,7 @@ p5.Element.prototype._translate = function(...args) {
};

/* Helper method called by p5.Element.style() */
p5.Element.prototype._rotate = function(...args) {
p5.Element.prototype._rotate = function (...args) {
// save out initial non-rotate transform styling
let transform = '';
if (this.elt.style.transform) {
Expand Down Expand Up @@ -3461,7 +3461,7 @@ p5.Element.prototype.removeAttribute = function (attr) {
* @param {String|Number} value
* @chainable
*/
p5.Element.prototype.value = function(...args) {
p5.Element.prototype.value = function (...args) {
if (args.length > 0) {
this.elt.value = args[0];
return this;
Expand Down Expand Up @@ -4004,10 +4004,10 @@ p5.Element.prototype.draggable = function (elmMove) {
closeDragElementEvt = isTouch ? 'touchend' : 'mouseup',
elementDragEvt = isTouch ? 'touchmove' : 'mousemove';

if(elmMove === undefined){
if (elmMove === undefined) {
elmMove = this.elt;
elmDrag = elmMove;
}else if(elmMove !== this.elt && elmMove.elt !== this.elt){
} else if (elmMove !== this.elt && elmMove.elt !== this.elt) {
elmMove = elmMove.elt;
elmDrag = this.elt;
}
Expand All @@ -4018,11 +4018,11 @@ p5.Element.prototype.draggable = function (elmMove) {
function dragMouseDown(e) {
e = e || window.event;

if(isTouch){
if (isTouch) {
const touches = e.changedTouches;
px = parseInt(touches[0].clientX);
py = parseInt(touches[0].clientY);
}else{
} else {
px = parseInt(e.clientX);
py = parseInt(e.clientY);
}
Expand All @@ -4035,13 +4035,13 @@ p5.Element.prototype.draggable = function (elmMove) {
function elementDrag(e) {
e = e || window.event;

if(isTouch){
if (isTouch) {
const touches = e.changedTouches;
x = px - parseInt(touches[0].clientX);
y = py - parseInt(touches[0].clientY);
px = parseInt(touches[0].clientX);
py = parseInt(touches[0].clientY);
}else{
} else {
x = px - parseInt(e.clientX);
y = py - parseInt(e.clientY);
px = parseInt(e.clientX);
Expand Down Expand Up @@ -4950,7 +4950,7 @@ p5.MediaElement = class MediaElement extends p5.Element {
* set this value to false after uploading the texture; or might set
* it to true if metadata has become available but there is no actual
* texture data available yet..
* @param {boolean} val sets whether or not the element has been
* @param {Boolean} val sets whether or not the element has been
* modified.
* @private
*/
Expand Down
16 changes: 8 additions & 8 deletions src/events/acceleration.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ p5.prototype.pAccelerationZ = 0;
*
* @private
*/
p5.prototype._updatePAccelerations = function() {
p5.prototype._updatePAccelerations = function () {
this._setProperty('pAccelerationX', this.accelerationX);
this._setProperty('pAccelerationY', this.accelerationY);
this._setProperty('pAccelerationZ', this.accelerationZ);
Expand Down Expand Up @@ -369,7 +369,7 @@ p5.prototype.pRotateDirectionX = undefined;
p5.prototype.pRotateDirectionY = undefined;
p5.prototype.pRotateDirectionZ = undefined;

p5.prototype._updatePRotations = function() {
p5.prototype._updatePRotations = function () {
this._setProperty('pRotationX', this.rotationX);
this._setProperty('pRotationY', this.rotationY);
this._setProperty('pRotationZ', this.rotationZ);
Expand Down Expand Up @@ -419,7 +419,7 @@ let shake_threshold = 30;
* the <a href="#/p5/deviceMoved">deviceMoved()</a> function. The default threshold is set to 0.5.
*
* @method setMoveThreshold
* @param {number} value The threshold value
* @param {Number} value The threshold value
* @example
* <div class="norender">
* <code>
Expand Down Expand Up @@ -451,7 +451,7 @@ let shake_threshold = 30;
* </div>
*/

p5.prototype.setMoveThreshold = function(val) {
p5.prototype.setMoveThreshold = function (val) {
p5._validateParameters('setMoveThreshold', arguments);
move_threshold = val;
};
Expand Down Expand Up @@ -493,7 +493,7 @@ p5.prototype.setMoveThreshold = function(val) {
* </div>
*/

p5.prototype.setShakeThreshold = function(val) {
p5.prototype.setShakeThreshold = function (val) {
p5._validateParameters('setShakeThreshold', arguments);
shake_threshold = val;
};
Expand Down Expand Up @@ -616,7 +616,7 @@ p5.prototype.setShakeThreshold = function(val) {
* </div>
*/

p5.prototype._ondeviceorientation = function(e) {
p5.prototype._ondeviceorientation = function (e) {
this._updatePRotations();

// Convert from degrees into current angle mode
Expand All @@ -625,14 +625,14 @@ p5.prototype._ondeviceorientation = function(e) {
this._setProperty('rotationZ', this._fromDegrees(e.alpha));
this._handleMotion();
};
p5.prototype._ondevicemotion = function(e) {
p5.prototype._ondevicemotion = function (e) {
this._updatePAccelerations();
this._setProperty('accelerationX', e.acceleration.x * 2);
this._setProperty('accelerationY', e.acceleration.y * 2);
this._setProperty('accelerationZ', e.acceleration.z * 2);
this._handleMotion();
};
p5.prototype._handleMotion = function() {
p5.prototype._handleMotion = function () {
if (window.orientation === 90 || window.orientation === -90) {
this._setProperty('deviceOrientation', 'landscape');
} else if (window.orientation === 0) {
Expand Down
Loading
Loading