Sada8888 commited on
Commit
a027658
·
verified ·
1 Parent(s): 8c07969

Create cartoon.html

Browse files
Files changed (1) hide show
  1. templates/cartoon.html +334 -0
templates/cartoon.html ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="fa" dir="rtl">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>خلق تصاویر کارتونی</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap" rel="stylesheet">
8
+ <style>
9
+ /* تمام CSS های اختصاصی شما بدون هیچ تغییری حفظ شده است */
10
+ :root {
11
+ --app-font: 'Vazirmatn', sans-serif;
12
+ --app-bg: #F8F9FC; --panel-bg: #FFFFFF; --panel-border: #EAEFF7;
13
+ --input-bg: #F6F8FB; --input-border: #E1E7EF;
14
+ --text-primary: #1A202C; --text-secondary: #626F86; --text-tertiary: #8A94A6;
15
+ --accent-primary: #4A6CFA; --accent-primary-hover: #3553D6;
16
+ --accent-primary-glow: rgba(74, 108, 250, 0.25);
17
+ --accent-secondary: #0FD4A8;
18
+ --shadow-sm: 0 1px 2px 0 rgba(26, 32, 44, 0.03);
19
+ --shadow-md: 0 4px 6px -1px rgba(26, 32, 44, 0.05);
20
+ --shadow-xl: 0 20px 25px -5px rgba(26, 32, 44, 0.07);
21
+ --radius-card: 24px; --radius-btn: 14px; --radius-input: 12px;
22
+ --transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
23
+ }
24
+
25
+ @keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
26
+ @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
27
+ @keyframes pulse { 0% { box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); } 50% { box-shadow: 0 0 60px rgba(56, 189, 248, 0.7); } 100% { box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); } }
28
+ @keyframes glow-text { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } }
29
+
30
+ body { font-family: var(--app-font); background-color: var(--app-bg); color: var(--text-primary); margin: 0; padding: 2.5rem 1rem; display: flex; justify-content: center; min-height: 100vh; }
31
+ .container { max-width: 820px; width: 100%; }
32
+
33
+ header { position: relative; text-align: center; margin-bottom: 2.5rem; padding: 2rem 0; animation: fadeIn 0.8s 0.1s ease-out backwards; overflow: hidden; }
34
+ #neural-network-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
35
+ h1, .subtitle { position: relative; z-index: 2; }
36
+ h1 { font-size: 2.8rem; font-weight: 800; margin: 0 0 0.8rem 0; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
37
+ .subtitle { font-size: 1.1rem; color: var(--text-secondary); margin-top: 0; max-width: 650px; margin-left: auto; margin-right: auto; line-height: 1.8; }
38
+
39
+ main { padding: 3rem; background-color: var(--panel-bg); border-radius: var(--radius-card); box-shadow: var(--shadow-xl); border: 1px solid var(--panel-border); animation: fadeIn 0.8s 0.3s ease-out backwards; }
40
+ .form-group { margin-bottom: 2.5rem; }
41
+ .form-label { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; color: var(--text-primary); font-size: 1.2em; margin-bottom: 1.2rem; }
42
+ .form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
43
+
44
+ textarea { width: 100%; padding: 1rem 1.2rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); font-family: inherit; font-size: 1rem; box-sizing: border-box; transition: var(--transition-smooth); min-height: 90px; resize: vertical; }
45
+ textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow); background-color: var(--panel-bg); }
46
+
47
+ .aspect-ratio-selector { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
48
+ .ratio-option { background-color: var(--input-bg); border: 2px solid var(--input-border); border-radius: var(--radius-input); padding: 1rem; cursor: pointer; transition: var(--transition-smooth); text-align: center; }
49
+ .ratio-option.active { border-color: var(--accent-primary); background-color: #fff; box-shadow: 0 0 0 3px var(--accent-primary-glow); }
50
+ .ratio-icon { height: 50px; display: flex; align-items: center; justify-content: center; margin: 0 auto 0.75rem; }
51
+ .ratio-icon > div, .ratio-icon > svg { background-color: var(--panel-bg); border: 2px solid var(--text-tertiary); border-radius: 6px; transition: var(--transition-smooth); box-sizing: border-box; }
52
+ .ratio-option.active .ratio-icon > div, .ratio-option.active .ratio-icon > svg { border-color: var(--accent-primary); background-color: var(--accent-primary-glow); }
53
+ .ratio-label { font-weight: 600; color: var(--text-secondary); font-size: 0.9rem; }
54
+ .ratio-option.active .ratio-label { color: var(--text-primary); }
55
+
56
+ #icon-portrait > div { width: 28px; height: 50px; }
57
+ #icon-landscape > div { width: 60px; height: 34px; }
58
+ #icon-square > div { width: 45px; height: 45px; }
59
+ #icon-custom > svg { width: 45px; height: 45px; padding: 8px; color: var(--text-tertiary); }
60
+ .ratio-option.active #icon-custom > svg { color: var(--accent-primary); }
61
+
62
+ #submit-btn { display: flex; align-items: center; justify-content: center; gap: 0.75rem; width: 100%; padding: 1.1rem; font-size: 1.2rem; font-weight: 700; background: linear-gradient(95deg, var(--accent-secondary) 0%, var(--accent-primary) 100%); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; transition: all 0.3s ease; box-shadow: 0 6px 12px -3px var(--accent-primary-glow); margin-top: 1.5rem; }
63
+ #submit-btn svg { width: 24px; height: 24px; }
64
+ #submit-btn:hover:not(:disabled) { transform: translateY(-5px) scale(1.02); }
65
+ #submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; opacity: 0.7; box-shadow: none; transform: none;}
66
+ #submit-btn .spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
67
+
68
+ #result-container { min-height: 250px; position: relative; padding: 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); border: 2px dashed var(--input-border); display: flex; align-items: center; justify-content: center; flex-direction: column; box-sizing: border-box; }
69
+ #result-container.loading { padding: 0; border: none; background-color: transparent; }
70
+ #result-container.has-content { border-style: solid; border-color: var(--panel-border); }
71
+
72
+ .generator-container { position: relative; width: 100%; max-width: 500px; height: 200px; border: 2px solid #38bdf8; border-radius: 20px; overflow: hidden; box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); animation: pulse 5s infinite; background-color: #161b22; color: #f0f6fc; display: flex; flex-direction: column; justify-content: center; align-items: center; }
73
+ .text-overlay { font-size: 18px; font-weight: 700; animation: glow-text 7s infinite ease-in-out; text-align: center; }
74
+ .progress-bar { position: absolute; bottom: 0; left: 0; width: 0%; height: 6px; background: linear-gradient(to right, #38bdf8, #bb86fc, #facc15); transition: width 1s linear; }
75
+
76
+ #result-image-wrapper { display: none; width: 100%; text-align: center; }
77
+ #result-image-display { max-width: 100%; max-height: 500px; object-fit: contain; border-radius: var(--radius-input); box-shadow: var(--shadow-md); border: 1px solid var(--panel-border); }
78
+
79
+ .download-button { padding: 12px 25px; margin-top: 1.5rem; border: none; border-radius: var(--radius-btn); font-size: 1rem; font-weight: 600; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 0.7rem; background-color: var(--accent-primary); color: white; box-shadow: var(--shadow-md); text-decoration: none;}
80
+ .download-button:hover { background-color: var(--accent-primary-hover); transform: translateY(-3px); }
81
+
82
+ .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(18, 24, 38, 0.6); backdrop-filter: blur(8px); display: none; justify-content: center; align-items: center; z-index: 1000; }
83
+ .modal-content-small { background: var(--panel-bg); padding: 2rem; border-radius: var(--radius-card); max-width: 350px; width: 90%; text-align: center; box-shadow: var(--shadow-xl); position: relative; }
84
+ .modal-content-small h3 { margin-top: 0; margin-bottom: 1.5rem; }
85
+ .modal-content-small input { width: 100%; padding: 0.8rem 1rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); font-family: inherit; font-size: 1rem; box-sizing: border-box; margin-bottom: 1rem;}
86
+ #confirm-custom-size-btn { width: 100%; padding: 0.9rem; font-size: 1rem; font-weight: 700; background-color: var(--accent-primary); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; }
87
+ #close-custom-modal-btn { position: absolute; top: 10px; left: 10px; background: transparent; border: none; font-size: 2rem; cursor: pointer; color: var(--text-tertiary); line-height: 1; padding: 0.5rem; }
88
+
89
+ @media (max-width: 768px) {
90
+ main { padding: 1.5rem; } h1 { font-size: 2.2rem; }
91
+ .aspect-ratio-selector { grid-template-columns: repeat(2, 1fr); }
92
+ }
93
+ </style>
94
+ </head>
95
+ <body>
96
+ <div class="container">
97
+ <header>
98
+ <canvas id="neural-network-canvas"></canvas>
99
+ <h1>خلق تصاویر انیمیشنی جذاب</h1>
100
+ <p class="subtitle">ایده‌های خود را به سادگی به تصاویر انیمیشنی با سبک منحصر به فرد تبدیل کنید.</p>
101
+ </header>
102
+ <main>
103
+ <div class="form-group">
104
+ <div class="form-label">
105
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>
106
+ ۱. ایده خود را توصیف کنید
107
+ </div>
108
+ <textarea id="prompt-input" rows="3" placeholder="مثال: یک فضانورد که روی ماه در حال موج‌سواری است"></textarea>
109
+ </div>
110
+
111
+ <div class="form-group">
112
+ <div class="form-label">
113
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 9V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h4"/><rect x="12" y="13" width="10" height="8" rx="2"/><path d="M17 12v-1a2 2 0 0 0-2-2h-1"/></svg>
114
+ ۲. اندازه تصویر را انتخاب کنید
115
+ </div>
116
+ <div class="aspect-ratio-selector" id="aspect-ratio-selector">
117
+ <div class="ratio-option" data-ratio="9:16">
118
+ <div class="ratio-icon" id="icon-portrait"><div></div></div>
119
+ <div class="ratio-label">عمودی ۹:۱۶</div>
120
+ </div>
121
+ <div class="ratio-option" data-ratio="16:9">
122
+ <div class="ratio-icon" id="icon-landscape"><div></div></div>
123
+ <div class="ratio-label">افقی ۱۶:۹</div>
124
+ </div>
125
+ <div class="ratio-option" data-ratio="custom">
126
+ <div class="ratio-icon" id="icon-custom">
127
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 16V8a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h8"/><circle cx="18" cy="18" r="3"/><path d="M18 15v-2"/><path d="M18 21v-2"/><path d="M15 18h-2"/><path d="M21 18h-2"/></svg>
128
+ </div>
129
+ <div class="ratio-label">
130
+ اندازه دلخواه <span id="custom-ratio-label-value"></span>
131
+ </div>
132
+ </div>
133
+ <div class="ratio-option active" data-ratio="1:1">
134
+ <div class="ratio-icon" id="icon-square"><div></div></div>
135
+ <div class="ratio-label">مربع ۱:۱</div>
136
+ </div>
137
+ </div>
138
+ </div>
139
+
140
+ <button id="submit-btn">
141
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/></svg>
142
+ <span id="btn-text">خلق کن!</span>
143
+ <div class="spinner" style="display: none;"></div>
144
+ </button>
145
+
146
+ <div class="form-group" style="margin-top: 3rem;">
147
+ <div class="form-label">
148
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/><path d="M21 14l-1.5 3-3-1.5 3-3 1.5 3z"/></svg>
149
+ ۳. نتیجه
150
+ </div>
151
+ <div id="result-container">
152
+ <p id="idle-text">برای شروع، ایده خود را نوشته و دکمه را بزنید.</p>
153
+ </div>
154
+ </div>
155
+ </main>
156
+ </div>
157
+
158
+ <!-- Modal for Custom Size -->
159
+ <div class="modal-overlay" id="custom-size-modal">
160
+ <div class="modal-content-small">
161
+ <button id="close-custom-modal-btn">&times;</button>
162
+ <h3>تنظیم اندازه دلخواه</h3>
163
+ <label>عرض (Width)</label>
164
+ <input type="number" id="custom-width-input" value="1024" min="512" max="1536" step="8">
165
+ <label>طول (Height)</label>
166
+ <input type="number" id="custom-height-input" value="1024" min="512" max="1536" step="8">
167
+ <button id="confirm-custom-size-btn">تایید و اعمال</button>
168
+ </div>
169
+ </div>
170
+
171
+ <script>
172
+ // اتصال بخش UI به کدهای جاوا اسکریپت
173
+ const promptInput = document.getElementById('prompt-input');
174
+ const submitBtn = document.getElementById('submit-btn');
175
+ const resultContainer = document.getElementById('result-container');
176
+ const ratioSelector = document.getElementById('aspect-ratio-selector');
177
+
178
+ let selectedRatio = '1:1';
179
+ let customWidth = 1024;
180
+ let customHeight = 1024;
181
+ let pollTimer = null;
182
+
183
+ const getDimensions = (ratio) => {
184
+ if (ratio === 'custom') return { width: customWidth, height: customHeight };
185
+ switch (ratio) {
186
+ case '9:16': return { width: 768, height: 1344 };
187
+ case '16:9': return { width: 1344, height: 768 };
188
+ case '1:1': return { width: 1024, height: 1024 };
189
+ default: return { width: 1024, height: 1024 };
190
+ }
191
+ };
192
+
193
+ const setLoadingState = (isLoading, message) => {
194
+ const spinner = submitBtn.querySelector('.spinner');
195
+ const icon = submitBtn.querySelector('svg');
196
+ const btnText = document.getElementById('btn-text');
197
+
198
+ if (isLoading) {
199
+ submitBtn.disabled = true;
200
+ icon.style.display = 'none';
201
+ spinner.style.display = 'inline-block';
202
+ btnText.textContent = message;
203
+
204
+ resultContainer.className = 'loading';
205
+ resultContainer.innerHTML = `
206
+ <div class="generator-container">
207
+ <div class="text-overlay" id="loading-status-text">${message}</div>
208
+ <div class="progress-bar" style="width: 50%;"></div>
209
+ </div>`;
210
+ } else {
211
+ submitBtn.disabled = false;
212
+ icon.style.display = 'inline-block';
213
+ spinner.style.display = 'none';
214
+ btnText.textContent = 'خلق کن!';
215
+ }
216
+ };
217
+
218
+ submitBtn.addEventListener('click', async () => {
219
+ const userPrompt = promptInput.value.trim();
220
+ if (!userPrompt) return alert('لطفاً ایده خود را بنویسید.');
221
+
222
+ setLoadingState(true, 'در حال ترجمه متن و ارتباط با سرور...');
223
+ const dims = getDimensions(selectedRatio);
224
+
225
+ try {
226
+ // ارسال اطلاعات به بک‌اند داکر (که خودش به گیت هاب میفرستد)
227
+ // نکته مهم: ما action_name را generate-cartoon گذاشتیم تا گیت هاب بداند کدام مدل را اجرا کند
228
+ const res = await fetch('/api/generate', {
229
+ method: 'POST',
230
+ headers: {'Content-Type': 'application/json'},
231
+ body: JSON.stringify({
232
+ prompt: userPrompt + " کارتونی انیمیشن سه بعدی", // کلمه کلیدی برای راهنمایی مترجم
233
+ width: dims.width,
234
+ height: dims.height,
235
+ action_name: "generate-cartoon"
236
+ })
237
+ });
238
+
239
+ const data = await res.json();
240
+
241
+ if (data.status === 'success') {
242
+ document.getElementById('loading-status-text').textContent = 'در حال ساخت تصویر... (حدود ۴۵ ثانیه زمان میبرد)';
243
+ // شروع به پیگیری وضعیت از داکر
244
+ pollTimer = setInterval(() => checkResult(data.run_id), 3000);
245
+ } else {
246
+ alert('خطا در ارسال به گیت‌هاب!');
247
+ setLoadingState(false);
248
+ }
249
+ } catch (e) {
250
+ alert('خطای اتصال به سرور!');
251
+ setLoadingState(false);
252
+ }
253
+ });
254
+
255
+ async function checkResult(run_id) {
256
+ try {
257
+ const res = await fetch(`/api/status/${run_id}`);
258
+ const data = await res.json();
259
+
260
+ if (data.status === 'ready') {
261
+ clearInterval(pollTimer);
262
+ setLoadingState(false);
263
+
264
+ // نمایش عکس و دکمه دانلود
265
+ resultContainer.className = 'has-content';
266
+ resultContainer.innerHTML = `
267
+ <div id="result-image-wrapper" style="display: block;">
268
+ <img id="result-image-display" src="${data.url}" alt="تصویر کارتونی">
269
+ <div class="download-actions">
270
+ <a href="${data.url}" download="cartoon_image.webp" class="download-button">
271
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
272
+ <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
273
+ <polyline points="7 10 12 15 17 10"></polyline>
274
+ <line x1="12" y1="15" x2="12" y2="3"></line>
275
+ </svg>
276
+ <span>دانلود تصویر</span>
277
+ </a>
278
+ </div>
279
+ </div>`;
280
+ }
281
+ } catch(e) {
282
+ console.log('Polling...', e);
283
+ }
284
+ }
285
+
286
+ // --- کدهای مربوط به انتخاب سایز و مُدال ---
287
+ const customSizeModal = document.getElementById('custom-size-modal');
288
+
289
+ ratioSelector.addEventListener('click', (event) => {
290
+ const selectedOption = event.target.closest('.ratio-option');
291
+ if (!selectedOption) return;
292
+ const ratioValue = selectedOption.dataset.ratio;
293
+
294
+ if (ratioValue === 'custom') {
295
+ customSizeModal.style.display = 'flex';
296
+ } else {
297
+ ratioSelector.querySelectorAll('.ratio-option').forEach(opt => opt.classList.remove('active'));
298
+ selectedOption.classList.add('active');
299
+ selectedRatio = ratioValue;
300
+ }
301
+ });
302
+
303
+ document.getElementById('close-custom-modal-btn').addEventListener('click', () => { customSizeModal.style.display = 'none'; });
304
+
305
+ document.getElementById('confirm-custom-size-btn').addEventListener('click', () => {
306
+ const wInput = document.getElementById('custom-width-input').value;
307
+ const hInput = document.getElementById('custom-height-input').value;
308
+ customWidth = parseInt(wInput);
309
+ customHeight = parseInt(hInput);
310
+
311
+ selectedRatio = 'custom';
312
+ ratioSelector.querySelectorAll('.ratio-option').forEach(opt => opt.classList.remove('active'));
313
+ document.querySelector('.ratio-option[data-ratio="custom"]').classList.add('active');
314
+ document.getElementById('custom-ratio-label-value').textContent = `(${customWidth}x${customHeight})`;
315
+
316
+ customSizeModal.style.display = 'none';
317
+ });
318
+
319
+ // انیمیشن شبکه عصبی پس‌زمینه
320
+ document.addEventListener('DOMContentLoaded', () => {
321
+ const canvas = document.getElementById('neural-network-canvas');
322
+ if(!canvas) return; const header = canvas.parentElement; const ctx = canvas.getContext('2d');
323
+ let particles = []; const particleCount = 20; const maxDistance = 100;
324
+ const particleColor = '#4A6CFA'; const lineColor = '#8A94A6';
325
+ function resizeCanvas() { canvas.width = header.clientWidth; canvas.height = header.clientHeight; init(); }
326
+ class Particle { constructor() { this.x = Math.random() * canvas.width; this.y = Math.random() * canvas.height; this.vx = (Math.random() - 0.5) * 0.3; this.vy = (Math.random() - 0.5) * 0.3; this.radius = 1.2; } update() { this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > canvas.width) this.vx *= -1; if (this.y < 0 || this.y > canvas.height) this.vy *= -1; } draw() { ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2); ctx.fillStyle = particleColor; ctx.fill(); } }
327
+ function init() { particles = []; for (let i = 0; i < particleCount; i++) { particles.push(new Particle()); } }
328
+ function connectParticles() { for (let i = 0; i < particles.length; i++) { for (let j = i + 1; j < particles.length; j++) { const dx = particles[i].x - particles[j].x; const dy = particles[i].y - particles[j].y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < maxDistance) { ctx.beginPath(); ctx.moveTo(particles[i].x, particles[i].y); ctx.lineTo(particles[j].x, particles[j].y); ctx.strokeStyle = lineColor; ctx.lineWidth = 0.2; ctx.globalAlpha = 1 - distance / maxDistance; ctx.stroke(); } } } ctx.globalAlpha = 1; }
329
+ function animate() { if(!ctx) return; ctx.clearRect(0, 0, canvas.width, canvas.height); particles.forEach(particle => { particle.update(); particle.draw(); }); connectParticles(); requestAnimationFrame(animate); }
330
+ window.addEventListener('resize', resizeCanvas); resizeCanvas(); animate();
331
+ });
332
+ </script>
333
+ </body>
334
+ </html>