xxxxxxxxxx
let angle = 0;
function setup() {
createCanvas(400, 400, WEBGL);
textureMode(NORMAL);
}
function draw() {
background(0);
for (let i = 0; i < width; i += 10) {
stroke(random(255), random(255), random(255));
let x1 = 200 - i;
let y1 = 200 - random(height);
let x2 = 200 - ((i + random(10)));
let y2 = 200 - random(height);
line(x1, y1, x2, y2);
}
rotateY(angle);
fill(255, 255, 255, 0);
strokeWeight(2);
stroke(255);
// box(100);
//generate noise patterns for each surface of the cube
let noiseVal1 = noise(frameCount * 0.01, 0, 0);
let noiseVal2 = noise(0, frameCount * 0.01, 0);
let noiseVal3 = noise(0, 0, frameCount * 0.01);
let noiseVal4 = noise(frameCount * 0.01, frameCount * 0.01, 0);
let noiseVal5 = noise(frameCount * 0.01, 0, frameCount * 0.01);
let noiseVal6 = noise(0, frameCount * 0.01, frameCount * 0.01);
//set the fill color based on the noise values
fill(255 * noiseVal1, 255 * noiseVal2, 255 * noiseVal3, 100);
box(140);
angle += 0.01;
}
function createNoiseTexture(size) {
let img = createImage(size, size);
img.loadPixels();
for (let x = 0; x < img.width; x++) {
for (let y = 0;y < img.height; y++) {
let index = (x + y * img.width) * 4;
let noiseVal = noise(x, y);
img.pixels[index] = noiseVal * 255;
img.pixels[index + 1] = noiseVal * 255;
img.pixels[index + 2] = noiseVal * 255;
img.pixels[index + 3] = 255;
}
}
img.updatePixels();
return img;
}