Skip to content

Instantly share code, notes, and snippets.

@Knovour
Last active March 22, 2016 10:02
Show Gist options
  • Save Knovour/57b761d08ff758396ab6 to your computer and use it in GitHub Desktop.
Save Knovour/57b761d08ff758396ab6 to your computer and use it in GitHub Desktop.
'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