Last active
January 29, 2021 09:10
-
-
Save GoToLoop/6125a5806872f7d4d93d11870b607851 to your computer and use it in GitHub Desktop.
Get p5js Version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
height: 200 | |
scrolling: no | |
border: no | |
license: cc-by-4.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get p5js Version (v1.1.1) | |
* GoToLoop (2020-Jul-31) | |
* | |
* https://Discourse.Processing.org/t/detect-p5-1-1-9-vs-1-0-0/22920/2 | |
* https://Bl.ocks.org/GoSubRoutine/6125a5806872f7d4d93d11870b607851 | |
*/ | |
'use strict'; | |
p5.prototype._version = p5.prototype._release = null; | |
p5.prototype.getVersion = function () { | |
const p5jsURL = /p5$|p5@|p5(?:\.min)?\.[mc]?[jt]s/, | |
p5jsVER = /p5(?:\.min)?\.js v(\d+)\.(\d+)\.(\d+) (\w+) (\d+), (\d+)/, | |
p5jsERR = URIError('No p5js script found within document!'), | |
p5jsNOT = Error('p5js file had no version comment header!'), | |
FUNCT = 'function', DOT = '.', SPC = ' '; | |
return function (success, fail) { | |
const { scripts } = document, | |
{ length: len } = scripts, | |
semver = new Uint8Array(3), | |
isSuccessAFunct = typeof success == FUNCT, | |
isFailAFunct = typeof fail == FUNCT; | |
for (var i = 0; i < len; ++i) if (p5jsURL.test(scripts[i].src)) break; | |
if (i == len) isFailAFunct && fail(p5jsERR); | |
else this.loadStrings( | |
scripts[i].src, | |
([ comment ]) => { | |
const matches = p5jsVER.exec(comment); | |
if (!matches) return isFailAFunct && fail(p5jsNOT); | |
for (i = 0; i < 3; semver[i++] = matches[i]); | |
p5.prototype._version = this._version = semver.join(DOT); | |
p5.prototype._release = this._release = matches.slice(4).join(SPC); | |
isSuccessAFunct && success(matches); | |
}, | |
err => isFailAFunct && fail(err) | |
); | |
return semver; | |
}; | |
}(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://cdn.JsDelivr.net/npm/p5></script> | |
<!-- <script defer src=https://Unpkg.com/p5></script> --> | |
<!-- <script defer src=https://cdn.JsDelivr.net/npm/[email protected]></script> --> | |
<!-- <script defer src=https://Unpkg.com/[email protected]></script> --> | |
<!-- <script defer src=https://cdn.JsDelivr.net/npm/[email protected]></script> --> | |
<!-- <script defer src=https://Unpkg.com/[email protected]></script> --> | |
<!-- <script defer src=https://cdn.JsDelivr.net/npm/[email protected]></script> --> | |
<!-- <script defer src=https://Unpkg.com/[email protected]></script> --> | |
<!-- <script defer src=https://cdn.JsDelivr.net/npm/[email protected]/lib/p5.js></script> --> | |
<!-- <script defer src=https://Unpkg.com/[email protected]/lib/p5.min.js></script> --> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://Unpkg.com/p5></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get p5js Version (v1.1.1) | |
* GoToLoop (2020-Jul-31) | |
* | |
* https://Discourse.Processing.org/t/detect-p5-1-1-9-vs-1-0-0/22920/2 | |
* https://Bl.ocks.org/GoSubRoutine/6125a5806872f7d4d93d11870b607851 | |
*/ | |
'use strict'; | |
var version; | |
function preload() { | |
version = getVersion(console.log, console.error); | |
} | |
function setup() { | |
createCanvas(500, 200).mousePressed(redraw); | |
noLoop(); | |
colorMode(HSB, 360, 1, 1); | |
textSize(50); | |
textAlign(CENTER, CENTER); | |
console.info(version); | |
} | |
function draw() { | |
background(~~random(360), 1, 1); | |
const info = p5.prototype._version + '\n' + p5.prototype._release; | |
text(info, width >> 1, height >> 1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://Unpkg.com/[email protected]></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://Unpkg.com/[email protected]/lib/p5.min.js></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://cdn.JsDelivr.net/npm/[email protected]/lib/p5.js></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://Unpkg.com/[email protected]></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://cdn.JsDelivr.net/npm/[email protected]></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://Unpkg.com/[email protected]></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://cdn.JsDelivr.net/npm/[email protected]></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src=https://cdn.JsDelivr.net/npm/[email protected]></script> | |
<script defer src=get_p5js_version.js></script> | |
<script defer src=sketch.js></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment