Spaces:
Running
Running
Update index.html
Browse files- index.html +92 -106
index.html
CHANGED
@@ -3,131 +3,117 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8" />
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
-
<title>Pulsar Mini โ
|
7 |
-
|
8 |
-
<!-- Tailwind CDN: ํ๋กํ ํ์
์ฉ, ํ์ ์ ๋ก์ปฌ ๋น๋๋ก ๊ต์ฒด -->
|
9 |
<script src="https://cdn.tailwindcss.com"></script>
|
10 |
<style>
|
11 |
-
|
12 |
-
|
13 |
-
}
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
}
|
18 |
</style>
|
19 |
</head>
|
20 |
<body>
|
21 |
-
|
22 |
-
<p class="text-sm text-gray-400 mb-4 text-center">์บ๋ฒ์ค๋ฅผ ํญํ๊ฑฐ๋ ํด๋ฆญํ ๋๋ง๋ค ์๋ก์ด ๋ฌด์์ ํจํด์ด ์ฌ์๋ฉ๋๋ค.</p>
|
23 |
-
|
24 |
<canvas id="canvas"></canvas>
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
<button id="
|
29 |
-
<button id="
|
|
|
30 |
</div>
|
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 |
-
resizeCanvas();
|
74 |
-
window.addEventListener('resize', resizeCanvas);
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
console.error(e);
|
81 |
-
return () => 0;
|
82 |
-
}
|
83 |
-
}
|
84 |
|
85 |
-
|
86 |
-
const t = (time - start) / 1000;
|
87 |
-
const w = canvas.width / DPR;
|
88 |
-
const h = canvas.height / DPR;
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
-
ctx.putImageData(img, 0, 0);
|
104 |
-
if (playing) requestAnimationFrame(draw);
|
105 |
}
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
fn = compile(formulaSrc);
|
111 |
-
start = performance.now();
|
112 |
-
}
|
113 |
-
|
114 |
-
// ๋ฒํผ ์ด๋ฒคํธ
|
115 |
-
playBtn.addEventListener('click', () => {
|
116 |
-
playing = true;
|
117 |
-
playBtn.classList.add('hidden');
|
118 |
-
pauseBtn.classList.remove('hidden');
|
119 |
-
start = performance.now();
|
120 |
-
requestAnimationFrame(draw);
|
121 |
-
});
|
122 |
|
123 |
-
|
124 |
-
playing = false;
|
125 |
-
pauseBtn.classList.add('hidden');
|
126 |
-
playBtn.classList.remove('hidden');
|
127 |
-
});
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
132 |
</body>
|
133 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8" />
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
+
<title>Pulsar Mini โ ํ์คํฌ๋ฆฐ ์ปฌ๋ฌ</title>
|
|
|
|
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
<style>
|
9 |
+
/* ๊ธฐ๋ณธ ๋ ์ด์์ */
|
10 |
+
body {@apply m-0 overflow-hidden bg-black text-gray-200 font-sans;}
|
11 |
+
canvas {width:100vw;height:100vh;display:block;image-rendering:pixelated;cursor:crosshair;}
|
12 |
+
/* ์ค๋ฒ๋ ์ด UI */
|
13 |
+
#ui {@apply absolute top-3 left-1/2 -translate-x-1/2 flex gap-2 z-50 select-none;}
|
14 |
+
#ui button {@apply px-4 py-1.5 rounded text-sm font-semibold shadow bg-gray-800/70 backdrop-blur hover:bg-gray-700;}
|
|
|
15 |
</style>
|
16 |
</head>
|
17 |
<body>
|
18 |
+
<!-- ํ์คํฌ๋ฆฐ ์บ๋ฒ์ค -->
|
|
|
|
|
19 |
<canvas id="canvas"></canvas>
|
20 |
|
21 |
+
<!-- UI ์ค๋ฒ๋ ์ด -->
|
22 |
+
<div id="ui">
|
23 |
+
<button id="play">โถ ์ฌ์</button>
|
24 |
+
<button id="pause" class="hidden">โโ ์ผ์์ ์ง</button>
|
25 |
+
<button id="random">๐ฒ ๋๋ค</button>
|
26 |
</div>
|
27 |
|
28 |
+
<script>
|
29 |
+
const DPR = window.devicePixelRatio || 1;
|
30 |
+
const canvas = document.getElementById('canvas');
|
31 |
+
const ctx = canvas.getContext('2d');
|
32 |
+
const playBtn = document.getElementById('play');
|
33 |
+
const pauseBtn = document.getElementById('pause');
|
34 |
+
const rndBtn = document.getElementById('random');
|
35 |
|
36 |
+
// ๋ค์ํ ์ํ ๊ณต์์ ํ์ฉํ ์ปฌ๋ฌ ํจํด ํ
ํ๋ฆฟ (R,G,B ๊ฐ๊ฐ์ ์)
|
37 |
+
const BASE_PATTERNS = [
|
38 |
+
// 1. ์ฌ์ธ/์ฝ์ฌ์ธ ๊ฒฉ์
|
39 |
+
'(x,y,t)=>{const r=Math.sin((x+$S1)*$F1+t);const g=Math.sin((y+$S2)*$F2-t);const b=Math.cos((x+y)*$F3+t*0.5);return[(r+1)/2,(g+1)/2,(b+1)/2];}',
|
40 |
+
// 2. ์ํ ํ๋
|
41 |
+
'(x,y,t)=>{const d=Math.hypot(x-0.5,y-0.5);return[0.5+0.5*Math.sin(d*$F1-t*2),0.5+0.5*Math.cos(d*$F2+t),0.5+0.5*Math.sin((x-y)*$F3+t)];}',
|
42 |
+
// 3. ๋ณต์ํจ์ ๊ธฐ๋ฐ ํจํด
|
43 |
+
'(x,y,t)=>{return[0.5+0.5*Math.sin((x*x-y*y)*$F1+t),0.5+0.5*Math.cos((x*y)*$F2-t),0.5+0.5*Math.sin((x+y)*$F3)];}',
|
44 |
+
// 4. ์ ๋๊ฐ ์ฌ์ธ โ ๋ฐ๊ณ ์ ๋ช
ํ ์
|
45 |
+
'(x,y,t)=>{return[Math.abs(Math.sin($F1*x+t)),Math.abs(Math.sin($F2*y-t)),Math.abs(Math.sin(($F3)*(x+y)+t*0.3))];}',
|
46 |
+
// 5. ๊ทน์ขํ ๋ฌด์ง๊ฐ
|
47 |
+
'(x,y,t)=>{const a=Math.atan2(y-0.5,x-0.5);const r=(a/Math.PI+1)/2;return[r,0.5+0.5*Math.sin(t+$F1*r*10),1-r];}',
|
48 |
+
// 6. ๋ก์ฆ(์ฅ๋ฏธ) ์ปค๋ธ ๊ธฐ๋ฐ
|
49 |
+
'(x,y,t)=>{const a=Math.atan2(y-0.5,x-0.5);const k=$K;return[0.5+0.5*Math.sin(k*a+t),0.5+0.5*Math.sin(k*a+t+2*Math.PI/3),0.5+0.5*Math.sin(k*a+t+4*Math.PI/3)];}',
|
50 |
+
// 7. ํ๋ฅด๋ง ๋์ ๋
ธ์ด์ฆ
|
51 |
+
'(x,y,t)=>{const r=Math.hypot(x-0.5,y-0.5);const phi=r*10+$F1;return[0.5+0.5*Math.sin(phi+t),0.5+0.5*Math.cos(phi*1.3-t),0.5+0.5*Math.sin(phi*0.7+t*0.5)];}',
|
52 |
+
];
|
53 |
|
54 |
+
function rand(min,max){return Math.random()*(max-min)+min;}
|
55 |
+
function pickRandomFormula(){
|
56 |
+
const tmpl=BASE_PATTERNS[Math.floor(Math.random()*BASE_PATTERNS.length)];
|
57 |
+
return tmpl
|
58 |
+
.replaceAll('$F1',rand(5,30).toFixed(2))
|
59 |
+
.replaceAll('$F2',rand(5,30).toFixed(2))
|
60 |
+
.replaceAll('$F3',rand(5,30).toFixed(2))
|
61 |
+
.replaceAll('$S1',Math.random().toFixed(2))
|
62 |
+
.replaceAll('$S2',Math.random().toFixed(2))
|
63 |
+
.replaceAll('$K',Math.floor(rand(3,9))); // ์ ์ ๊ฝ์ ์
|
64 |
+
}
|
65 |
|
66 |
+
let formulaSrc = pickRandomFormula();
|
67 |
+
let fn = compile(formulaSrc);
|
68 |
+
let playing = true;
|
69 |
+
let start = performance.now();
|
70 |
|
71 |
+
function resizeCanvas(){
|
72 |
+
canvas.width = window.innerWidth * DPR;
|
73 |
+
canvas.height = window.innerHeight * DPR;
|
74 |
+
ctx.setTransform(DPR,0,0,DPR,0,0);
|
75 |
+
}
|
76 |
+
resizeCanvas();
|
77 |
+
window.addEventListener('resize',resizeCanvas);
|
|
|
|
|
|
|
78 |
|
79 |
+
function compile(src){
|
80 |
+
try{ return eval(src); }
|
81 |
+
catch(e){ console.error(e); return ()=>[0,0,0]; }
|
82 |
+
}
|
|
|
|
|
|
|
|
|
83 |
|
84 |
+
function clamp01(v){ return v<0?0:v>1?1:v; }
|
|
|
|
|
|
|
85 |
|
86 |
+
function draw(time){
|
87 |
+
const t = (time - start)/1000;
|
88 |
+
const w = canvas.width/DPR;
|
89 |
+
const h = canvas.height/DPR;
|
90 |
+
const img = ctx.createImageData(w,h);
|
91 |
+
const data = img.data;
|
92 |
+
let idx=0;
|
93 |
+
for(let y=0;y<h;y++){
|
94 |
+
for(let x=0;x<w;x++){
|
95 |
+
const c = fn(x/w,y/h,t,idx);
|
96 |
+
const r = clamp01(c[0])*255;
|
97 |
+
const g = clamp01(c[1])*255;
|
98 |
+
const b = clamp01(c[2])*255;
|
99 |
+
data[idx++] = r;
|
100 |
+
data[idx++] = g;
|
101 |
+
data[idx++] = b;
|
102 |
+
data[idx++] = 255;
|
103 |
}
|
|
|
|
|
104 |
}
|
105 |
+
ctx.putImageData(img,0,0);
|
106 |
+
if(playing) requestAnimationFrame(draw);
|
107 |
+
}
|
108 |
+
requestAnimationFrame(draw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
+
function randomize(){ formulaSrc = pickRandomFormula(); fn = compile(formulaSrc); start = performance.now(); }
|
|
|
|
|
|
|
|
|
111 |
|
112 |
+
// UI ์ด๋ฒคํธ
|
113 |
+
playBtn.addEventListener('click',()=>{playing=true;playBtn.classList.add('hidden');pauseBtn.classList.remove('hidden');start=performance.now();requestAnimationFrame(draw);} );
|
114 |
+
pauseBtn.addEventListener('click',()=>{playing=false;pauseBtn.classList.add('hidden');playBtn.classList.remove('hidden');});
|
115 |
+
rndBtn.addEventListener('click',randomize);
|
116 |
+
canvas.addEventListener('pointerdown',randomize);
|
117 |
+
</script>
|
118 |
</body>
|
119 |
</html>
|