arirajuns commited on
Commit
538fd91
·
verified ·
1 Parent(s): 8c8c5f1

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +309 -19
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Gradient Simulator Glsl
3
- emoji: 🐨
4
- colorFrom: green
5
- colorTo: indigo
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: gradient-simulator-glsl
3
+ emoji: 🐳
4
+ colorFrom: purple
5
+ colorTo: red
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,309 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Fluid Gradient Simulator</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/dat.gui@0.7.7/build/dat.gui.min.js"></script>
10
+ <style>
11
+ body {
12
+ margin: 0;
13
+ overflow: hidden;
14
+ font-family: 'Inter', sans-serif;
15
+ }
16
+ canvas {
17
+ display: block;
18
+ }
19
+ #info-panel {
20
+ position: absolute;
21
+ bottom: 20px;
22
+ left: 20px;
23
+ background: rgba(0,0,0,0.7);
24
+ color: white;
25
+ padding: 15px;
26
+ border-radius: 10px;
27
+ max-width: 300px;
28
+ backdrop-filter: blur(5px);
29
+ }
30
+ #title {
31
+ position: absolute;
32
+ top: 20px;
33
+ left: 20px;
34
+ color: white;
35
+ font-size: 2rem;
36
+ text-shadow: 0 0 10px rgba(0,0,0,0.5);
37
+ z-index: 100;
38
+ }
39
+ .gradient-control {
40
+ display: flex;
41
+ align-items: center;
42
+ margin-bottom: 10px;
43
+ }
44
+ .gradient-control input[type="color"] {
45
+ margin-right: 10px;
46
+ width: 30px;
47
+ height: 30px;
48
+ border: none;
49
+ border-radius: 50%;
50
+ cursor: pointer;
51
+ }
52
+ .gradient-control input[type="range"] {
53
+ flex-grow: 1;
54
+ }
55
+ </style>
56
+ </head>
57
+ <body class="bg-gray-900">
58
+ <div id="title" class="font-bold">Fluid Gradient Simulator</div>
59
+ <div id="info-panel">
60
+ <h3 class="text-lg font-semibold mb-2">Interactive Controls</h3>
61
+ <p class="text-sm mb-4">Move your mouse to disturb the gradient. Scroll to zoom in/out.</p>
62
+ <div id="controls">
63
+ <div class="gradient-control">
64
+ <input type="color" id="color1" value="#ff0000">
65
+ <input type="range" id="color1Pos" min="0" max="1" step="0.01" value="0">
66
+ </div>
67
+ <div class="gradient-control">
68
+ <input type="color" id="color2" value="#00ff00">
69
+ <input type="range" id="color2Pos" min="0" max="1" step="0.01" value="0.5">
70
+ </div>
71
+ <div class="gradient-control">
72
+ <input type="color" id="color3" value="#0000ff">
73
+ <input type="range" id="color3Pos" min="0" max="1" step="0.01" value="1">
74
+ </div>
75
+ <button id="randomize" class="mt-3 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition">Randomize Colors</button>
76
+ </div>
77
+ </div>
78
+
79
+ <script>
80
+ // Initialize Three.js scene
81
+ const scene = new THREE.Scene();
82
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
83
+ const renderer = new THREE.WebGLRenderer({ antialias: true });
84
+ renderer.setSize(window.innerWidth, window.innerHeight);
85
+ renderer.setPixelRatio(window.devicePixelRatio);
86
+ document.body.appendChild(renderer.domElement);
87
+
88
+ // Create a full-screen plane for our shader
89
+ const geometry = new THREE.PlaneGeometry(2, 2);
90
+
91
+ // Fluid simulation shader
92
+ const shaderMaterial = new THREE.ShaderMaterial({
93
+ uniforms: {
94
+ time: { value: 0 },
95
+ resolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) },
96
+ mouse: { value: new THREE.Vector2(0, 0) },
97
+ color1: { value: new THREE.Color(0xff0000) },
98
+ color2: { value: new THREE.Color(0x00ff00) },
99
+ color3: { value: new THREE.Color(0x0000ff) },
100
+ pos1: { value: 0 },
101
+ pos2: { value: 0.5 },
102
+ pos3: { value: 1 },
103
+ turbulence: { value: 0.5 },
104
+ speed: { value: 0.5 }
105
+ },
106
+ vertexShader: `
107
+ varying vec2 vUv;
108
+ void main() {
109
+ vUv = uv;
110
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
111
+ }
112
+ `,
113
+ fragmentShader: `
114
+ uniform float time;
115
+ uniform vec2 resolution;
116
+ uniform vec2 mouse;
117
+ uniform vec3 color1;
118
+ uniform vec3 color2;
119
+ uniform vec3 color3;
120
+ uniform float pos1;
121
+ uniform float pos2;
122
+ uniform float pos3;
123
+ uniform float turbulence;
124
+ uniform float speed;
125
+
126
+ varying vec2 vUv;
127
+
128
+ // Simplex noise function (simplified)
129
+ vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
130
+ vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
131
+ vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); }
132
+ vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
133
+
134
+ float snoise(vec3 v) {
135
+ const vec2 C = vec2(1.0/6.0, 1.0/3.0);
136
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
137
+
138
+ vec3 i = floor(v + dot(v, C.yyy));
139
+ vec3 x0 = v - i + dot(i, C.xxx);
140
+
141
+ vec3 g = step(x0.yzx, x0.xyz);
142
+ vec3 l = 1.0 - g;
143
+ vec3 i1 = min(g.xyz, l.zxy);
144
+ vec3 i2 = max(g.xyz, l.zxy);
145
+
146
+ vec3 x1 = x0 - i1 + C.xxx;
147
+ vec3 x2 = x0 - i2 + C.yyy;
148
+ vec3 x3 = x0 - D.yyy;
149
+
150
+ i = mod289(i);
151
+ vec4 p = permute(permute(permute(
152
+ i.z + vec4(0.0, i1.z, i2.z, 1.0))
153
+ + i.y + vec4(0.0, i1.y, i2.y, 1.0))
154
+ + i.x + vec4(0.0, i1.x, i2.x, 1.0));
155
+
156
+ float n_ = 0.142857142857;
157
+ vec3 ns = n_ * D.wyz - D.xzx;
158
+
159
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
160
+
161
+ vec4 x_ = floor(j * ns.z);
162
+ vec4 y_ = floor(j - 7.0 * x_);
163
+
164
+ vec4 x = x_ * ns.x + ns.yyyy;
165
+ vec4 y = y_ * ns.x + ns.yyyy;
166
+ vec4 h = 1.0 - abs(x) - abs(y);
167
+
168
+ vec4 b0 = vec4(x.xy, y.xy);
169
+ vec4 b1 = vec4(x.zw, y.zw);
170
+
171
+ vec4 s0 = floor(b0)*2.0 + 1.0;
172
+ vec4 s1 = floor(b1)*2.0 + 1.0;
173
+ vec4 sh = -step(h, vec4(0.0));
174
+
175
+ vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy;
176
+ vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww;
177
+
178
+ vec3 p0 = vec3(a0.xy, h.x);
179
+ vec3 p1 = vec3(a0.zw, h.y);
180
+ vec3 p2 = vec3(a1.xy, h.z);
181
+ vec3 p3 = vec3(a1.zw, h.w);
182
+
183
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2,p2), dot(p3,p3)));
184
+ p0 *= norm.x;
185
+ p1 *= norm.y;
186
+ p2 *= norm.z;
187
+ p3 *= norm.w;
188
+
189
+ vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
190
+ m = m * m;
191
+ return 42.0 * dot(m*m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3)));
192
+ }
193
+
194
+ void main() {
195
+ vec2 uv = vUv;
196
+ vec2 p = uv * 2.0 - 1.0;
197
+ p.x *= resolution.x / resolution.y;
198
+
199
+ // Mouse influence
200
+ vec2 mousePos = (mouse * 2.0 - 1.0);
201
+ mousePos.x *= resolution.x / resolution.y;
202
+ float mouseDist = length(p - mousePos);
203
+ float mouseInfluence = smoothstep(0.5, 0.0, mouseDist) * 0.5;
204
+
205
+ // Fluid simulation with noise
206
+ float noise = snoise(vec3(uv * 5.0, time * speed)) * turbulence;
207
+ noise += mouseInfluence * (snoise(vec3(uv * 10.0, time * speed * 2.0)) * 0.5 + 0.5);
208
+
209
+ // Gradient with noise influence
210
+ float gradientPos = uv.y + noise * 0.2;
211
+
212
+ // Three-color gradient
213
+ vec3 color;
214
+ if (gradientPos < pos2) {
215
+ float t = (gradientPos - pos1) / (pos2 - pos1);
216
+ color = mix(color1, color2, t);
217
+ } else {
218
+ float t = (gradientPos - pos2) / (pos3 - pos2);
219
+ color = mix(color2, color3, t);
220
+ }
221
+
222
+ // Add some subtle highlights
223
+ float highlight = snoise(vec3(uv * 20.0, time * 0.5)) * 0.1;
224
+ color += highlight;
225
+
226
+ gl_FragColor = vec4(color, 1.0);
227
+ }
228
+ `
229
+ });
230
+
231
+ const plane = new THREE.Mesh(geometry, shaderMaterial);
232
+ scene.add(plane);
233
+
234
+ camera.position.z = 1;
235
+
236
+ // Mouse interaction
237
+ const mouse = new THREE.Vector2();
238
+ document.addEventListener('mousemove', (event) => {
239
+ mouse.x = (event.clientX / window.innerWidth);
240
+ mouse.y = 1 - (event.clientY / window.innerHeight);
241
+ shaderMaterial.uniforms.mouse.value = mouse;
242
+ });
243
+
244
+ // Handle window resize
245
+ window.addEventListener('resize', () => {
246
+ camera.aspect = window.innerWidth / window.innerHeight;
247
+ camera.updateProjectionMatrix();
248
+ renderer.setSize(window.innerWidth, window.innerHeight);
249
+ shaderMaterial.uniforms.resolution.value.set(window.innerWidth, window.innerHeight);
250
+ });
251
+
252
+ // Color controls
253
+ const color1Input = document.getElementById('color1');
254
+ const color2Input = document.getElementById('color2');
255
+ const color3Input = document.getElementById('color3');
256
+ const pos1Input = document.getElementById('color1Pos');
257
+ const pos2Input = document.getElementById('color2Pos');
258
+ const pos3Input = document.getElementById('color3Pos');
259
+ const randomizeBtn = document.getElementById('randomize');
260
+
261
+ color1Input.addEventListener('input', () => {
262
+ shaderMaterial.uniforms.color1.value.set(color1Input.value);
263
+ });
264
+
265
+ color2Input.addEventListener('input', () => {
266
+ shaderMaterial.uniforms.color2.value.set(color2Input.value);
267
+ });
268
+
269
+ color3Input.addEventListener('input', () => {
270
+ shaderMaterial.uniforms.color3.value.set(color3Input.value);
271
+ });
272
+
273
+ pos1Input.addEventListener('input', () => {
274
+ shaderMaterial.uniforms.pos1.value = parseFloat(pos1Input.value);
275
+ });
276
+
277
+ pos2Input.addEventListener('input', () => {
278
+ shaderMaterial.uniforms.pos2.value = parseFloat(pos2Input.value);
279
+ });
280
+
281
+ pos3Input.addEventListener('input', () => {
282
+ shaderMaterial.uniforms.pos3.value = parseFloat(pos3Input.value);
283
+ });
284
+
285
+ // Randomize colors
286
+ randomizeBtn.addEventListener('click', () => {
287
+ const randomColor = () => {
288
+ return '#' + Math.floor(Math.random()*16777215).toString(16);
289
+ };
290
+
291
+ color1Input.value = randomColor();
292
+ color2Input.value = randomColor();
293
+ color3Input.value = randomColor();
294
+
295
+ shaderMaterial.uniforms.color1.value.set(color1Input.value);
296
+ shaderMaterial.uniforms.color2.value.set(color2Input.value);
297
+ shaderMaterial.uniforms.color3.value.set(color3Input.value);
298
+ });
299
+
300
+ // Animation loop
301
+ function animate() {
302
+ requestAnimationFrame(animate);
303
+ shaderMaterial.uniforms.time.value += 0.01;
304
+ renderer.render(scene, camera);
305
+ }
306
+ animate();
307
+ </script>
308
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=arirajuns/gradient-simulator-glsl" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
309
+ </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Shader toy, three.js,GLSL, type script, physics simulation of gradients