Last active
June 25, 2024 14:40
-
-
Save yoya/ae8816b003340def21091a362c073376 to your computer and use it in GitHub Desktop.
mexican hat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<canvas width="800" height="500" style="background-color:black"> </canvas> | |
<script> | |
"use strict" | |
const canvas = document.querySelector("canvas") | |
const ctx = canvas.getContext("2d") | |
const {width, height} = canvas | |
ctx.fillStyle = "black" | |
ctx.fillRect(0, 0, width, height) | |
const d = new Float32Array(160) | |
for (let l = 0; l <= 159; l++) { | |
d[l] = 100 | |
} | |
const dr = 3.14/180 | |
const s = 2 // view scale | |
function pset(x, y, color) { | |
ctx.globalCompositeOperation = "lighter" | |
ctx.fillStyle = color | |
ctx.fillRect(s*x, s*y, s, s) | |
} | |
for (let y = -180; y <= 180; y += 6) { | |
for (let x = -180; x <= 180; x += 4) { | |
const r = dr * Math.sqrt(x*x + y*y) | |
const z = 100 * Math.cos(r) - 30 * Math.cos(3*r) | |
const sx = Math.floor(80 + x/3 - y/6) | |
const sy = Math.floor(40 - y/6 - z/4) | |
if ((sx < 0) || (sx >= 160)) { continue } | |
if (d[sx] <= sy) { continue } | |
const zz = Math.floor((z+100) * 0.035) + 1 | |
if ((zz==1) || (zz==3) || (zz==5) || (zz==7)) { | |
pset(sx*2, sy*2, "#26F") // blue | |
} | |
if ((zz==2) || (zz==3) || (zz>=6)) { | |
pset(sx*2, sy*2, "#F26") // red | |
} | |
if (zz>=4) { | |
pset(sx*2, sy*2, "#0F0") // green | |
} | |
d[sx] = sy | |
} | |
} | |
// https://x.com/yone/status/1804801190448054746 | |
</script> | |
</body> | |
</html> |
Author
yoya
commented
Jun 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment