K00B404 commited on
Commit
d8b5099
1 Parent(s): 2f2c86e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -104
app.py CHANGED
@@ -5,110 +5,72 @@ import random
5
  import os
6
  from PIL import Image
7
  from deep_translator import GoogleTranslator
8
- html='''<!DOCTYPE html>
9
- <html lang="en">
10
- <head>
11
- <meta charset="UTF-8">
12
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
13
- <title>Perlin Noise Animated Neon Square Effect</title>
14
- <style>
15
- body {
16
- background-color: #000;
17
- margin: 0;
18
- height: 100vh;
19
- display: flex;
20
- justify-content: center;
21
- align-items: center;
22
- }
23
-
24
- #neon-square {
25
- width: 300px;
26
- height: 300px;
27
- position: relative;
28
- }
29
-
30
- #neon-square::before {
31
- content: '';
32
- position: absolute;
33
- top: -20px;
34
- left: -20px;
35
- right: -20px;
36
- bottom: -20px;
37
- z-index: -1;
38
- filter: blur(20px);
39
- }
40
- </style>
41
- </head>
42
- <body>
43
- <div id="neon-square"></div>
44
-
45
- <script src="https://cdnjs.cloudflare.com/ajax/libs/noisejs/2.1.0/perlin.min.js"></script>
46
- <script>
47
- const neonSquare = document.getElementById('neon-square');
48
- let time = 0;
49
-
50
- function hslToRgb(h, s, l) {
51
- let r, g, b;
52
- if (s === 0) {
53
- r = g = b = l;
54
- } else {
55
- const hue2rgb = (p, q, t) => {
56
- if (t < 0) t += 1;
57
- if (t > 1) t -= 1;
58
- if (t < 1/6) return p + (q - p) * 6 * t;
59
- if (t < 1/2) return q;
60
- if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
61
- return p;
62
- };
63
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
64
- const p = 2 * l - q;
65
- r = hue2rgb(p, q, h + 1/3);
66
- g = hue2rgb(p, q, h);
67
- b = hue2rgb(p, q, h - 1/3);
68
- }
69
- return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
70
- }
71
-
72
- function updateColors() {
73
- const noise1 = noise.simplex2(time * 0.5, 0) * 0.5 + 0.5;
74
- const noise2 = noise.simplex2(time * 0.5, 1000) * 0.5 + 0.5;
75
- const noise3 = noise.simplex2(time * 0.5, 2000) * 0.5 + 0.5;
76
- const noise4 = noise.simplex2(time * 0.5, 3000) * 0.5 + 0.5;
77
-
78
- const [r1, g1, b1] = hslToRgb(noise1, 1, 0.5);
79
- const [r2, g2, b2] = hslToRgb(noise2, 1, 0.5);
80
- const [r3, g3, b3] = hslToRgb(noise3, 1, 0.5);
81
- const [r4, g4, b4] = hslToRgb(noise4, 1, 0.5);
82
-
83
- const gradient = `linear-gradient(45deg,
84
- rgb(${r1},${g1},${b1}),
85
- rgb(${r2},${g2},${b2}),
86
- rgb(${r3},${g3},${b3}),
87
- rgb(${r4},${g4},${b4}))`;
88
-
89
- neonSquare.style.background = gradient;
90
- neonSquare.style.boxShadow = `
91
- 0 0 20px rgb(${r1},${g1},${b1}),
92
- 0 0 40px rgb(${r2},${g2},${b2}),
93
- 0 0 60px rgb(${r3},${g3},${b3}),
94
- 0 0 80px rgb(${r4},${g4},${b4})
95
- `;
96
-
97
- neonSquare.style.setProperty('--glow', gradient);
98
-
99
- time += 0.01;
100
- }
101
-
102
- // Update colors every frame
103
- function animate() {
104
- updateColors();
105
- requestAnimationFrame(animate);
106
- }
107
-
108
- animate();
109
- </script>
110
- </body>
111
- </html>'''
112
  # os.makedirs('assets', exist_ok=True)
113
  if not os.path.exists('icon.jpg'):
114
  os.system("wget -O icon.jpg https://i.pinimg.com/564x/64/49/88/644988c59447eb00286834c2e70fdd6b.jpg")
 
5
  import os
6
  from PIL import Image
7
  from deep_translator import GoogleTranslator
8
+ html='''<style>
9
+ body, html, #app {
10
+ margin: 0;
11
+ width: 100%;
12
+ height: 100%;
13
+ }
14
+
15
+ #app {
16
+ overflow: hidden;
17
+ touch-action: pan-up;
18
+ color: #ffffff;
19
+ font-family: 'Montserrat', sans-serif;
20
+ text-align: center;
21
+ text-shadow: 0 0 5px #000000, 0 0 20px #000;
22
+ user-select: none;
23
+ }
24
+
25
+ #app h1 {
26
+ --fontSize: 50px;
27
+ --lineHeight: 70px;
28
+ width: auto;
29
+ height: calc(2 * var(--lineHeight));
30
+ line-height: var(--lineHeight);
31
+ margin: calc(50vh - var(--lineHeight)) auto 0;
32
+ font-size: var(--fontSize);
33
+ }
34
+
35
+ #app a {
36
+ margin-top: 10px;
37
+ display: inline-block;
38
+ text-decoration: none;
39
+ color: #fff;
40
+ }
41
+
42
+ #app canvas {
43
+ display: block;
44
+ position: fixed;
45
+ z-index: -1;
46
+ top: 0;
47
+ }
48
+ </style>
49
+
50
+ <script>
51
+ import { swarmBackground } from 'https://unpkg.com/[email protected]/build/threejs-toys.module.cdn.min.js'
52
+
53
+ const bg = swarmBackground({
54
+ el: document.getElementById('app'),
55
+ eventsEl: document.body,
56
+ gpgpuSize: 256,
57
+ color: [Math.random() * 0xffffff, Math.random() * 0xffffff],
58
+ geometry: 'default'
59
+ })
60
+
61
+ bg.three.camera.position.set(0, 0, 200)
62
+
63
+ document.body.addEventListener('click', () => {
64
+ bg.setColors([Math.random() * 0xffffff, Math.random() * 0xffffff])
65
+ })
66
+ </script>
67
+ <div id="app">
68
+ <div id="hero">
69
+ <h1>SWARM<br/>BACKGROUND</h1>
70
+ <a target="_blank" href="https://github.com/klevron/threejs-toys">github/threejs-toys</a>
71
+ </div>
72
+ </div>
73
+ '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  # os.makedirs('assets', exist_ok=True)
75
  if not os.path.exists('icon.jpg'):
76
  os.system("wget -O icon.jpg https://i.pinimg.com/564x/64/49/88/644988c59447eb00286834c2e70fdd6b.jpg")