xxxxxxxxxx
101
let grid, particles;
function setup() {
createCanvas(1000, 1000);
// createCanvas(2000, 2000);
noiseDetail(16, 0.05);
background(20);
let wscale = width / 1000;
pixelDensity(1);
strokeWeight(wscale);
grid = [];
particles = [];
for (let _ = 0; _ < 5000; _++) {
particles.push({
x: int(random(width - 1)),
y: int(random(height - 1)),
col: int(random(180, 255)),
t: random(["flow", "automata"]),
});
}
for (let y = 0; y < height; y++) {
grid[y] = [];
for (let x = 0; x < width; x++) {
let n = noise(x * 0.01, y * 0.01);
let mapped = map(n, 0.0, 1.0, -TWO_PI, TWO_PI) * (PI / 8);
let rule = random([0, 1]);
grid[y][x] = {
noise: n,
mapped_noise: mapped,
mapped_two: Math.ceil(
(map(n, 0.0, 1.0, 0.0, TWO_PI) * (PI / 4)) / (PI / 4)
),
automata_rule: rule,
special: false
};
}
}
for (let _ = 0; _ < 10; _++)
random(particles).special = true;
off = width * 0.2;
}
let off;
function draw() {
for (let p of particles) {
let _col = p.col;
if (p.t == "automata") _col = 255 - _col;
let _x = p.x + random(-20,20);
let _y = p.y + random(-20,20);
if (_x > off && _x < width - off && _y > off && _y < height - off) {
if (_col < 120) _col = color(128, 0, 128, 128);
if (_col > 120) _col = color(0, 128, 128, 128); //255,255,255,100);
}
if (p.special) {
// strokeWeight(5);
_col = color(255,0,0);
} //else strokeWeight(1);
stroke(_col);
point(p.x, p.y);
if (p.t == "flow") {
let a = grid[int(p.y)][int(p.x)].mapped_noise;
p.x += cos(a);
p.y += sin(a);
} else {
let a = grid[int(p.y)][int(p.x)].mapped_two;
p.x += cos(a);
p.y += sin(a);
// let b = grid[int(p.y)][int(p.x)].automata_rule;
// let a = 0;
// let c = 0;
// if (p.x > 0) a = grid[int(p.y)][int(p.x - 1)].automata_rule;
// if (p.x < width - 1) c = grid[int(p.y)][int(p.x + 1)].automata_rule;
// let next = rules(a, b, c);
// p.x += next.x;
// p.y += next.y;
}
if (p.x < 0 || p.x > width - 1 || p.y < 0 || p.y > height - 1) {
p.x = int(random(width - 1));
p.y = int(random(height - 1));
p.t = random(["flow", "automata"]);
}
if (random() > 0.98) p.t = random(["flow", "automata"]);
}
}
let ruleset = [0, 1, 0, 1, 1, 0, 1, 0];
function rules(a, b, c) {
if (a == 1 && b == 1 && c == 1) return { x: -1, y: 0 }; //ruleset[0];
if (a == 1 && b == 1 && c == 0) return { x: 1, y: 0 }; //ruleset[1];
if (a == 1 && b == 0 && c == 1) return { x: -1, y: 1 }; //ruleset[2];
if (a == 1 && b == 0 && c == 0) return { x: 0, y: 1 }; //ruleset[3];
if (a == 0 && b == 1 && c == 1) return { x: 1, y: 1 }; //ruleset[4];
if (a == 0 && b == 1 && c == 0) return { x: -1, y: 1 }; //ruleset[5];
if (a == 0 && b == 0 && c == 1) return { x: 0, y: 1 }; //ruleset[6];
if (a == 0 && b == 0 && c == 0) return { x: 1, y: 1 }; //ruleset[7];
return 0;
}