-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
356 lines (307 loc) · 17.8 KB
/
Copy pathindex.html
File metadata and controls
356 lines (307 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!DOCTYPE html>
<html lang="en">
<head>
<title>bradi.sh | Regime Shift</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Homepage for bradi.sh - Viral Regime Edition">
<script src="https://d3js.org/d3.v6.min.js"></script>
<style>
body, html { margin: 0; padding: 0; overflow: hidden; width: 100%; height: 100%; background: #17191D; }
#svg { width: 100vw; height: 100vh; }
</style>
</head>
<body>
<div id="svg"></div>
<script type="application/javascript">
const margin = {top: 0, right: 0, bottom: 0, left: 0};
const width = window.innerWidth - margin.left - margin.right;
const height = window.innerHeight - margin.top - margin.bottom;
const TILE_SIZE = 80;
const TILES_PER_ROW = Math.ceil(width / TILE_SIZE) + 2;
const TILES_PER_COLUMN = Math.ceil(height / TILE_SIZE) + 2;
let cameraX = 0;
let cameraY = 0;
let targetCameraX = 0;
let targetCameraY = 0;
// --- AUTO SCROLL & BROWNIAN STATE ---
let lastUserActivity = 0;
const SUSPEND_DURATION = 5000;
let vx = 0;
let vy = 0;
const maxVelocity = 1.5;
const friction = 0.97;
const impulse = 0.1;
// --- REGIME STATE ---
let currentGlobalRegime = 0;
const regimePalettes = {
0: ["#FFF4E0", "#F8B501", "#06ACB5", "#17191D", "#FC3D3C"]
};
const PAINT_LOCATIONS = {
TOP_LEFT_CORNER: 0, TOP_RIGHT_CORNER: 1, BOTTOM_RIGHT_CORNER: 2,
BOTTOM_LEFT_CORNER: 3, CENTER: 4, BASE: 5, TEXT: 6
};
const N_PAINT_LOCATIONS = Object.keys(PAINT_LOCATIONS).length;
const CORNERS = [0, 1, 2, 3];
const CHANCE = { ofHavingACenter: 0.75, ofOffCorners: 0.1 };
// Helper to generate new palettes
const generatePalette = () => {
const rotation = (Math.random() * 360 | 0)
const rotateHue = (hex, degree) => {
// 1. Convert hex to RGB
let r = parseInt(hex.slice(1, 3), 16) / 255;
let g = parseInt(hex.slice(3, 5), 16) / 255;
let b = parseInt(hex.slice(5, 7), 16) / 255;
// 2. Find HSL values
let max = Math.max(r, g, b), min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;
if (max === min) {
h = s = 0; // achromatic
} else {
let d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
// 3. Rotate Hue
h = (h * 360 + degree) % 360;
if (h < 0) h += 360; // Handle negative rotations
h /= 360;
// 4. Convert HSL back to RGB
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
};
let q = l < 0.5 ? l * (1 + s) : l + s - l * s;
let p = 2 * l - q;
r = Math.round(hue2rgb(p, q, h + 1/3) * 255);
g = Math.round(hue2rgb(p, q, h) * 255);
b = Math.round(hue2rgb(p, q, h - 1/3) * 255);
// 5. Back to Hex
const toHex = val => val.toString(16).padStart(2, '0');
return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
};
return regimePalettes[0].map(c=>rotateHue(c,rotation))
};
class Tile {
constructor(ix, iy) {
this._regime = 0;
this._rotation = 0; // Initialize rotation explicitly
this.init(ix, iy);
}
// Helper to get the D3 selection for this specific tile's group
get selection() {
return d3.select(`.t-${this.index}`);
}
init(ix, iy) {
this._ix = ix;
this._iy = iy;
this._cx = this._cy = TILE_SIZE / 2;
this._index = (this.iy % TILES_PER_COLUMN + TILES_PER_COLUMN) % TILES_PER_COLUMN * TILES_PER_ROW + (this.ix % TILES_PER_ROW + TILES_PER_ROW) % TILES_PER_ROW;
// Initial state without transitions
this._rotation = [-180, -90, 0, 90, 180][Math.random() * 5 | 0];
this.recircle(true, false);
this.recolour(this._regime, false);
}
recircle(noOffCorners = false, animate = true) {
this._centerCircleRadius = Math.random() < CHANCE.ofHavingACenter ? TILE_SIZE / 2 * Math.SQRT2 * (Math.random() * 0.1 + 0.15) : 0;
this._cornerCircleRadius = TILE_SIZE / 2;
this._corners = Math.random() > 0.5 ? [1, 0, 1, 0] : [0, 1, 0, 1];
if (!noOffCorners) this._corners = this._corners.map(corner => Math.random() < CHANCE.ofOffCorners ? 1 - corner : corner);
if (animate) {
const s = this.selection;
s.select("circle").transition().duration(800).attr("r", this._centerCircleRadius);
s.selectAll("path").filter((d, i) => i < 4)
.transition().duration(800)
.attr("d", (d, i) => this.corners[i]);
}
}
recolour(regime = 0, animate = true) {
this._regime = regime;
const palette = regimePalettes[regime] || regimePalettes[0];
this._colours = Array(N_PAINT_LOCATIONS).fill(0).map(_ => palette[Math.random() * palette.length | 0]);
if (animate) {
const s = this.selection;
const dur = 800;
s.select("rect").transition().duration(dur).attr("fill", this._colours[PAINT_LOCATIONS.BASE]);
s.select("circle").transition().duration(dur).attr("fill", this._colours[PAINT_LOCATIONS.CENTER]);
s.selectAll("path").filter((d, i) => i < 4)
.transition().duration(dur)
.attr("fill", (d, i) => this._colours[i]);
}
}
rerotate(animate = true) {
this._rotation = [-180, -90, 0, 90, 180][Math.random() * 5 | 0]
if (animate) {
// Target the nested rotation group specifically
this.selection.select(".tileRotation")
.transition()
.duration(500)
.attr("transform", `rotate(${this._rotation})`);
}
}
get ix() { return this._ix; }
get iy() { return this._iy; }
get x() { return this._ix * TILE_SIZE - cameraX; }
get y() { return this._iy * TILE_SIZE - cameraY; }
get cx() { return this._cx; }
get cy() { return this._cy; }
get index() { return this._index; }
get cornerCircleRadius() { return this._cornerCircleRadius; }
get centerCircleRadius() { return this._centerCircleRadius; }
get colours() { return this._colours; }
get rotation() { return this._rotation; }
get corners() {
return [
(r => `M${r},0A${r},${r},0,0,1,0,${r}L0,0Z`)(this._corners[0] * this.cornerCircleRadius),
(r => `M${TILE_SIZE},${r}A${r},${r},0,0,1,${TILE_SIZE - r},0L${TILE_SIZE},0Z`)(this._corners[1] * this.cornerCircleRadius),
(r => `M${TILE_SIZE - r},${TILE_SIZE}A${r},${r},0,0,1,${TILE_SIZE},${TILE_SIZE - r}L${TILE_SIZE},${TILE_SIZE}Z`)(this._corners[2] * this.cornerCircleRadius),
(r => `M0,${TILE_SIZE - r}A${r},${r},0,0,1,${r},${TILE_SIZE}L0,${TILE_SIZE}Z`)(this._corners[3] * this.cornerCircleRadius)
];
}
get arcs() {
return [
(r => `M${r},0A${r},${r},0,0,1,0,${r}`)(this._corners[0] * this.cornerCircleRadius),
(r => `M${TILE_SIZE},${r}A${r},${r},0,0,1,${TILE_SIZE - r},0`)(this._corners[1] * this.cornerCircleRadius),
(r => `M${TILE_SIZE - r},${TILE_SIZE}A${r},${r},0,0,1,${TILE_SIZE},${TILE_SIZE - r}`)(this._corners[2] * this.cornerCircleRadius),
(r => `M0,${TILE_SIZE - r}A${r},${r},0,0,1,${r},${TILE_SIZE}`)(this._corners[3] * this.cornerCircleRadius)
];
}
}
const tiles = [];
for (let y = -1; y < TILES_PER_COLUMN - 1; y++) {
for (let x = -1; x < TILES_PER_ROW - 1; x++) {
tiles.push(new Tile(x, y));
}
}
const svg = d3.selectAll("#svg").append("svg")
.attr("viewBox", [0, 0, width, height])
.style("width", "100%").style("height", "100%").style("display", "block");
// Interaction Handlers
const markActivity = () => { lastUserActivity = Date.now(); };
window.addEventListener('wheel', e => {
e.preventDefault(); markActivity();
targetCameraX += e.deltaX; targetCameraY += e.deltaY;
}, { passive: false });
let touchStartX = 0, touchStartY = 0;
window.addEventListener('touchstart', e => {
markActivity(); touchStartX = e.touches[0].clientX; touchStartY = e.touches[0].clientY;
});
window.addEventListener('touchmove', e => {
e.preventDefault(); markActivity();
const dx = e.touches[0].clientX - touchStartX;
const dy = e.touches[0].clientY - touchStartY;
targetCameraX -= dx; targetCameraY -= dy;
touchStartX = e.touches[0].clientX; touchStartY = e.touches[0].clientY;
}, { passive: false });
// Rendering Tiles
const theTiles = svg.append("g").attr("id", "theTiles");
const tileTranslations = theTiles.selectAll(".tileTranslations")
.data(tiles, d => d.index).enter().append("g")
.attr("transform", d => `translate(${d.x},${d.y})`)
.attr("class", d => `tileTranslations t-${d.index}`);
const tileOffsets = tileTranslations.append("g").attr("transform", `translate(${TILE_SIZE / 2},${TILE_SIZE / 2})`).attr("class","tileTranslation");
const tileRotations = tileOffsets.append("g").attr("transform", d => `rotate(${d.rotation})`).attr("class","tileRotation");
const tileGroups = tileRotations.append("g").attr("transform", `translate(${TILE_SIZE / -2},${TILE_SIZE / -2})`).attr("class","tileGroup");;
const bases = tileGroups.append("rect").attr("width", TILE_SIZE).attr("height", TILE_SIZE).attr("fill", d => d.colours[PAINT_LOCATIONS.BASE]);
const corners = CORNERS.map(c => tileGroups.append("path").attr("d", d => d.corners[c]).attr("fill", d => d.colours[c]));
const arcs = CORNERS.map(a => tileGroups.append("path").attr("d", d => d.arcs[a]).attr("fill", "none").attr("stroke", "rgba(255,255,255,0.3)"));
const centers = tileGroups.append("circle").attr("r", d => d.centerCircleRadius).attr("cx", d => d.cx).attr("cy", d => d.cy).attr("fill", d => d.colours[PAINT_LOCATIONS.CENTER]);
// Big Overlay Text
const textLabels = ["bradi.sh", "bradi.sh"];
textLabels.forEach((t, i) => {
svg.append("text")
.attr("x", width / 2).attr("y", height / 2)
.attr("text-anchor", "middle").attr("dominant-baseline", "central")
.attr("font-family", "sans-serif").attr("font-weight", "900").attr("font-size", "20vw")
.style("pointer-events", "none").text(t)
.style("fill", i === 0 ? "none" : "#fff")
.style("stroke", i === 0 ? "black" : "none")
.style("filter", i === 0 ? "blur(5px)" : "none")
.style("mix-blend-mode", i === 0 ? "hard-light" : "difference");
});
const updateVisuals = (tile) => {
const group = d3.select(`.t-${tile.index}`);
group.select("rect").transition().duration(800).attr("fill", tile.colours[PAINT_LOCATIONS.BASE]);
group.select("circle").transition().duration(800).attr("fill", tile.colours[PAINT_LOCATIONS.CENTER]);
group.selectAll("path").filter((d, i) => i < 4).transition().duration(800).attr("fill", (d, i) => tile.colours[i]);
};
const redraw = () => {
const now = Date.now();
if (now - lastUserActivity > SUSPEND_DURATION) {
vx += (Math.random() - 0.5) * impulse;
vy += (Math.random() - 0.5) * impulse;
vx *= friction; vy *= friction;
vx = Math.max(-maxVelocity, Math.min(maxVelocity, vx));
vy = Math.max(-maxVelocity, Math.min(maxVelocity, vy));
targetCameraX += vx; targetCameraY += vy;
} else {
vx = 0; vy = 0;
}
cameraX += (targetCameraX - cameraX) * 0.1;
cameraY += (targetCameraY - cameraY) * 0.1;
const buffer = TILE_SIZE;
tiles.forEach(tile => {
let dirty = false;
if (tile.ix * TILE_SIZE - cameraX < -buffer * 2) { tile.init(tile.ix + TILES_PER_ROW, tile.iy); dirty = true; }
else if (tile.ix * TILE_SIZE - cameraX > width + buffer) { tile.init(tile.ix - TILES_PER_ROW, tile.iy); dirty = true; }
if (tile.iy * TILE_SIZE - cameraY < -buffer * 2) { tile.init(tile.ix, tile.iy + TILES_PER_COLUMN); dirty = true; }
else if (tile.iy * TILE_SIZE - cameraY > height + buffer) { tile.init(tile.ix, tile.iy - TILES_PER_COLUMN); dirty = true; }
if (dirty) {
const g = d3.select(`.t-${tile.index}`);
g.attr("transform", `translate(${tile.x},${tile.y})`);
g.select("rect").attr("fill", tile.colours[PAINT_LOCATIONS.BASE]);
g.select("circle").attr("r", tile.centerCircleRadius).attr("fill", tile.colours[PAINT_LOCATIONS.CENTER]);
g.selectAll("path").filter((d, i) => i < 4).attr("d", (d, i) => tile.corners[i]).attr("fill", (d, i) => tile.colours[i]);
}
});
tileTranslations.attr("transform", d => `translate(${d.x},${d.y})`);
};
const animate = () => { redraw(); requestAnimationFrame(animate); };
animate();
// --- FEATURE 1 & 2: REGIME SPONTANEITY (10s) ---
setInterval(() => {
currentGlobalRegime++;
regimePalettes[currentGlobalRegime] = generatePalette();
// Pick a visible-ish tile to be "Patient Zero"
const visibleTiles = tiles.filter(t => t.x > 0 && t.x < width && t.y > 0 && t.y < height);
const target = visibleTiles.length > 0 ? visibleTiles[Math.floor(Math.random()*visibleTiles.length)] : tiles[0];
target.recolour(currentGlobalRegime);
updateVisuals(target);
}, 10000);
// --- FEATURE 4: NEIGHBOR CHECK (1s) ---
setInterval(() => {
const updates = [];
tiles.forEach(tile => {
// Find cardinal neighbors
const neighbors = tiles.filter(t =>
(Math.abs(t.ix - tile.ix) === 1 && t.iy === tile.iy) ||
(Math.abs(t.iy - tile.iy) === 1 && t.ix === tile.ix)
);
const highestNeighborRegime = Math.max(...neighbors.map(n => n._regime));
if (highestNeighborRegime > tile._regime && Math.random() > 0.5) {
updates.push({tile, regime: highestNeighborRegime});
}
});
// Apply updates after check to prevent synchronous chain reactions in one tick
updates.forEach(u => {
u.tile.recolour(u.regime);
u.tile.rerotate();
updateVisuals(u.tile);
});
}, 500);
// Random Tile Pulse (Rotation only now to separate from regime change)
setInterval(() => {
const tile = tiles[Math.floor(Math.random() * tiles.length)];
tile.rerotate()
}, 500);
</script>
</body>
</html>