xxxxxxxxxx
134
let noiseGen;
let grid;
let offset;
let z;
let dir = true;
let paused = false;
let img; // Photo by <a href="https://unsplash.com/@pgreen1983?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Paul Green</a> on <a href="https://unsplash.com/images/feelings/happy?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
function keyPressed() {
if (key === " ") paused = !paused;
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
function preload() {
img = loadImage("paul-green-5lRxNLHfZOY-unsplash.smol.jpg");
}
function setup() {
randomSeed(1);
z = 0;
offset = random(5000);
// createCanvas(400, 400);
createCanvas(1000, 1000);
pixelDensity(1);
grid = new Array(height);
for (let i = 0; i < grid.length; i++) grid[i] = new Array(width);
noiseGen = new FastSimplexNoise({ frequency: 0.001, octaves: 4 });
background(255);
image(img, 0, 0);
loadPixels();
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
grid[x][y] = noiseGen.get3DNoise(x + offset, y + offset, z + offset);
let r = random(255); //0;
let g = random(255); //0;
let b = random(255); //0;
let a = 255;
// if (grid[x][y] < 0.0) {
// a = 0;//map(grid[x][y], -1.0, 0.0, 255, 0);
// } else {
// r = 0;
// g = 0;
// b = map(grid[x][y], 0.0, 1.0, 255, 0);
// }
if (grid[x][y] > 0.0) {
let d = 1; // pixelDensity();
// loop over
index = 4 * (y * d * width * d + x * d);
pixels[index] = r;
pixels[index + 1] = g;
pixels[index + 2] = b;
pixels[index + 3] = a;
}
}
}
updatePixels();
}
function draw() {
if (!paused) {
loadPixels();
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
// // grid[x][y] = noiseGen.get3DNoise(x + offset, y + offset, z + offset);
// let r = 0;
// let g = 0;
// let b = 0;
// let a = 255;
// if (grid[x][y] < 0.0) {
// a = map(grid[x][y], -1.0, 0.0, 255, 0);
// } else {
// r = 0;
// g = 0;
// b = map(grid[x][y], 0.0, 1.0, 255, 0);
// }
let d = 1; // pixelDensity();
// for (let i = 0; i < d; i++) {
// for (let j = 0; j < d; j++) {
// loop over
index = 4 * (y * d * width * d + x * d);
// pixels[index] = r;
// pixels[index + 1] = g;
// pixels[index + 2] = b;
if (grid[x][y] > 0.0) {
let a = pixels[index + 3];
// if (getRandomInt(0,1000) > 900)
// a = pixels[index + getRandomInt(0,4)];
if (!dir) {
a--;
if (a < 0) {
a = 0;
dir = !dir;
}
} else {
a++;
if (a > 255) {
a = 255;
dir = !dir;
}
}
pixels[index + 3] = a;
}
// }
// }
// // let col;
// // if (grid[x][y] < 0.0) {
// // col = color(0,0,0,map(grid[x][y], -1.0, 0.0, 255,0));
// // } else {
// // col = color(255, 0, 255, 255);
// // }
}
}
updatePixels();
z++;
}
}