Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict'
const file = {
load(cb) {
let tmp = [];
d3.tsv("data.tsv", (err, list) => {
const length = list.length;
// you CANNOT overwrite tmp with another object, it must be updated with the data.
for(let i = 0; i < length; i++)
tmp[i] = list[i];
cb(tmp);
});
return tmp;
}
}
p5.prototype.registerPreloadMethod('load', file);
let data;
function preload() {
data = file.load();
}
function setup() {
console.log(data);
}
function draw() {
}
'use strict'
new p5(ctx => {
const file = {
load(cb) {
let tmp = [];
d3.tsv("data.tsv", (err, list) => {
const length = list.length;
// you CANNOT overwrite tmp with another object, it must be updated with the data.
for(let i = 0; i < length; i++)
tmp[i] = list[i];
cb(tmp);
});
return tmp;
}
}
ctx.__proto__.registerPreloadMethod('load', file);
let data;
ctx.preload = () => {
data = file.load();
}
ctx.setup = () => {
console.log(data);
}
ctx.draw = () => {
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.