Skip to content

Instantly share code, notes, and snippets.

@GoSubRoutine
Last active October 10, 2020 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoSubRoutine/823e9f8b008b7481b11d5f4f12a80839 to your computer and use it in GitHub Desktop.
Save GoSubRoutine/823e9f8b008b7481b11d5f4f12a80839 to your computer and use it in GitHub Desktop.
LoadTable State
height: 310
scrolling: no
border: no
license: cc-by-4.0
<!DOCTYPE html>
<meta charset=utf-8>
<script async src=https://cdn.JsDelivr.net/npm/p5></script>
<script defer src=sketch.js></script>
/**
* 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;
}
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