xxxxxxxxxx
38
let kid;
function setup() {
createCanvas(600, 600);
createButton('kid').mousePressed(generateKid);
}
function generateKid() {
// httpPost(path, [datatype], [data], [callback], [errorCallback])
const z = [];
for (let i = 0; i < 512; i++) {
z[i] = random(-1, 1);
}
const path = "http://localhost:8000/query";
const data = {
z: z,
truncation: 0.8
};
httpPost(path, 'json', data, gotImage, gotError);
}
function gotError(error) {
console.error(error);
}
function gotImage(result) {
kid = createImg(result.image);
kid.hide();
}
function draw() {
background(220);
if (kid) {
image(kid, 0, 0);
}
}