xxxxxxxxxx
113
let colors, spacing, stk, bg, h1, w1, points, sx, sy;
function setup() {
createCanvas(windowWidth, windowHeight);
gencolors(32);
spacing = min(width, height) / 15;
cx = width / 2;
cy = height / 2;
genFrame();
bg = random(colors);
stk = random(colors)
a = 0;
}
function draw() {
if(bg == stk){
stk = random(colors)
}
background(bg);
stroke(stk);
a += PI/200
r1 = sqrt(sq(h1*spacing/4)+sq(w1*spacing/4))
sx = cx + r1*cos(a)
sy = cy + r1*sin(a)
noFill();
rectMode(CENTER);
rect(width / 2, height / 2, w1 * spacing, h1 * spacing);
fill(stk);
strokeWeight(spacing/20)
strokeWeight(spacing / 10);
for (let i = 0; i < points.length; i++) {
points[i].scale();
points[i].display();
}
sign();
}
function mousePressed() {
if (mouseButton != RIGHT) {
bg = random(colors);
stk = random(colors);
genFrame();
}
}
function genFrame() {
h1 = int(random(4, min(height / spacing - 1, width / spacing - 3)));
w1 = int(random(h1 + 2, width / spacing - 1));
genPoints(
cx - w1 / 2 + spacing,
cy - h1 / 2 + spacing,
cx + w1 / 2 - spacing,
cy + h1 / 2 - spacing
);
}
function genPoints(minX, minY, maxX, maxY) {
points = [];
for (let i = 1; i < h1; i++) {
for (let j = 1; j < w1; j++) {
let c = new Point(j, i);
points.push(c);
}
}
}
class Point {
constructor(xStep, yStep) {
this.xStep = xStep;
this.yStep = yStep;
this.x = xStep * spacing + (cx - (w1 * spacing) / 2);
this.y = yStep * spacing + (cy - (h1 * spacing) / 2);
this.r = 0;
}
scale() {
let d = dist(this.x, this.y, sx,sy);
this.r = min(0.75*spacing,max(1, (d / spacing) * 4));
}
display() {
circle(this.x, this.y, this.r);
}
}
function lineSDL(x, y, d, l) {
line(x, y, x + l * cos(d), y + l * sin(d));
}
function sign() {
push();
let t = "jesse toohey";
textSize(spacing / 2);
textAlign(RIGHT, BOTTOM);
noStroke();
fill(stk);
text(t, width - spacing / 4, height - spacing / 4);
pop();
}
function gencolors(n) {
colors = [];
colorMode(HSL);
for (var i = 0; i < n; i++) {
var newColor = color(random(360), random(80), random(30, 80));
colors.push(newColor);
}
colorMode(RGB);
}