xxxxxxxxxx
86
//---------------------- variables ----------------------//
//--- Remember: noise Loops do not use any vector inputs ---//
let truncation_value = 0.7;
let frame_count = 24*3; // fps*seconds
let diameter = 1.0 // diameter and frame_count control how diverse the video is
let height = 1024;
let width = 1024;
let download_images = true;
let random_seed = 1
//--------- you can ignore below this line -------------//
let rainbow;
const a = [];
const n = [];
let angle = 0;
function setup() {
randomSeed(random_seed)
pixelDensity(1);
createCanvas(height, width);
for (let i = 0; i < 512; i++) {
n[i] = new NoiseLoop(diameter, -1, 1);
}
generateRainbow();
}
function generateRainbow() {
// httpPost(path, [datatype], [data], [callback], [errorCallback])
const path = "http://localhost:8000/query";
for (let i = 0; i < 512; i++) {
a[i] = n[i].value(angle); //randomGaussian() / 50.0;
}
let da = TWO_PI / (frame_count);
angle += da;
const data = {
z: a,
truncation: truncation_value
};
httpPost(path, 'json', data, gotImage, gotError);
}
function gotError(error) {
console.error(error);
}
function gotImage(result) {
rainbow = createImg(result.image, imageReady);
rainbow.hide();
}
let count = 0;
function imageReady() {
image(rainbow, 0, 0);
if (download_images) save(`step${nf(count, 4)}`);
count++;
if (angle <= TWO_PI) {
setTimeout(generateRainbow, 100);
}
}
const osn = new OpenSimplexNoise(Date.now());
class NoiseLoop {
constructor(diameter, min, max) {
this.diameter = diameter;
this.min = min;
this.max = max;
this.cx = random(1000);
this.cy = random(1000);
}
value(a) {
let xoff = map(cos(a), -1, 1, this.cx, this.cx + this.diameter);
let yoff = map(sin(a), -1, 1, this.cy, this.cy + this.diameter);
let r = osn.noise2D(xoff, yoff);
return map(r, -1, 1, this.min, this.max);
}
}