xxxxxxxxxx
62
let truncation_value = 0.5;
let inp;
let seed;
function setup() {
// create canvas
pixelDensity(1);
createCanvas(1024, 1024);
inp = createInput('');
inp.input(gotText);
noStroke();
}
function draw() {
inp.position(10,10);
}
function gotText() {
seed = 0;
if(this.value()!=""){
let text = this.value()
for(let t = 0; t < text.length; t++){
// print(text[t].charCodeAt())
seed+=int(text[t].charCodeAt())
}
// print(seed)
randomSeed(seed);
getImageFromRunway()
}
}
function getImageFromRunway() {
z = createZ(512)
const path = "http://localhost:8000/query";
const data = {
z: z,
truncation: truncation_value
};
httpPost(path, 'json', data, gotImage, gotError);
}
function gotError(error) {
console.error(error);
}
function gotImage(result) {
i = createImg(result.image, imageReady);
i.hide();
}
function imageReady() {
image(i, 0, 0,1024,1024);
}
function createZ(v) {
let z =[];
for(let zi = 0; zi < v; zi++){
z.push(random(-1, 1))
}
return z;
}