Skip to content

Instantly share code, notes, and snippets.

@CIOSAI
Created January 7, 2025 13:08
Show Gist options
  • Save CIOSAI/e57e29622c2e1bd57620e67948461bc0 to your computer and use it in GitHub Desktop.
Save CIOSAI/e57e29622c2e1bd57620e67948461bc0 to your computer and use it in GitHub Desktop.
genuary 2025 day 7
<!DOCTYPE html>
<html lang="zh_TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta author="CIOSAI_tw">
<title>day 7</title>
<script>
//genuary 2025, day 7, "Use software that is not intended to create art or images."
window.onload = () => {
const main = document.body;
const width = 30;
const height = 30;
let time = 0.0;
// <actual proj>
let box = (p) => {
let q = p.map(n=>Math.abs(n));
return Math.max(...q);
}
let mix = (a,b,c) => (b-a)*c+a;
let heart = (p) => {
let q = p.map(n=>Math.abs(n));
let sq = q[0]*q[0]+q[1]*q[1];
sq /= 2*(q[0]+q[1]);
return mix(
box([p[0]-p[1],p[0]+p[1]])/Math.sqrt(2),
Math.hypot(...(q.map(n=>n-sq))),
(p[1]>0?1:0));
}
let sineEase = (x) => x<=0?0:(x>=1?1:Math.cos(-x*Math.PI)*0.5+0.5);
let frag = (x,y) => {
let o = 0.0;
let uv = [x-width/2, y-height/2];
uv = uv.map(n=>n/width);
uv = uv.map(n=>n+0.001); //avoid dividing by 0
uv[1] = -uv[1];
o = sineEase((heart(uv)*4+time+Math.sin(time*8)*0.3)%1);
return Math.max(Math.min(o,1),0);
};
// </actual proj>
(() => {
main.innerHTML = "";
for(let i=0; i<height; i++){
let row = document.createElement("div");
for(let j=0; j<width; j++){
let pix = document.createElement("span");
pix.innerHTML = "演算藝術"[((i*width)+j)%4];
row.appendChild(pix);
}
main.appendChild(row);
}
})();
let preFrag = () => {
time = Date.now()/1000;
}
setInterval(()=>{
preFrag();
for(let i=0; i<height; i++){
let row = main.children[i];
for(let j=0; j<width; j++){
let pix = row.children[j];
let brightness = frag(j,i);
let hex = "0123456789ABCDEF"[Math.floor(brightness*15.9)];
pix.style.color = "#F"+hex+hex;
}
}
}, 10);
};
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment