586 lines
18 KiB
HTML
586 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>awesome johnruina site</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@600;800;900&display=swap" rel="stylesheet">
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
min-height: 100vh;
|
|
background: #0f0f0f;
|
|
font-family: 'Inter', sans-serif;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.layout {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100vh;
|
|
width: 100vw;
|
|
gap: 1.5rem;
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.canvas-wrap {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex: 1;
|
|
min-width: 0;
|
|
align-self: stretch;
|
|
}
|
|
|
|
.canvas-wrap canvas {
|
|
max-width: 100%;
|
|
max-height: 100%;
|
|
aspect-ratio: 1;
|
|
border-radius: 12px;
|
|
box-shadow: 0 0 60px rgba(74,74,138,0.15);
|
|
cursor: crosshair;
|
|
}
|
|
|
|
.top-bar {
|
|
position: fixed;
|
|
top: 0; left: 0; right: 0;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 1rem 1.5rem;
|
|
z-index: 10;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.top-bar > * { pointer-events: auto; }
|
|
|
|
.back-btn {
|
|
text-decoration: none;
|
|
color: #888;
|
|
font-family: 'Inter', sans-serif;
|
|
font-size: 0.75rem;
|
|
font-weight: 700;
|
|
letter-spacing: 0.5px;
|
|
text-transform: uppercase;
|
|
transition: color 0.2s;
|
|
background: rgba(15,15,15,0.7);
|
|
padding: 0.4rem 0.8rem;
|
|
border-radius: 6px;
|
|
border: 1px solid #333;
|
|
}
|
|
|
|
.back-btn:hover { color: #fff; border-color: #555; }
|
|
|
|
.settings {
|
|
width: 200px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.85rem;
|
|
padding: 1.2rem;
|
|
background: rgba(20,20,35,0.85);
|
|
border: 1px solid #2a2a4a;
|
|
border-radius: 12px;
|
|
max-height: 90vh;
|
|
overflow-y: auto;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.settings::-webkit-scrollbar { width: 4px; }
|
|
.settings::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }
|
|
|
|
.settings-title {
|
|
color: #aaa;
|
|
font-weight: 800;
|
|
font-size: 0.65rem;
|
|
letter-spacing: 1.5px;
|
|
text-transform: uppercase;
|
|
border-bottom: 1px solid #2a2a4a;
|
|
padding-bottom: 0.6rem;
|
|
}
|
|
|
|
.s-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.25rem;
|
|
}
|
|
|
|
.s-group label {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
color: #888;
|
|
font-size: 0.6rem;
|
|
font-weight: 600;
|
|
letter-spacing: 0.5px;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
.s-group label span { color: #bbb; font-weight: 800; }
|
|
|
|
.s-group input[type="range"] {
|
|
-webkit-appearance: none;
|
|
appearance: none;
|
|
width: 100%;
|
|
height: 3px;
|
|
background: #2a2a4a;
|
|
border-radius: 2px;
|
|
outline: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.s-group input[type="range"]::-webkit-slider-thumb {
|
|
-webkit-appearance: none;
|
|
appearance: none;
|
|
width: 12px;
|
|
height: 12px;
|
|
background: #4a4a8a;
|
|
border-radius: 50%;
|
|
cursor: pointer;
|
|
transition: background 0.2s;
|
|
}
|
|
|
|
.s-group input[type="range"]::-webkit-slider-thumb:hover { background: #6a6aaa; }
|
|
.s-group input[type="range"]::-moz-range-thumb {
|
|
width: 12px; height: 12px;
|
|
background: #4a4a8a;
|
|
border-radius: 50%;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.subtitle {
|
|
color: #888;
|
|
font-size: 0.6rem;
|
|
font-weight: 600;
|
|
letter-spacing: 0.5px;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
.palette-row {
|
|
display: flex;
|
|
gap: 4px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.palette-swatch {
|
|
width: 28px; height: 20px;
|
|
border-radius: 4px;
|
|
border: 2px solid transparent;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.palette-swatch:hover { border-color: #666; transform: scale(1.1); }
|
|
.palette-swatch.active { border-color: #4a4a8a; box-shadow: 0 0 8px rgba(74,74,138,0.4); }
|
|
|
|
.s-btn {
|
|
padding: 0.5rem 0;
|
|
background: transparent;
|
|
color: #666;
|
|
border: 1px solid #333;
|
|
border-radius: 6px;
|
|
font-family: 'Inter', sans-serif;
|
|
font-weight: 700;
|
|
font-size: 0.6rem;
|
|
cursor: pointer;
|
|
transition: all 0.25s;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
text-align: center;
|
|
}
|
|
|
|
.s-btn:hover { color: #ccc; border-color: #555; background: rgba(255,255,255,0.03); }
|
|
|
|
@media (max-width: 800px) {
|
|
.layout { flex-direction: column; padding: 0.75rem; padding-top: 3rem; gap: 0.75rem; }
|
|
.settings { width: 100%; max-height: 170px; flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 0.4rem; padding: 0.6rem; }
|
|
.settings .settings-title { width: 100%; font-size: 0.55rem; }
|
|
.settings .s-group { flex: 1; min-width: 80px; }
|
|
.settings .s-group label { font-size: 0.5rem; }
|
|
.settings .palette-row { width: 100%; }
|
|
.palette-swatch { width: 24px; height: 16px; }
|
|
.subtitle { font-size: 0.5rem; }
|
|
.s-btn { font-size: 0.5rem; padding: 0.35rem 0; }
|
|
}
|
|
@media (max-width: 480px) {
|
|
.layout { padding: 0.5rem; padding-top: 2.6rem; gap: 0.5rem; }
|
|
.settings { max-height: 130px; padding: 0.4rem; gap: 0.3rem; }
|
|
.settings .s-group { min-width: 60px; }
|
|
.s-group input[type="range"]::-webkit-slider-thumb { width: 16px; height: 16px; }
|
|
.s-group input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="top-bar">
|
|
<a class="back-btn" href="index.html">← Back</a>
|
|
</div>
|
|
|
|
<div class="layout">
|
|
<div class="canvas-wrap">
|
|
<canvas id="waveCanvas"></canvas>
|
|
</div>
|
|
<div class="settings">
|
|
<div class="settings-title">Wave Simulation</div>
|
|
|
|
<div class="s-group">
|
|
<label>Wave Speed <span id="speedVal">0.5</span></label>
|
|
<input type="range" id="speedSlider" min="0.05" max="1.5" step="0.05" value="0.5">
|
|
</div>
|
|
|
|
<div class="s-group">
|
|
<label>Damping <span id="dampVal">0.5%</span></label>
|
|
<input type="range" id="dampSlider" min="0" max="5" step="0.1" value="0.5">
|
|
</div>
|
|
|
|
<div class="s-group">
|
|
<label>Drop Force <span id="forceVal">10</span></label>
|
|
<input type="range" id="forceSlider" min="1" max="40" step="1" value="10">
|
|
</div>
|
|
|
|
<div class="s-group">
|
|
<label>Drop Radius <span id="radiusVal">5</span></label>
|
|
<input type="range" id="radiusSlider" min="1" max="20" step="1" value="5">
|
|
</div>
|
|
|
|
<div class="s-group">
|
|
<label>Speed <span id="timeVal">1.0</span></label>
|
|
<input type="range" id="timeSlider" min="0.1" max="3" step="0.1" value="1">
|
|
</div>
|
|
|
|
<div>
|
|
<div class="subtitle">Palette</div>
|
|
<div class="palette-row" id="paletteRow"></div>
|
|
</div>
|
|
|
|
<button class="s-btn" id="resetBtn">Reset</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// ─── palette ───
|
|
const palettes = [
|
|
{ name: 'ocean', stops: [
|
|
[0,0,10], [5,20,60], [10,60,120], [40,120,180],
|
|
[80,180,200], [160,220,220], [200,240,240]
|
|
]},
|
|
{ name: 'neon', stops: [
|
|
[0,0,0], [10,10,50], [20,40,120], [60,120,200],
|
|
[100,200,220], [200,220,80], [240,140,40], [200,40,80], [100,10,60]
|
|
]},
|
|
{ name: 'fire', stops: [
|
|
[0,0,0], [40,10,0], [100,20,0], [180,60,0],
|
|
[240,140,20], [255,220,80], [255,255,200]
|
|
]},
|
|
{ name: 'psych', stops: [
|
|
[0,0,0], [80,0,80], [200,0,100], [255,100,0],
|
|
[255,255,0], [0,200,100], [0,100,200], [80,0,120]
|
|
]},
|
|
];
|
|
|
|
let currentPalette = 0;
|
|
function buildPalette(name) {
|
|
const p = palettes.find(x => x.name === name) || palettes[0];
|
|
const arr = [];
|
|
const segs = p.stops.length - 1;
|
|
for (let i = 0; i < 256; i++) {
|
|
const t = i / 255;
|
|
const seg = Math.min(segs - 1, Math.floor(t * segs));
|
|
const f = (t * segs) - seg;
|
|
const a = p.stops[seg];
|
|
const b = p.stops[seg + 1];
|
|
arr.push([
|
|
Math.round(a[0] + (b[0] - a[0]) * f),
|
|
Math.round(a[1] + (b[1] - a[1]) * f),
|
|
Math.round(a[2] + (b[2] - a[2]) * f),
|
|
]);
|
|
}
|
|
return arr;
|
|
}
|
|
|
|
let palette = buildPalette('ocean');
|
|
function getPaletteColor(t) {
|
|
const i = Math.max(0, Math.min(255, Math.floor(t * 255)));
|
|
return palette[i];
|
|
}
|
|
function setPalette(name) {
|
|
const idx = palettes.findIndex(x => x.name === name);
|
|
if (idx >= 0) currentPalette = idx;
|
|
palette = buildPalette(name);
|
|
document.querySelectorAll('#paletteRow .palette-swatch').forEach(s => {
|
|
s.classList.toggle('active', s.dataset.name === name);
|
|
});
|
|
}
|
|
|
|
// ─── key state ───
|
|
const keyState = {};
|
|
document.addEventListener('keydown', (e) => { keyState[e.key.toLowerCase()] = true; });
|
|
document.addEventListener('keyup', (e) => { keyState[e.key.toLowerCase()] = false; });
|
|
|
|
// ─── wave sim ───
|
|
const canvas = document.getElementById('waveCanvas');
|
|
const ctx = canvas.getContext('2d');
|
|
const offscreen = document.createElement('canvas');
|
|
const offCtx = offscreen.getContext('2d');
|
|
|
|
const N = 200;
|
|
const S = N + 2;
|
|
const IX = (i, j) => i + j * S;
|
|
|
|
let h = new Float32Array(S * S);
|
|
let hPrev = new Float32Array(S * S);
|
|
let hTmp = new Float32Array(S * S);
|
|
|
|
let waveSpeed = 0.5;
|
|
let damping = 0.005;
|
|
let dropForce = 10;
|
|
let dropRadius = 5;
|
|
let timeScale = 1;
|
|
|
|
let mouseX = -1, mouseY = -1;
|
|
let prevMouseX = -1, prevMouseY = -1;
|
|
let isDown = false;
|
|
let running = true;
|
|
let animId = null;
|
|
let startTime = 0;
|
|
|
|
// ─── slider refs ───
|
|
const speedSlider = document.getElementById('speedSlider');
|
|
const dampSlider = document.getElementById('dampSlider');
|
|
const forceSlider = document.getElementById('forceSlider');
|
|
const radiusSlider = document.getElementById('radiusSlider');
|
|
const timeSlider = document.getElementById('timeSlider');
|
|
const speedVal = document.getElementById('speedVal');
|
|
const dampVal = document.getElementById('dampVal');
|
|
const forceVal = document.getElementById('forceVal');
|
|
const radiusVal = document.getElementById('radiusVal');
|
|
const timeVal = document.getElementById('timeVal');
|
|
|
|
function updateSliders() {
|
|
waveSpeed = parseFloat(speedSlider.value);
|
|
damping = parseFloat(dampSlider.value) * 0.01;
|
|
dropForce = parseFloat(forceSlider.value);
|
|
dropRadius = parseFloat(radiusSlider.value);
|
|
timeScale = parseFloat(timeSlider.value);
|
|
|
|
speedVal.textContent = waveSpeed.toFixed(2);
|
|
dampVal.textContent = (damping * 100).toFixed(1) + '%';
|
|
forceVal.textContent = dropForce.toFixed(0);
|
|
radiusVal.textContent = dropRadius.toFixed(0);
|
|
timeVal.textContent = timeScale.toFixed(1);
|
|
}
|
|
|
|
speedSlider.addEventListener('input', updateSliders);
|
|
dampSlider.addEventListener('input', updateSliders);
|
|
forceSlider.addEventListener('input', updateSliders);
|
|
radiusSlider.addEventListener('input', updateSliders);
|
|
timeSlider.addEventListener('input', updateSliders);
|
|
|
|
// ─── palette swatches ───
|
|
(function buildPaletteSwatches() {
|
|
const row = document.getElementById('paletteRow');
|
|
palettes.forEach((p) => {
|
|
const swatch = document.createElement('div');
|
|
swatch.className = 'palette-swatch' + (p.name === 'ocean' ? ' active' : '');
|
|
const col = buildPalette(p.name);
|
|
const avg = col[Math.floor(col.length * 0.6)];
|
|
swatch.style.background = `rgb(${avg[0]},${avg[1]},${avg[2]})`;
|
|
swatch.title = p.name;
|
|
swatch.dataset.name = p.name;
|
|
swatch.addEventListener('click', () => setPalette(p.name));
|
|
row.appendChild(swatch);
|
|
});
|
|
})();
|
|
|
|
// ─── core wave sim ───
|
|
function addDrop(cx, cy, force, radius) {
|
|
const px = Math.floor(cx * N);
|
|
const py = Math.floor(cy * N);
|
|
const r = Math.floor(radius);
|
|
for (let j = Math.max(1, py - r); j <= Math.min(N, py + r); j++) {
|
|
for (let i = Math.max(1, px - r); i <= Math.min(N, px + r); i++) {
|
|
const dist = Math.sqrt((i - px) ** 2 + (j - py) ** 2);
|
|
if (dist <= r) {
|
|
h[IX(i, j)] -= force * (1 - dist / r);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function step() {
|
|
const c2 = waveSpeed * waveSpeed;
|
|
|
|
for (let j = 1; j <= N; j++) {
|
|
for (let i = 1; i <= N; i++) {
|
|
const laplacian =
|
|
h[IX(i + 1, j)] + h[IX(i - 1, j)] +
|
|
h[IX(i, j + 1)] + h[IX(i, j - 1)] -
|
|
4 * h[IX(i, j)];
|
|
|
|
hTmp[IX(i, j)] = 2 * h[IX(i, j)] - hPrev[IX(i, j)] + c2 * laplacian;
|
|
hTmp[IX(i, j)] *= (1 - damping);
|
|
}
|
|
}
|
|
|
|
const tmp = hPrev;
|
|
hPrev = h;
|
|
h = hTmp;
|
|
hTmp = tmp;
|
|
|
|
hPrev.set(h);
|
|
}
|
|
|
|
function render() {
|
|
const w = canvas.width;
|
|
const h2 = canvas.height;
|
|
if (w === 0 || h2 === 0) return;
|
|
|
|
const imgData = offCtx.createImageData(N, N);
|
|
const data = imgData.data;
|
|
const paletteShift = (performance.now() - startTime) * 0.00005;
|
|
|
|
let maxH = 0.001;
|
|
for (let j = 1; j <= N; j++) {
|
|
for (let i = 1; i <= N; i++) {
|
|
const val = Math.abs(h[IX(i, j)]);
|
|
if (val > maxH) maxH = val;
|
|
}
|
|
}
|
|
|
|
for (let j = 0; j < N; j++) {
|
|
for (let i = 0; i < N; i++) {
|
|
const val = h[IX(i + 1, j + 1)];
|
|
const t = ((val / maxH) * 0.5 + 0.5 + paletteShift) % 1.0;
|
|
const c = getPaletteColor(t);
|
|
const idx = (j * N + i) * 4;
|
|
data[idx] = c[0];
|
|
data[idx + 1] = c[1];
|
|
data[idx + 2] = c[2];
|
|
data[idx + 3] = 255;
|
|
}
|
|
}
|
|
offCtx.putImageData(imgData, 0, 0);
|
|
|
|
ctx.clearRect(0, 0, w, h2);
|
|
ctx.fillStyle = '#05050a';
|
|
ctx.fillRect(0, 0, w, h2);
|
|
ctx.imageSmoothingEnabled = true;
|
|
ctx.drawImage(offscreen, 0, 0, w, h2);
|
|
}
|
|
|
|
function resizeSim() {
|
|
const wrap = document.querySelector('.canvas-wrap');
|
|
const rect = wrap.getBoundingClientRect();
|
|
let size = Math.floor(Math.min(rect.width, rect.height, 800));
|
|
if (size < 50) size = 400;
|
|
canvas.width = size;
|
|
canvas.height = size;
|
|
offscreen.width = N;
|
|
offscreen.height = N;
|
|
}
|
|
|
|
function loop() {
|
|
if (!running) return;
|
|
|
|
if (isDown && prevMouseX >= 0) {
|
|
const rect = canvas.getBoundingClientRect();
|
|
const mx = (mouseX / rect.width);
|
|
const my = (mouseY / rect.height);
|
|
const pmx = (prevMouseX / rect.width);
|
|
const pmy = (prevMouseY / rect.height);
|
|
const dist = Math.sqrt((mx - pmx) ** 2 + (my - pmy) ** 2);
|
|
if (dist > 0.005) {
|
|
addDrop(mx, my, dropForce * timeScale, dropRadius);
|
|
}
|
|
}
|
|
|
|
const steps = Math.ceil(timeScale);
|
|
for (let s = 0; s < steps; s++) step();
|
|
render();
|
|
|
|
animId = requestAnimationFrame(loop);
|
|
prevMouseX = mouseX;
|
|
prevMouseY = mouseY;
|
|
}
|
|
|
|
function reset() {
|
|
h.fill(0);
|
|
hPrev.fill(0);
|
|
hTmp.fill(0);
|
|
}
|
|
|
|
// ─── events ───
|
|
function canvasCoords(e) {
|
|
const rect = canvas.getBoundingClientRect();
|
|
return {
|
|
x: (e.clientX - rect.left) * (canvas.width / rect.width),
|
|
y: (e.clientY - rect.top) * (canvas.height / rect.height),
|
|
};
|
|
}
|
|
|
|
function startDrop(e) {
|
|
const p = canvasCoords(e);
|
|
const rect = canvas.getBoundingClientRect();
|
|
mouseX = e.clientX - rect.left;
|
|
mouseY = e.clientY - rect.top;
|
|
prevMouseX = mouseX;
|
|
prevMouseY = mouseY;
|
|
isDown = true;
|
|
addDrop(mouseX / rect.width, mouseY / rect.height, dropForce * timeScale, dropRadius);
|
|
}
|
|
|
|
function moveDrop(e) {
|
|
const rect = canvas.getBoundingClientRect();
|
|
mouseX = e.clientX - rect.left;
|
|
mouseY = e.clientY - rect.top;
|
|
}
|
|
|
|
canvas.addEventListener('mousedown', startDrop);
|
|
window.addEventListener('mouseup', () => { isDown = false; prevMouseX = -1; prevMouseY = -1; });
|
|
canvas.addEventListener('mousemove', moveDrop);
|
|
|
|
canvas.addEventListener('touchstart', (e) => {
|
|
e.preventDefault();
|
|
const t = e.touches[0];
|
|
const rect = canvas.getBoundingClientRect();
|
|
mouseX = t.clientX - rect.left;
|
|
mouseY = t.clientY - rect.top;
|
|
prevMouseX = mouseX; prevMouseY = mouseY;
|
|
isDown = true;
|
|
addDrop(mouseX / rect.width, mouseY / rect.height, dropForce * timeScale, dropRadius);
|
|
}, { passive: false });
|
|
|
|
canvas.addEventListener('touchmove', (e) => {
|
|
e.preventDefault();
|
|
const t = e.touches[0];
|
|
const rect = canvas.getBoundingClientRect();
|
|
mouseX = t.clientX - rect.left;
|
|
mouseY = t.clientY - rect.top;
|
|
}, { passive: false });
|
|
|
|
canvas.addEventListener('touchend', (e) => {
|
|
e.preventDefault();
|
|
isDown = false; prevMouseX = -1; prevMouseY = -1;
|
|
}, { passive: false });
|
|
|
|
document.getElementById('resetBtn').addEventListener('click', reset);
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape') window.location.href = 'index.html';
|
|
});
|
|
window.addEventListener('resize', resizeSim);
|
|
|
|
// ─── start ───
|
|
updateSliders();
|
|
resizeSim();
|
|
startTime = performance.now();
|
|
loop();
|
|
</script>
|
|
</body>
|
|
</html>
|