xxxxxxxxxx
63
// Daniel Shiffman
// https://thecodingtrain.com/CodingChallenges/150-runway-rainbows.html
// https://youtu.be/vEetoBuHj8g
// https://editor.p5js.org/codingtrain/sketches/K6l0JbS6u
// https://youtu.be/ARnf4ilr9Hcc
// https://youtu.be/7btNir5L8Jc
// RunwayML must be running locally for the sketch to function
// You can download at: https://runwayml.com/download/
// ML Lab on website
// https://app.runwayml.com/all-models
// Instructions for runwayML app
// Click on ↕️ next to Sequel in top left corner
// Click on ML Lab to get to the Browse Models interface
// Click View All Models
// Search for StyleGAN in the search bar
// There are now many different StyleGan models to choose from
// The StyleGAN model used in challenge is next to last
// Once the latent space has been populated in the vector on the
// RunwayML app, run this sketch
// If you get a permissions error on Safari, try Chrome
let rainbow;
function setup() {
createCanvas(400, 400);
createButton('rainbow').mousePressed(generateRainbow);
}
function generateRainbow() {
// 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) {
rainbow = createImg(result.image);
rainbow.hide();
}
function draw() {
background(220);
if (rainbow) {
image(rainbow, 0, 0);
}
}