xxxxxxxxxx
228
p5.disableFriendlyErrors = true;
let m = [];
let w = 10;
let h = 10;
let dim = 94;
let rotationAlpha = 0;
let rotationIter;
function setup() {
cnvs = createCanvas(w * dim, h * dim);
rotationIter = TWO_PI / 60;
frameRate(30);
background(255);
for (let i = 0; i < w; i++) {
m[i] = [];
for (let j = 0; j < h; j++) {
let n = int(random(2, 52));
let ln = true;
let bl = !ln;
let p = {sc: random(0.3, 0.5),
n1: n, n2: n, td: 1,
v1: 0, v2: random(-20, 47),
b1: 0, b2: random(0, 10),
l1: 0, l2: random(0, 30),
c1: 0, c2: random(0, 40),
t1: 2, t2: random(0, 10),
core: false, circ: false,
blob: bl,
line: ln,
tipx: (random() < 0.5)};
m[i][j] = new Mutation(i * dim, j * dim, dim,
p.sc, p.n1, p.n2, p.td,
p.v1, p.v2, p.b1, p.b2,
p.l1, p.l2, p.c1, p.c2,
p.t1, p.t2, p.core, p.circ,
p.blob, p.line, p.tipx);
}
}
// createLoop({ duration: 2, gif: true });
noLoop();
}
function draw() {
background(255);
for (let i = 0; i < w; i++) {
for (let j = 0; j < h; j++) {
m[i][j].update();
}
}
rotationAlpha += rotationIter;
}
class Mutation {
constructor(x, y, dim, sc, n1, n2, td, v1, v2, b1, b2, l1, l2,
c1, c2, t1, t2, core, circ, blob, line, tipx) {
this.dim = dim;
this.width = dim;
this.height = dim;
this.rttAlpha = random(0, TWO_PI);
this.amp = random(0.01, 1);
this.core = core;
this.circ = circ;
this.blob = blob;
this.line = line;
this.tipInside = tipx;
this.pos = {
"x": x,
"y": y
}
this.rayMax = int(n2 + 2);
this.seeds = [];
this.rays = [];
this.rtt = 0;
this.circleSize = new NoiseSeed(dim*sc, dim*0.5, 0.03);
this.coreSize = new NoiseSeed(c1, c2, 0.06)
this.rayCount = new NoiseSeed(n1, n2, 0.01);
this.tipDistr = new NoiseSeed(1, td);
this.strokeW = new NoiseSeed(2, 4, 0.05);
this.strokeW2 = new NoiseSeed(1, 1, 0.05);
this.seeds = [this.circleSize, this.coreSize, this.rayCount, this.tipDistr, this.strokeW, this.strokeW2];
for (let r = 0; r < this.rayMax; r++) {
let ray = {
"valley": new NoiseSeed(v1, v2, random(0.05, 0.1)),
"begin": new NoiseSeed(b1, b2, random(0.001, 0.07)),
"length": new NoiseSeed(l1, l2, random(0.001, 0.07)),
"tip": new NoiseSeed(t1, t2, random(0.001, 0.07))
}
this.seeds.push(ray.valley, ray.begin, ray.length, ray.tip);
this.rays.push(ray);
}
}
update() {
this.seeds.forEach(function(s) {
s.update();
});
this.rtt += 0.01;
let cr = this.circleSize.value() / 2;
let rc = this.rayCount.intValue();
push();
translate(this.pos.x + this.width/2, this.pos.y + this.height/2);
noFill();
stroke(0);
strokeWeight(this.strokeW2.value());
if (this.core === true) {
circle(0, 0, this.coreSize.value());
} else if (this.circ === true) {
circle(0, 0, cr * 2);
}
push();
// rotate(this.rtt);
let rotAngle = sin(rotationAlpha + this.rttAlpha) * this.amp;
rotate(rotAngle);
strokeWeight(this.strokeW2.value());
// Rays and Tips
for (let i = 0; i < rc; i++) {
let r1 = cr - this.rays[i].begin.value();
let r2 = cr + this.rays[i].length.value();
let alpha = i * (TWO_PI / rc);
alpha += this.rttAlpha;
let x1 = r1 * Math.cos(alpha);
let y1 = r1 * Math.sin(alpha);
let x2 = r2 * Math.cos(alpha);
let y2 = r2 * Math.sin(alpha);
if (this.line) {
line(x1, y1, x2, y2);
}
let circX = x2, circY = y2;
if (this.tipInside) {
circX = x1;
circY = y1;
}
if (i % this.tipDistr.intValue() === 0) {
// circle(circX, circY,this.rays[i].tip.value());
}
}
// Bezier Star
if (this.blob) {
curveTightness(0);
beginShape();
let angle = TWO_PI / rc;
let index = 0;
for (let a = 0; a <= TWO_PI + angle; a += angle) {
let alpha = a + this.rttAlpha;
let r1 = cr - this.rays[index].valley.value();
let r2 = cr; // + this.rays[index].length.value();
let vrtxOut = {
"x": Math.cos(alpha) * r2,
"y": Math.sin(alpha) * r2
}, vrtxIn = {
"x": Math.cos(alpha + angle/2.0) * r1,
"y": Math.sin(alpha + angle/2.0) * r1
};
index++;
// if (a != 0) curveVertex(vrtxOut.x, vrtxOut.y);
// curveVertex(vrtxIn.x, vrtxIn.y);
}
endShape();
}
pop();
pop();
}
}
class NoiseSeed {
constructor(min, max, speed = 0.01) {
this.min = min;
this.max = max;
this.speed = speed;
this.seed = random(0, 1000);
}
update() {
if (frameCount === 31) {
this.speed = -this.speed;
}
this.seed += this.speed;
}
value() {
return map(noise(this.seed), 0, 1, this.min, this.max);
}
intValue() {
return int(this.value());
}
}
function keyPressed() {
if (keyCode === DOWN_ARROW) {
let f = "corona_" + frameCount;
saveCanvas(cnvs, f, 'png');
}
}