Last active
October 10, 2020 07:09
-
-
Save GoSubRoutine/823e9f8b008b7481b11d5f4f12a80839 to your computer and use it in GitHub Desktop.
LoadTable State
This file contains 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: 310 | |
scrolling: no | |
border: no | |
license: cc-by-4.0 |
This file contains 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
<!DOCTYPE html> | |
<meta charset=utf-8> | |
<script async src=https://cdn.JsDelivr.net/npm/p5></script> | |
<script defer src=sketch.js></script> |
This file contains 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
/** | |
* LoadTable State (v1.1.0) | |
* GoToLoop (2020-Oct-09) | |
* | |
* Discourse.Processing.org/t/loadtable-how-to-handle-missing-file-error/24476/3 | |
* Bl.ocks.org/GoSubRoutine/823e9f8b008b7481b11d5f4f12a80839 | |
*/ | |
'use strict'; | |
const | |
CORRECT_NAME = 'xy.csv', WRONG_NAME = 'ab.csv', | |
STYLE = 'color: yellow; background: blue; font-size: 1.2em;', | |
DELAY = 120, | |
[ NO_LOAD, BEGIN_LOAD, WAIT_LOAD, SUCCESS_LOAD, FAIL_LOAD ] = | |
Uint8Array.from({ length: 5 }, (_, idx) => idx); | |
var table, loadState = NO_LOAD; | |
function setup() { | |
createCanvas(400, 300); | |
strokeWeight(3).background(0); | |
console.clear(); | |
loadState = BEGIN_LOAD; | |
} | |
function draw() { | |
frameCount % DELAY || background('#' + hex(~~random(0x1000), 3)); | |
if (loadState == BEGIN_LOAD) startLoad(WRONG_NAME); | |
else if (loadState == FAIL_LOAD) startLoad(CORRECT_NAME); | |
fill(loadState == SUCCESS_LOAD && 'cyan' || 'fuchsia'); | |
circle(width >> 1, height >> 1, width >> 1); | |
} | |
function startLoad(filename, head = 'header', type = 'csv', style = STYLE) { | |
console.info('%cLoading: ' + filename, style); | |
table = loadTable(filename, type, head, successLoad, failLoad); | |
loadState = WAIT_LOAD; | |
} | |
function successLoad(file) { | |
console.table(file.getArray()); | |
print(table); | |
loadState = SUCCESS_LOAD; | |
} | |
function failLoad(err) { | |
console.log(err); | |
loadState = FAIL_LOAD; | |
} |
This file contains 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
x | y | |
---|---|---|
337 | 333 | |
337 | 342 | |
333 | 390 | |
332 | 391 | |
328 | 406 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment