xxxxxxxxxx
353
let grid;
let offset;
let cellsize;
let cellsR, cellsC;
let zOff = 0;
let nOff = 0.1;
let accentColor;
let blockDepth = 5;
let font;
const Y_AXIS = 1;
const X_AXIS = 2;
function preload() {
font = loadFont("m5x7.ttf");
}
function setup() {
// createCanvas(1600, 800);
createCanvas(3000,3000);//(2500, 3300);//800,1600);
pixelDensity(1);
// createCanvas(1000,1000);
let rs = int(random(0,50000));
let ns = int(random(0,50000));
randomSeed(rs);
noiseSeed(ns);
console.log(`Random seed [${rs}] // Noise seed [${ns}]`);
// accentColor = random(["#800080", "#00FF00"]);
accentColor = "#0065a4";// "#660000";
cellsize = 20;
cellsR = int(height / cellsize);
cellsC = int(width / cellsize);
offset = 5;
grid = [];
textFont(font);
let threshold = 1.0 / 8.0;
for (let r = 0; r < cellsR; r++) {
grid[r] = [];
for (let c = 0; c < cellsC; c++) {
if (
r < offset ||
c < offset ||
r >= cellsR - offset ||
c >= cellsC - offset
) {
grid[r][c] = null;
} else {
let n = noise(c * nOff, r * nOff, zOff * nOff);
let t;
if (n < 1 / 8) t = "up";
else if (n < 2 / 8) t = "upright";
else if (n < 3 / 8) t = "right";
else if (n < 4 / 8) t = "downright";
else if (n < 5 / 8) t = "down";
else if (n < 6 / 8) t = "downleft";
else if (n < 7 / 8) t = "left";
else t = "upleft";
grid[r][c] = t;
}
}
}
// drawingContext.shadowOffsetX = 0;
// drawingContext.shadowOffsetY = 0;
// drawingContext.shadowBlur = 50;
// drawingContext.shadowColor = color("#800080");//)'black';
}
let frameCtr = 0;
function draw() {
let purps = [];
let bg_c;
if (frameCtr < 10) bg_c = map(frameCtr,0,10,221,20);
else bg_c = map(frameCtr,10,20,20,222);
background(bg_c);
frameCtr+=0.01;
if (frameCtr > 20) frameCtr = 0;
// let baccentColor = "#800080";
// if (accentColor == "#800080")
let baccentColor = "#330000";
setGradient(0,0,width,height,color("#0057B8"),color("#FFD700"),Y_AXIS);
// setGradient(0,0,width,height,color(220),color(baccentColor),Y_AXIS);
fill(40);
noStroke();
rectMode(CENTER);
let cs = cellsize / 2;
textAlign(CENTER,CENTER);
textSize(cellsize+10);
let txt = " GVSU ";// "FUCK PUTIN ";
let txtCtr = 0;
for (let r = 0; r < cellsR; r++) {
for (let c = 0; c < cellsC; c++) {
noStroke();
if (grid[r][c] != null) {
for (let d = blockDepth-1; d >= 1; d--) {
fill(map(d,blockDepth-1,1,0,20));
square(c * cellsize + cs-d, r * cellsize + cs-d, cellsize - 2);
}
// fill(0);
// square(c * cellsize + cs-5, r * cellsize + cs-5, cellsize - 2);
// fill(50);
// square(c * cellsize + cs-4, r * cellsize + cs-4, cellsize - 2);
// fill(100);
// square(c * cellsize + cs-3, r * cellsize + cs-3, cellsize - 2);
// fill(150);
// square(c * cellsize + cs-2, r * cellsize + cs-2, cellsize - 2);
// fill(200);
// square(c * cellsize + cs-1, r * cellsize + cs-1, cellsize - 2);
let t = grid[r][c];
if (t == "up") fill(20);
else if (t == "upright") fill(40);
else if (t == "right") {
fill(color(accentColor));
purps.push({r:r,c:c});
//fill (80)
} else if (t == "downright") fill(120);
else if (t == "down") fill(180);
else if (t == "downleft") fill(200);
else if (t == "left") fill(220);
else fill(240);
square(c * cellsize + cs, r * cellsize + cs, cellsize - 2);
// fill(0)
push();
drawShadow(2,null);
if (txtCtr % 2 == 0) fill(color("#0057B8"));
else fill(color("#FFFFFF"));//#FFD700"))
text(txt[txtCtr],c*cellsize+cs,r*cellsize+cs-4);
txtCtr++;
if (txtCtr > txt.length-1) txtCtr = 0;
drawShadow(0,null);
pop();
}
}
}
// textSize(1024);
// fill(0,0,0,120)
// // stroke(255)
// textAlign(CENTER,CENTER);
// text("💚", width/2, height/2);
for (let p of purps) {
// let pcol = color("#800080");
// pcol.setAlpha(90);
let col1 = color(accentColor);
let col2 = color("#FF00FF");
let r = p.r+1;
let c = p.c;
let s = cellsize;
let l = random(10,50);
for (let i = 0; i < l; i++) {
let pcol = lerpColor(col1,col2,map(i,0,l,0.0,1.0))
pcol.setAlpha(map(i,0,l,30,1));
fill(pcol);
square(c*cellsize+cellsize/2,r*cellsize+cellsize/2,map(i,0,l,cellsize,cellsize/8));
r++;
if (random() > 0.8) c += random([-1,1])
if (r*cellsize > height) break;
}
}
// if (frameCount % 10 == 0) {
// for (let r = 0; r < cellsR; r++) {
// for (let c = 0; c < cellsC; c++) {
// if (
// r < offset ||
// c < offset ||
// r >= cellsR - offset ||
// c >= cellsC - offset
// ) {
// continue;
// } else {
// let n = noise(c * nOff, r * nOff, zOff * nOff);
// let t;
// if (n < 1 / 8) t = "up";
// else if (n < 2 / 8) t = "upright";
// else if (n < 3 / 8) t = "right";
// else if (n < 4 / 8) t = "downright";
// else if (n < 5 / 8) t = "down";
// else if (n < 6 / 8) t = "downleft";
// else if (n < 7 / 8) t = "left";
// else t = "upleft";
// grid[r][c] = t;
// }
// }
// }
// zOff++;
// }
dither(null);
noLoop();
}
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();
}
}
function setGradient(x, y, w, h, c1, c2, axis) {
noFill();
if (axis === Y_AXIS) {
// Top to bottom gradient
for (let i = y; i <= y + h; i++) {
let inter = map(i, y, y + h, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(x, i, x + w, i);
}
} else if (axis === X_AXIS) {
// Left to right gradient
for (let i = x; i <= x + w; i++) {
let inter = map(i, x, x + w, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(i, y, i, y + h);
}
}
}
function drawShadow(b, g) {
if (g == null) {
if (b == 0) {
drawingContext.shadowOffsetX = 0;
drawingContext.shadowOffsetY = 0;
drawingContext.shadowBlur = 0;
drawingContext.shadowColor = color(0); //"black";
} else {
let off = -3;
let off2 = -3;
let col = 0;
drawingContext.shadowOffsetX = off;
drawingContext.shadowOffsetY = off;
drawingContext.shadowBlur = b;
drawingContext.shadowColor = color(col); //"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";
}
}
}