xxxxxxxxxx
342
let pt;
let version;
let monochrome = false;
let step;
let paused = false;
let gfx;
let colors, bg, bc;
let o;
function keyPressed() {
if (key === " ") paused = !paused;
if (key === "r") {
translate(0, 0);
image(gfx, -width / 2, -height / 2);
}
}
function setup() {
createCanvas(1000, 1000);
o = width * 0.01;
let versions = [1,2,3,4,5,6,7,8];
version = random(versions);
pixelDensity(1);
gfx = createGraphics(width, height);
// https://www.colourlovers.com/palette/9362/Powerpuff_Girls!
// colors = [
// color("#000000"),
// color("#00D0FF"),
// color("#F91D8B"),
// color("#81F400"),
// ];
// chromotome : system#08
colors = [
color(255),
color(246,98,91),
color(146,178,159),
color(39,44,63),
];
bg = colors.splice(Math.floor(Math.random() * colors.length), 1)[0];
// monochrome v. colored
if (monochrome) gfx.background(random(20, 220));
else gfx.background(bg);
dither(gfx);
image(gfx, 0, 0);
angleMode(RADIANS);
step = random([512, 1024, 2048,4096]);
// random([16, 32, 64, 128, 256,
let pt_col = color(0, 0, 0, 200);
if (!monochrome) {
pt_col = random(colors);
pt_col._array[3] = 200 / 255;
}
bc = pt_col;//random(colors);
pt = {
theta: 0,
r: 1,
color: pt_col,
step: TWO_PI / step,
size: 1,
countStep: 0,
};
frameRate(60);
}
function draw() {
if (!paused) {
drawShadow(4, null);
translate(width / 2, height / 2);
let x;
let y;
fill(pt.color);
if (version < 7) {
if (pt.countStep == 0) {
x = pt.r * cos(pt.theta);
y = pt.r * sin(pt.theta);
noStroke();
circle(x, y, pt.size);
} else {
for (let i = 0; i < 10; i++) {
let _c = color(pt.color);
_c._array[3] = map(i, 0, 10, 1.0, 0.0);
fill(_c);
x = pt.r * cos(pt.theta);
y = pt.r * sin(pt.theta) + i;
noStroke();
circle(x, y, pt.size);
}
}
} else {
// iris thing - 7
strokeWeight(0.5);
stroke(pt.color);
x = pt.r * cos(pt.theta);
y = pt.r * sin(pt.theta);
for (let i = 0; i < random(10, 100); i++) {
x += random(-3, 3);
y += random(-3, 3);
noStroke();
circle(x, y, pt.size);
}
//circle(x,y,pt.size);
}
if (version > 1) pt.theta += pt.size;
else {
pt.theta += pt.size + random(PI);
pt.r += random(-5, 5);
}
// update points
switch (version) {
case 1:
case 2:
if (random() > 0.9) {
let lt = 0;
if (pt.r > 100) lt = -25;
pt.r += random(lt, 25);
}
if (random() > 0.9) {
pt.size += random(-2, 2);
pt.size = constrain(pt.size, 1, 10);
}
if (monochrome) {
if (random() > 0.9) pt.color = color(random(0, 50));
if (random() > 0.9) pt.color = color(0);
} else {
if (random() > 0.9) pt.color = random(colors);
// if (random() > 0.9) pt.color = color(0);
}
if (pt.r > width) pt.r = 1;
if (pt.r < 1) pt.r = width / 2;
break;
case 3:
pt.size = 15;
if (frameCount % 10 == 0) {
pt.r += random(0.5, 3);
}
if (pt.r > width / 2) pt.r = random(1, width / 2);
break;
case 4:
// if (frameCount % 10 == 0) {
{
pt.r += random(0.5, 3);
stroke(pt.color);
strokeWeight(0.5);
let x2 = pt.r * cos(pt.theta);
let y2 = pt.r * sin(pt.theta);
line(x, y, x2, y2);
}
if (pt.r > width / 2) pt.r = random(1, width / 2);
break;
case 5:
let _r = random(1, width / 2);
let _theta = random(0, TWO_PI);
pt.r = _r;
pt.theta = _theta;
stroke(pt.color);
strokeWeight(0.5);
let x2 = pt.r * cos(pt.theta);
let y2 = pt.r * sin(pt.theta);
line(x, y, x2, y2);
break;
case 6:
pt.r += 50;
if (pt.r > width / 2) {
pt.countStep = 1;
pt.r = 1;
}
break;
case 7:
if (frameCount % 100 == 0) {
pt.r += 50;
}
if (pt.r > width / 2) {
pt.countStep = 1;
pt.r = 1;
}
break;
case 8:
if (frameCount % 100 == 0) {
pt.r += random(1, 10);
}
if (pt.r > width / 2) {
pt.countStep = 1;
pt.r = 1;
}
break;
default:
console.log("version not defined");
noLoop();
break;
}
push();
fill(bc);
noStroke();
translate(-width / 2, -height / 2);
rect(0, 0, o, height);
rect(o, 0, width, o);
rect(width - o, o, o, height);
rect(o, height - o, width - o, o);
pop();
}
}
function drawShadow(b, g) {
if (g == null) {
drawingContext.shadowOffsetX = 2;
drawingContext.shadowOffsetY = 2;
drawingContext.shadowBlur = b;
if (bg._array[0] == 0 && bg._array[1] == 0 && bg._array[2] == 0)
drawingContext.shadowColor = color(50);
//"black";
else drawingContext.shadowColor = color(0); //"black";
} else {
if (b == 0) {
g.drawingContext.shadowOffsetX = 0;
g.drawingContext.shadowOffsetY = 0;
g.drawingContext.shadowBlur = 0;
g.drawingContext.shadowColor = color(0); //"black";
} else {
g.drawingContext.shadowOffsetX = 3;
g.drawingContext.shadowOffsetY = 3;
g.drawingContext.shadowBlur = b;
g.drawingContext.shadowColor = color(0); //"black";
}
}
}
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) {
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();
} else {
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();
}
}