xxxxxxxxxx
239
let grid;
let numcells;
let cellsize;
let o;
let colors;
let borderColor;
function setup() {
createCanvas(800, 800);
numcells = 25;
cellsize = width / numcells;
angleMode(RADIANS);
let miradors = [
color("#020202"),
color("#ff6936"),
color("#fddc3f"),
color("#0075ca"),
color("#03bb70"),
];
let powerpuff = [
color("#201010"),
color("#5dece1"),
color("#ea50c4"),
color("#47e752"),
color("#130d0d"),
];
let butterfly = [
color("#191e36"),
color("#f40104"),
color("#f6c0b3"),
color("#99673a"),
color("#f0f1f4"),
];
let cc239 = [
color("#e0eff0"),
color("#e3dd34"),
color("#78496b"),
color("#f0527f"),
color("#a7e0e2"),
];
let matrix_palette = [
color("#020204"),
color("#204829"),
color("#22b455"),
color("#80ce87"),
color("#92e5a1"),
];
let monochrome_palette = [
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
color(random(0, 255)),
];
colors = random([
miradors,
powerpuff,
butterfly,
cc239,
matrix_palette,
monochrome_palette,
]);
borderColor = random(colors);
// colors = powerpuff;
// size
grid = [];
for (let r = 0; r < numcells; r++) {
grid[r] = [];
for (let c = 0; c < numcells; c++) {
let start = random(0, PI);
let stop = random(PI, TWO_PI);
grid[r][c] = {
col: random(colors),// color(random(255), random(255), random(255)),
width: random(0.5, 3.0),
start: start,
stop: stop,
step: TWO_PI / random(32, 256), //64,//random(256),
filled: random([true,false]),
direction: random(["positive", "negative", "whacky"]),
size: cellsize/2,// random([cellsize, cellsize*2, cellsize/2]),
};
}
}
o = width * random([0.01,0.05]);
noFill();
stroke(0);
}
function draw() {
background(220);
for (let r = 0; r < numcells; r++) {
for (let c = 0; c < numcells; c++) {
push();
let g = grid[r][c];
stroke(g.width);
if (g.filled) fill(g.col);
else noFill();
let x = c * cellsize + cellsize / 2;
let y = r * cellsize + cellsize / 2;
translate(x, y);
arc(0, 0, g.size, g.size, g.start, g.stop, PIE);
if (random() > 0.99) {
for (let i = 0; i < random(2,10); i++) {
arc(i, i, g.size, g.size, g.start, g.stop, PIE);
}
}
if (g.direction == "positive") {
g.start += g.step;
g.stop += g.step;
} else if (g.direction == "negative") {
g.start -= g.step;
g.stop -= g.step;
} else {
g.start -= g.step;
g.stop += g.step;
}
pop();
}
}
dither(null);
noStroke();
fill(color(0,0,0,180));
rect(0,0,o,height);
rect(o,0,width-2*o,o);
rect(o,height-o,width-2*o,o);
rect(width-o,0,o,height);
let _c = borderColor;
_c.setAlpha(190);
fill(_c);
rect(o,o,width-2*o,o);
rect(o,2*o,o,height-3*o);
rect(o*2,height-2*o,width-4*o,o);
rect(width-2*o,2*o,o,height-3*o);
if (random() > 0.9) borderColor = random(colors);
}
function index(g, x, y) {
if (g == null)
return (x + y * width) * 4;
else
return (x + y * g.width) * 4;
}
function dither(g) {
if (g == null) {
loadPixels();
for (let y = 0; y < height - 1; y++) {
for (let x = 1; x < width - 1; x++) {
let oldr = pixels[index(g, x, y)];
let oldg = pixels[index(g, x, y) + 1];
let oldb = pixels[index(g, x, y) + 2];
let factor = 1.0;
let newr = round((factor * oldr) / 255) * (255 / factor);
let newg = round((factor * oldg) / 255) * (255 / factor);
let newb = round((factor * oldb) / 255) * (255 / factor);
pixels[index(g, x, y)] = newr;
pixels[index(g, x, y) + 1] = newg;
pixels[index(g, x, y) + 2] = newb;
pixels[index(g, x + 1, y)] += ((oldr - newr) * 7) / 16.0;
pixels[index(g, x + 1, y) + 1] += ((oldr - newr) * 7) / 16.0;
pixels[index(g, x + 1, y) + 2] += ((oldr - newr) * 7) / 16.0;
pixels[index(g, x - 1, y + 1)] += ((oldr - newr) * 3) / 16.0;
pixels[index(g, x - 1, y + 1) + 1] += ((oldr - newr) * 3) / 16.0;
pixels[index(g, x - 1, y + 1) + 2] += ((oldr - newr) * 3) / 16.0;
pixels[index(g, x, y + 1)] += ((oldr - newr) * 5) / 16.0;
pixels[index(g, x, y + 1) + 1] += ((oldr - newr) * 5) / 16.0;
pixels[index(g, x, y + 1) + 2] += ((oldr - newr) * 5) / 16.0;
pixels[index(g, x + 1, y + 1)] += ((oldr - newr) * 1) / 16.0;
pixels[index(g, x + 1, y + 1) + 1] += ((oldr - newr) * 1) / 16.0;
pixels[index(g, x + 1, y + 1) + 2] += ((oldr - newr) * 1) / 16.0;
}
}
updatePixels();
} else {
g.loadPixels();
for (let y = 0; y < height - 1; y++) {
for (let x = 1; x < width - 1; x++) {
let oldr = g.pixels[index(g, x, y)];
let oldg = g.pixels[index(g, x, y) + 1];
let oldb = g.pixels[index(g, x, y) + 2];
let factor = 1.0;
let newr = round((factor * oldr) / 255) * (255 / factor);
let newg = round((factor * oldg) / 255) * (255 / factor);
let newb = round((factor * oldb) / 255) * (255 / factor);
g.pixels[index(g, x, y)] = newr;
g.pixels[index(g, x, y) + 1] = newg;
g.pixels[index(g, x, y) + 2] = newb;
g.pixels[index(g, x + 1, y)] += ((oldr - newr) * 7) / 16.0;
g.pixels[index(g, x + 1, y) + 1] += ((oldr - newr) * 7) / 16.0;
g.pixels[index(g, x + 1, y) + 2] += ((oldr - newr) * 7) / 16.0;
g.pixels[index(g, x - 1, y + 1)] += ((oldr - newr) * 3) / 16.0;
g.pixels[index(g, x - 1, y + 1) + 1] += ((oldr - newr) * 3) / 16.0;
g.pixels[index(g, x - 1, y + 1) + 2] += ((oldr - newr) * 3) / 16.0;
g.pixels[index(g, x, y + 1)] += ((oldr - newr) * 5) / 16.0;
g.pixels[index(g, x, y + 1) + 1] += ((oldr - newr) * 5) / 16.0;
g.pixels[index(g, x, y + 1) + 2] += ((oldr - newr) * 5) / 16.0;
g.pixels[index(g, x + 1, y + 1)] += ((oldr - newr) * 1) / 16.0;
g.pixels[index(g, x + 1, y + 1) + 1] += ((oldr - newr) * 1) / 16.0;
g.pixels[index(g, x + 1, y + 1) + 2] += ((oldr - newr) * 1) / 16.0;
}
}
g.updatePixels();
}
}