WhyMe1234 commited on
Commit
573f7ec
·
verified ·
1 Parent(s): aa5b7e1

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +466 -19
index.html CHANGED
@@ -1,19 +1,466 @@
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>Moiré Pattern Generator</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
16
+ background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
17
+ min-height: 100vh;
18
+ display: flex;
19
+ flex-direction: column;
20
+ overflow-x: hidden;
21
+ }
22
+
23
+ header {
24
+ padding: 1rem 2rem;
25
+ background: rgba(0, 0, 0, 0.2);
26
+ backdrop-filter: blur(10px);
27
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
28
+ }
29
+
30
+ .header-content {
31
+ max-width: 1200px;
32
+ margin: 0 auto;
33
+ display: flex;
34
+ justify-content: space-between;
35
+ align-items: center;
36
+ }
37
+
38
+ h1 {
39
+ color: white;
40
+ font-size: 1.8rem;
41
+ font-weight: 300;
42
+ }
43
+
44
+ .built-with {
45
+ color: #64ffda;
46
+ text-decoration: none;
47
+ font-size: 1rem;
48
+ transition: all 0.3s ease;
49
+ }
50
+
51
+ .built-with:hover {
52
+ color: #ffffff;
53
+ text-shadow: 0 0 10px rgba(100, 255, 218, 0.5);
54
+ }
55
+
56
+ main {
57
+ flex: 1;
58
+ display: flex;
59
+ flex-direction: column;
60
+ align-items: center;
61
+ padding: 2rem;
62
+ }
63
+
64
+ .canvas-container {
65
+ position: relative;
66
+ width: 100%;
67
+ max-width: 1200px;
68
+ background: white;
69
+ border-radius: 12px;
70
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
71
+ overflow: hidden;
72
+ margin-bottom: 2rem;
73
+ }
74
+
75
+ canvas {
76
+ display: block;
77
+ width: 100%;
78
+ height: auto;
79
+ background: white;
80
+ }
81
+
82
+ .controls {
83
+ max-width: 1200px;
84
+ width: 100%;
85
+ background: rgba(255, 255, 255, 0.95);
86
+ backdrop-filter: blur(10px);
87
+ border-radius: 12px;
88
+ padding: 2rem;
89
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
90
+ }
91
+
92
+ .control-group {
93
+ margin-bottom: 1.5rem;
94
+ }
95
+
96
+ .control-group:last-child {
97
+ margin-bottom: 0;
98
+ }
99
+
100
+ label {
101
+ display: block;
102
+ margin-bottom: 0.5rem;
103
+ color: #333;
104
+ font-weight: 500;
105
+ }
106
+
107
+ .slider-container {
108
+ display: flex;
109
+ align-items: center;
110
+ gap: 1rem;
111
+ }
112
+
113
+ input[type="range"] {
114
+ flex: 1;
115
+ height: 6px;
116
+ background: #e0e0e0;
117
+ border-radius: 3px;
118
+ outline: none;
119
+ -webkit-appearance: none;
120
+ }
121
+
122
+ input[type="range"]::-webkit-slider-thumb {
123
+ -webkit-appearance: none;
124
+ appearance: none;
125
+ width: 20px;
126
+ height: 20px;
127
+ background: #2a5298;
128
+ border-radius: 50%;
129
+ cursor: pointer;
130
+ transition: all 0.3s ease;
131
+ }
132
+
133
+ input[type="range"]::-webkit-slider-thumb:hover {
134
+ background: #1e3c72;
135
+ transform: scale(1.2);
136
+ }
137
+
138
+ .value-display {
139
+ min-width: 50px;
140
+ text-align: center;
141
+ font-weight: 600;
142
+ color: #2a5298;
143
+ }
144
+
145
+ .button-group {
146
+ display: flex;
147
+ gap: 1rem;
148
+ margin-top: 1.5rem;
149
+ }
150
+
151
+ button {
152
+ padding: 0.8rem 1.5rem;
153
+ border: none;
154
+ border-radius: 6px;
155
+ background: linear-gradient(135deg, #2a5298 0%, #1e3c72 100%);
156
+ color: white;
157
+ font-weight: 500;
158
+ cursor: pointer;
159
+ transition: all 0.3s ease;
160
+ }
161
+
162
+ button:hover {
163
+ transform: translateY(-2px);
164
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
165
+ }
166
+
167
+ button:active {
168
+ transform: translateY(0);
169
+ }
170
+
171
+ .info-panel {
172
+ max-width: 1200px;
173
+ width: 100%;
174
+ background: rgba(255, 255, 255, 0.1);
175
+ backdrop-filter: blur(10px);
176
+ border-radius: 12px;
177
+ padding: 1.5rem;
178
+ margin-top: 2rem;
179
+ color: white;
180
+ }
181
+
182
+ .info-panel h2 {
183
+ margin-bottom: 1rem;
184
+ font-weight: 300;
185
+ }
186
+
187
+ .info-panel p {
188
+ line-height: 1.6;
189
+ opacity: 0.9;
190
+ }
191
+
192
+ @media (max-width: 768px) {
193
+ header {
194
+ padding: 1rem;
195
+ }
196
+
197
+ h1 {
198
+ font-size: 1.4rem;
199
+ }
200
+
201
+ .controls {
202
+ padding: 1.5rem;
203
+ }
204
+
205
+ .button-group {
206
+ flex-direction: column;
207
+ }
208
+
209
+ button {
210
+ width: 100%;
211
+ }
212
+ }
213
+
214
+ @media (max-width: 480px) {
215
+ main {
216
+ padding: 1rem;
217
+ }
218
+
219
+ .canvas-container {
220
+ border-radius: 8px;
221
+ }
222
+
223
+ .controls {
224
+ border-radius: 8px;
225
+ }
226
+ }
227
+ </style>
228
+ </head>
229
+ <body>
230
+ <header>
231
+ <div class="header-content">
232
+ <h1>Moiré Pattern Generator</h1>
233
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" class="built-with" target="_blank">Built with anycoder</a>
234
+ </div>
235
+ </header>
236
+
237
+ <main>
238
+ <div class="canvas-container">
239
+ <canvas id="moireCanvas"></canvas>
240
+ </div>
241
+
242
+ <div class="controls">
243
+ <div class="control-group">
244
+ <label for="angle1">Angle 1 (degrees)</label>
245
+ <div class="slider-container">
246
+ <input type="range" id="angle1" min="0" max="180" value="0" step="1">
247
+ <span class="value-display" id="angle1Value">0°</span>
248
+ </div>
249
+ </div>
250
+
251
+ <div class="control-group">
252
+ <label for="angle2">Angle 2 (degrees)</label>
253
+ <div class="slider-container">
254
+ <input type="range" id="angle2" min="0" max="180" value="1" step="1">
255
+ <span class="value-display" id="angle2Value">1°</span>
256
+ </div>
257
+ </div>
258
+
259
+ <div class="control-group">
260
+ <label for="lineSpacing">Line Spacing (pixels)</label>
261
+ <div class="slider-container">
262
+ <input type="range" id="lineSpacing" min="1" max="50" value="10" step="1">
263
+ <span class="value-display" id="lineSpacingValue">10px</span>
264
+ </div>
265
+ </div>
266
+
267
+ <div class="control-group">
268
+ <label for="lineWidth">Line Width (pixels)</label>
269
+ <div class="slider-container">
270
+ <input type="range" id="lineWidth" min="0.5" max="5" value="1" step="0.5">
271
+ <span class="value-display" id="lineWidthValue">1px</span>
272
+ </div>
273
+ </div>
274
+
275
+ <div class="button-group">
276
+ <button id="randomizeBtn">Randomize</button>
277
+ <button id="resetBtn">Reset</button>
278
+ <button id="animateBtn">Animate</button>
279
+ </div>
280
+ </div>
281
+
282
+ <div class="info-panel">
283
+ <h2>About Moiré Patterns</h2>
284
+ <p>
285
+ A Moiré pattern is an interference pattern created when two sets of lines or dots are overlaid at slightly different angles.
286
+ This visual effect is often seen in printed materials, digital displays, and optical systems.
287
+ Adjust the controls above to create your own unique Moiré patterns by changing the angles, spacing, and thickness of the lines.
288
+ </p>
289
+ </div>
290
+ </main>
291
+
292
+ <script>
293
+ class MoirePattern {
294
+ constructor(canvas) {
295
+ this.canvas = canvas;
296
+ this.ctx = canvas.getContext('2d');
297
+ this.angle1 = 0;
298
+ this.angle2 = 1;
299
+ this.lineSpacing = 10;
300
+ this.lineWidth = 1;
301
+ this.animationId = null;
302
+ this.isAnimating = false;
303
+ this.time = 0;
304
+
305
+ this.resizeCanvas();
306
+ window.addEventListener('resize', () => this.resizeCanvas());
307
+ }
308
+
309
+ resizeCanvas() {
310
+ const container = this.canvas.parentElement;
311
+ this.canvas.width = container.clientWidth;
312
+ this.canvas.height = window.innerHeight * 0.6;
313
+ this.draw();
314
+ }
315
+
316
+ draw() {
317
+ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
318
+
319
+ // Draw first set of lines
320
+ this.drawLines(this.angle1, 'rgba(42, 82, 152, 0.8)');
321
+
322
+ // Draw second set of lines
323
+ this.drawLines(this.angle2, 'rgba(100, 255, 218, 0.8)');
324
+ }
325
+
326
+ drawLines(angle, color) {
327
+ this.ctx.save();
328
+ this.ctx.strokeStyle = color;
329
+ this.ctx.lineWidth = this.lineWidth;
330
+ this.ctx.lineCap = 'round';
331
+
332
+ const radians = (angle * Math.PI) / 180;
333
+ const spacing = this.lineSpacing;
334
+
335
+ // Calculate the number of lines needed to cover the canvas
336
+ const diagonal = Math.sqrt(this.canvas.width * this.canvas.width + this.canvas.height * this.canvas.height);
337
+ const numLines = Math.ceil(diagonal / spacing) + 1;
338
+
339
+ // Calculate the perpendicular direction to the lines
340
+ const perpX = -Math.sin(radians);
341
+ const perpY = Math.cos(radians);
342
+
343
+ // Calculate the starting point for the first line
344
+ const startX = -diagonal;
345
+ const startY = -diagonal;
346
+
347
+ for (let i = 0; i < numLines; i++) {
348
+ const offset = i * spacing;
349
+ const x1 = startX + perpX * offset;
350
+ const y1 = startY + perpY * offset;
351
+ const x2 = x1 + this.canvas.width * Math.cos(radians) + this.canvas.height * Math.sin(radians);
352
+ const y2 = y1 + this.canvas.height * Math.cos(radians) - this.canvas.width * Math.sin(radians);
353
+
354
+ this.ctx.beginPath();
355
+ this.ctx.moveTo(x1, y1);
356
+ this.ctx.lineTo(x2, y2);
357
+ this.ctx.stroke();
358
+ }
359
+
360
+ this.ctx.restore();
361
+ }
362
+
363
+ update(angle1, angle2, lineSpacing, lineWidth) {
364
+ this.angle1 = angle1;
365
+ this.angle2 = angle2;
366
+ this.lineSpacing = lineSpacing;
367
+ this.lineWidth = lineWidth;
368
+ this.draw();
369
+ }
370
+
371
+ animate() {
372
+ if (this.isAnimating) {
373
+ this.isAnimating = false;
374
+ cancelAnimationFrame(this.animationId);
375
+ return;
376
+ }
377
+
378
+ this.isAnimating = true;
379
+ this.time = 0;
380
+
381
+ const animateFrame = () => {
382
+ if (!this.isAnimating) return;
383
+
384
+ this.time += 0.01;
385
+ const angle1 = Math.sin(this.time) * 30;
386
+ const angle2 = angle1 + 1;
387
+
388
+ this.update(angle1, angle2, this.lineSpacing, this.lineWidth);
389
+ this.animationId = requestAnimationFrame(animateFrame);
390
+ };
391
+
392
+ animateFrame();
393
+ }
394
+
395
+ randomize() {
396
+ const angle1 = Math.random() * 180;
397
+ const angle2 = (angle1 + Math.random() * 10) % 180;
398
+ const spacing = Math.random() * 30 + 5;
399
+ const width = Math.random() * 3 + 0.5;
400
+
401
+ this.update(angle1, angle2, spacing, width);
402
+
403
+ // Update sliders
404
+ document.getElementById('angle1').value = angle1;
405
+ document.getElementById('angle1Value').textContent = `${Math.round(angle1)}°`;
406
+ document.getElementById('angle2').value = angle2;
407
+ document.getElementById('angle2Value').textContent = `${Math.round(angle2)}°`;
408
+ document.getElementById('lineSpacing').value = spacing;
409
+ document.getElementById('lineSpacingValue').textContent = `${Math.round(spacing)}px`;
410
+ document.getElementById('lineWidth').value = width;
411
+ document.getElementById('lineWidthValue').textContent = `${width}px`;
412
+ }
413
+
414
+ reset() {
415
+ this.update(0, 1, 10, 1);
416
+
417
+ // Reset sliders
418
+ document.getElementById('angle1').value = 0;
419
+ document.getElementById('angle1Value').textContent = '0°';
420
+ document.getElementById('angle2').value = 1;
421
+ document.getElementById('angle2Value').textContent = '1°';
422
+ document.getElementById('lineSpacing').value = 10;
423
+ document.getElementById('lineSpacingValue').textContent = '10px';
424
+ document.getElementById('lineWidth').value = 1;
425
+ document.getElementById('lineWidthValue').textContent = '1px';
426
+ }
427
+ }
428
+
429
+ // Initialize the application
430
+ document.addEventListener('DOMContentLoaded', () => {
431
+ const canvas = document.getElementById('moireCanvas');
432
+ const moire = new MoirePattern(canvas);
433
+
434
+ // Set up event listeners for controls
435
+ const angle1Slider = document.getElementById('angle1');
436
+ const angle2Slider = document.getElementById('angle2');
437
+ const lineSpacingSlider = document.getElementById('lineSpacing');
438
+ const lineWidthSlider = document.getElementById('lineWidth');
439
+
440
+ const updateValues = () => {
441
+ const angle1 = parseFloat(angle1Slider.value);
442
+ const angle2 = parseFloat(angle2Slider.value);
443
+ const spacing = parseFloat(lineSpacingSlider.value);
444
+ const width = parseFloat(lineWidthSlider.value);
445
+
446
+ moire.update(angle1, angle2, spacing, width);
447
+
448
+ document.getElementById('angle1Value').textContent = `${angle1}°`;
449
+ document.getElementById('angle2Value').textContent = `${angle2}°`;
450
+ document.getElementById('lineSpacingValue').textContent = `${spacing}px`;
451
+ document.getElementById('lineWidthValue').textContent = `${width}px`;
452
+ };
453
+
454
+ angle1Slider.addEventListener('input', updateValues);
455
+ angle2Slider.addEventListener('input', updateValues);
456
+ lineSpacingSlider.addEventListener('input', updateValues);
457
+ lineWidthSlider.addEventListener('input', updateValues);
458
+
459
+ // Button event listeners
460
+ document.getElementById('randomizeBtn').addEventListener('click', () => moire.randomize());
461
+ document.getElementById('resetBtn').addEventListener('click', () => moire.reset());
462
+ document.getElementById('animateBtn').addEventListener('click', () => moire.animate());
463
+ });
464
+ </script>
465
+ </body>
466
+ </html>