xxxxxxxxxx
58
/*
* @name Noise3D
* @frame 710,400 (optional)
* @description Using 3D noise to create simple animated texture.
*/
let noiseVal;
//Increment x by 0.01
let x_increment = 0.03;
//Increment z by 0.02 every draw() cycle
let z_increment = 0.02;
//Offset values
let z_off, y_off, x_off;
let osnoise;
function setup() {
//Create the Canvas
createCanvas(360, 360);
pixelDensity(1);
//Initial value of z_off
z_off = 0;
osnoise = new OpenSimplexNoise();
}
function draw() {
x_off = 0;
y_off = 0;
//Make the background black
background(0);
//Adjust the noice detail
//noiseDetail(8, 0.65);
//For each x,y calculate noice value
loadPixels();
for (let y = 0; y < height; y++) {
x_off += x_increment;
y_off = 0;
for (let x = 0; x < width; x++) {
//Calculate and Draw each pixel
//noiseVal = random(255);
//noiseVal = noise(x_off, y_off) * 255;
noiseVal = osnoise.noise3D(x_off, y_off, z_off)* 127 + 127;
y_off += x_increment;
let index = (x + y * width) * 4;
pixels[index+0] = noiseVal;
pixels[index+1] = noiseVal;
pixels[index+2] = noiseVal;
pixels[index+3] = 255;
}
}
updatePixels();
z_off += z_increment;
}