| <!DOCTYPE html> |
| <html lang="fa" dir="rtl"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>خلق تصاویر سبک میدجرنی</title> |
| <link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap" rel="stylesheet"> |
| <style> |
| :root { |
| --app-font: 'Vazirmatn', sans-serif; |
| --app-bg: #F8F9FC; |
| --panel-bg: #FFFFFF; |
| --panel-border: #EAEFF7; |
| --input-bg: #F6F8FB; |
| --input-border: #E1E7EF; |
| --text-primary: #1A202C; |
| --text-secondary: #626F86; |
| --text-tertiary: #8A94A6; |
| --accent-primary: #8B5CF6; |
| --accent-primary-hover: #7C3AED; |
| --accent-primary-glow: rgba(139, 92, 246, 0.25); |
| --accent-secondary: #EC4899; |
| --shadow-sm: 0 1px 2px 0 rgba(26, 32, 44, 0.03); |
| --shadow-md: 0 4px 6px -1px rgba(26, 32, 44, 0.05), 0 2px 4px -2px rgba(26, 32, 44, 0.04); |
| --shadow-lg: 0 10px 15px -3px rgba(26, 32, 44, 0.06), 0 4px 6px -4px rgba(26, 32, 44, 0.05); |
| --shadow-xl: 0 20px 25px -5px rgba(26, 32, 44, 0.07), 0 8px 10px -6px rgba(26, 32, 44, 0.05); |
| --radius-card: 24px; |
| --radius-btn: 14px; |
| --radius-input: 12px; |
| --transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1); |
| } |
| |
| @keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } } |
| @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } |
| @keyframes pulse { 0% { box-shadow: 0 0 40px rgba(139, 92, 246, 0.3); } 50% { box-shadow: 0 0 60px rgba(139, 92, 246, 0.7); } 100% { box-shadow: 0 0 40px rgba(139, 92, 246, 0.3); } } |
| @keyframes glow-text { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } } |
| |
| 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; align-items: flex-start; min-height: 100vh; } |
| .container { max-width: 820px; width: 100%; } |
| |
| header { position: relative; text-align: center; margin-bottom: 2.5rem; padding: 2rem 0; animation: fadeIn 0.8s 0.1s ease-out backwards; overflow: hidden; } |
| #neural-network-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; } |
| h1, .subtitle { position: relative; z-index: 2; } |
| 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; letter-spacing: -1px; } |
| .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; } |
| |
| 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; } |
| |
| .form-group { margin-bottom: 2.5rem; } |
| .form-group:last-child { margin-bottom: 0; } |
| |
| .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; } |
| .form-label svg { width: 24px; height: 24px; color: var(--accent-primary); } |
| |
| textarea { width: 100%; padding: 1rem 1.2rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); color: var(--text-primary); box-shadow: var(--shadow-sm) inset; font-family: var(--app-font); font-size: 1rem; box-sizing: border-box; transition: var(--transition-smooth); min-height: 90px; resize: vertical; } |
| textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow), var(--shadow-sm) inset; background-color: var(--panel-bg); } |
| |
| .aspect-ratio-selector { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; } |
| .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; } |
| .ratio-option:hover { border-color: var(--accent-primary); transform: translateY(-4px); box-shadow: var(--shadow-md); } |
| .ratio-option.active { border-color: var(--accent-primary); background-color: #fff; box-shadow: 0 0 0 3px var(--accent-primary-glow); } |
| .ratio-icon { height: 50px; display: flex; align-items: center; justify-content: center; margin: 0 auto 0.75rem; } |
| .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; } |
| .ratio-option.active .ratio-icon > div, .ratio-option.active .ratio-icon > svg { border-color: var(--accent-primary); background-color: var(--accent-primary-glow); } |
| .ratio-label { font-weight: 600; color: var(--text-secondary); font-size: 0.9rem; transition: color 0.2s; } |
| .ratio-option.active .ratio-label { color: var(--text-primary); } |
| |
| #icon-portrait > div { width: 28px; height: 50px; } |
| #icon-landscape > div { width: 60px; height: 34px; } |
| #icon-square > div { width: 45px; height: 45px; } |
| #icon-custom > svg { width: 45px; height: 45px; padding: 8px; color: var(--text-tertiary); } |
| .ratio-option.active #icon-custom > svg { color: var(--accent-primary); } |
| .custom-ratio-value { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; height: 1em; } |
| |
| #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), 0 6px 12px -3px rgba(236, 72, 153, 0.3); margin-top: 1.5rem; } |
| #submit-btn svg { width: 24px; height: 24px; margin-left: 4px; filter: drop-shadow(0 0 5px rgba(255,255,255,0.5)); } |
| #submit-btn:hover:not(:disabled) { transform: translateY(-5px) scale(1.02); box-shadow: 0 8px 20px -4px var(--accent-primary-glow), 0 8px 20px -4px rgba(236, 72, 153, 0.4); } |
| #submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; box-shadow: none; opacity: 0.7; transform: none; } |
| #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; } |
| |
| #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); box-shadow: var(--shadow-sm) inset; transition: var(--transition-smooth); display: flex; align-items: center; justify-content: center; flex-direction: column; box-sizing: border-box; } |
| #result-container.loading { padding: 0; border: none; background-color: transparent; box-shadow: none; } |
| #result-container.has-content { border-style: solid; border-color: var(--panel-border); padding: 1rem; } |
| |
| .generator-container { position: relative; width: 100%; max-width: 500px; height: 200px; border: 2px solid #a78bfa; border-radius: 20px; overflow: hidden; box-shadow: 0 0 40px rgba(139, 92, 246, 0.3); animation: pulse 5s infinite cubic-bezier(0.4, 0, 0.6, 1); background-color: #161b22; color: #f0f6fc; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 1rem; } |
| .text-overlay { font-size: 18px; font-weight: 700; text-shadow: 0 0 20px rgba(139, 92, 246, 0.8); animation: glow-text 7s infinite ease-in-out; text-align: center; } |
| .progress-bar { position: absolute; bottom: 0; left: 0; width: 0%; height: 6px; background: linear-gradient(to right, #8B5CF6, #EC4899, #F59E0B); transition: width 1s linear; } |
| |
| #result-image-wrapper { display: none; width: 100%; text-align: center; } |
| #result-container.has-content #result-image-wrapper { display: block; animation: fadeIn 0.5s; } |
| #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); } |
| |
| .download-button { display: inline-flex; align-items: center; justify-content: center; gap: 0.75rem; width: 100%; max-width: 280px; margin: 1.5rem auto 0; padding: 0.9rem; font-size: 1rem; font-weight: 600; background: var(--accent-primary); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; transition: all 0.3s ease; box-shadow: var(--shadow-md); text-decoration: none;} |
| .download-button svg { width: 20px; height: 20px; } |
| .download-button:hover { background: var(--accent-primary-hover); transform: translateY(-3px); box-shadow: var(--shadow-lg); } |
| |
| .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; animation: fadeIn 0.3s; } |
| .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; } |
| .modal-content-small h3 { margin-top: 0; margin-bottom: 1.5rem; font-size: 1.5rem; color: var(--text-primary); } |
| .modal-content-small .input-group { margin-bottom: 1rem; text-align: right; } |
| .modal-content-small label { display: block; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-secondary); font-size: 0.9rem; } |
| .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); color: var(--text-primary); box-shadow: var(--shadow-sm) inset; font-family: var(--app-font); font-size: 1rem; box-sizing: border-box; transition: var(--transition-smooth); } |
| .modal-content-small input:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow), var(--shadow-sm) inset; background-color: var(--panel-bg); } |
| #confirm-custom-size-btn { width: 100%; padding: 0.9rem; margin-top: 1rem; font-size: 1rem; font-weight: 700; background-color: var(--accent-primary); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; transition: var(--transition-smooth); } |
| #confirm-custom-size-btn:hover { background-color: var(--accent-primary-hover); } |
| #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; } |
| |
| @media (max-width: 768px) { main { padding: 1.5rem; } h1 { font-size: 2.2rem; } .aspect-ratio-selector { grid-template-columns: repeat(2, 1fr); } } |
| </style> |
| </head> |
| <body> |
| <div class="container"> |
| <header> |
| <canvas id="neural-network-canvas"></canvas> |
| <h1>خلق تصاویر سبک میدجرنی</h1> |
| <p class="subtitle">ایدههای خود را با سبک واقعگرایانه و هنری Midjourney v6 به تصویر بکشید</p> |
| </header> |
| <main> |
| <div class="form-group"> |
| <div class="form-label"> |
| <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> |
| ۱. ایده خود را توصیف کنید |
| </div> |
| <textarea id="prompt-input" rows="3" placeholder="مثال: پرتره یک پیرمرد با نورپردازی سینمایی، کیفیت بسیار بالا"></textarea> |
| </div> |
|
|
| <div class="form-group"> |
| <div class="form-label"> |
| <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> |
| ۲. اندازه تصویر را انتخاب کنید |
| </div> |
| <div class="aspect-ratio-selector" id="aspect-ratio-selector"> |
| <div class="ratio-option" data-ratio="9:16"> |
| <div class="ratio-icon" id="icon-portrait"><div></div></div> |
| <div class="ratio-label">عمودی ۹:۱۶</div> |
| </div> |
| <div class="ratio-option" data-ratio="16:9"> |
| <div class="ratio-icon" id="icon-landscape"><div></div></div> |
| <div class="ratio-label">افقی ۱۶:۹</div> |
| </div> |
| <div class="ratio-option" data-ratio="custom"> |
| <div class="ratio-icon" id="icon-custom"> |
| <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> |
| </div> |
| <div class="ratio-label"> |
| اندازه دلخواه |
| <div class="custom-ratio-value" id="custom-ratio-label-value"></div> |
| </div> |
| </div> |
| <div class="ratio-option active" data-ratio="1:1"> |
| <div class="ratio-icon" id="icon-square"><div></div></div> |
| <div class="ratio-label">مربع ۱:۱</div> |
| </div> |
| </div> |
| </div> |
| |
| <button id="submit-btn"> |
| <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> |
| <span id="btn-text">خلق کن!</span> |
| <div class="spinner" style="display: none;"></div> |
| </button> |
| |
| <div class="form-group" style="margin-top: 3rem; margin-bottom: 0;"> |
| <div class="form-label"> |
| <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"/><path d="M19.5 2.5l-3 1.5 1.5 3 3-1.5-1.5-3z"/></svg> |
| ۳. نتیجه را ببینید |
| </div> |
| <div id="result-container"> |
| <p id="idle-text">برای شروع، ایده خود را نوشته و دکمه را بزنید.</p> |
| </div> |
| </div> |
| </main> |
| </div> |
|
|
| |
| <div class="modal-overlay" id="custom-size-modal"> |
| <div class="modal-content-small"> |
| <button id="close-custom-modal-btn">×</button> |
| <h3>تنظیم اندازه دلخواه</h3> |
| <div class="input-group"> |
| <label>عرض (Width)</label> |
| <input type="number" id="custom-width-input" value="1024" min="512" max="1536" step="8"> |
| </div> |
| <div class="input-group"> |
| <label>طول (Height)</label> |
| <input type="number" id="custom-height-input" value="1024" min="512" max="1536" step="8"> |
| </div> |
| <button id="confirm-custom-size-btn">تایید و اعمال</button> |
| </div> |
| </div> |
|
|
| <script> |
| const promptInput = document.getElementById('prompt-input'); |
| const submitBtn = document.getElementById('submit-btn'); |
| const resultContainer = document.getElementById('result-container'); |
| const ratioSelector = document.getElementById('aspect-ratio-selector'); |
| const customSizeModal = document.getElementById('custom-size-modal'); |
| |
| let selectedRatio = '1:1'; |
| let customWidth = 1024; |
| let customHeight = 1024; |
| let pollTimer = null; |
| |
| const getDimensions = (ratio) => { |
| if (ratio === 'custom') return { width: customWidth, height: customHeight }; |
| switch (ratio) { |
| case '9:16': return { width: 768, height: 1344 }; |
| case '16:9': return { width: 1344, height: 768 }; |
| case '1:1': return { width: 1024, height: 1024 }; |
| default: return { width: 1024, height: 1024 }; |
| } |
| }; |
| |
| const setLoadingState = (isLoading, message) => { |
| const spinner = submitBtn.querySelector('.spinner'); |
| const icon = submitBtn.querySelector('svg'); |
| const btnText = document.getElementById('btn-text'); |
| |
| if (isLoading) { |
| submitBtn.disabled = true; |
| icon.style.display = 'none'; |
| spinner.style.display = 'inline-block'; |
| btnText.textContent = message; |
| |
| resultContainer.className = 'loading'; |
| resultContainer.innerHTML = ` |
| <div class="generator-container"> |
| <div class="text-overlay" id="loading-status-text">${message}</div> |
| <div class="progress-bar" style="width: 50%;"></div> |
| </div>`; |
| } else { |
| submitBtn.disabled = false; |
| icon.style.display = 'inline-block'; |
| spinner.style.display = 'none'; |
| btnText.textContent = 'خلق کن!'; |
| } |
| }; |
| |
| submitBtn.addEventListener('click', async () => { |
| const userPrompt = promptInput.value.trim(); |
| if (!userPrompt) return alert('لطفاً ایده خود را بنویسید.'); |
| |
| setLoadingState(true, 'در حال ارتباط با سرور و ترجمه...'); |
| const dims = getDimensions(selectedRatio); |
| |
| try { |
| |
| const res = await fetch('/api/generate', { |
| method: 'POST', |
| headers: {'Content-Type': 'application/json'}, |
| body: JSON.stringify({ |
| prompt: userPrompt, |
| width: dims.width, |
| height: dims.height, |
| action_name: "generate-midjourney" |
| }) |
| }); |
| |
| const data = await res.json(); |
| |
| if (data.status === 'success') { |
| document.getElementById('loading-status-text').textContent = 'در حال ساخت تصویر با مدل میدجرنی... (حدود ۴۵ ثانیه زمان میبرد)'; |
| pollTimer = setInterval(() => checkResult(data.run_id), 3000); |
| } else { |
| alert('خطا در ارسال به گیتهاب!'); |
| setLoadingState(false); |
| } |
| } catch (e) { |
| alert('خطای اتصال به سرور داکر!'); |
| setLoadingState(false); |
| } |
| }); |
| |
| async function checkResult(run_id) { |
| try { |
| const res = await fetch(`/api/status/${run_id}`); |
| const data = await res.json(); |
| |
| if (data.status === 'ready') { |
| clearInterval(pollTimer); |
| setLoadingState(false); |
| |
| resultContainer.className = 'has-content'; |
| resultContainer.innerHTML = ` |
| <div id="result-image-wrapper" style="display: block;"> |
| <img id="result-image-display" src="${data.url}" alt="تصویر میدجرنی"> |
| <div> |
| <a href="${data.url}" download="midjourney_image.webp" class="download-button"> |
| <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 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path> |
| <polyline points="7 10 12 15 17 10"></polyline> |
| <line x1="12" y1="15" x2="12" y2="3"></line> |
| </svg> |
| <span>دانلود تصویر</span> |
| </a> |
| </div> |
| </div>`; |
| } |
| } catch(e) { |
| console.log('در حال پیگیری...', e); |
| } |
| } |
| |
| |
| ratioSelector.addEventListener('click', (event) => { |
| const selectedOption = event.target.closest('.ratio-option'); |
| if (!selectedOption) return; |
| const ratioValue = selectedOption.dataset.ratio; |
| |
| if (ratioValue === 'custom') { |
| customSizeModal.style.display = 'flex'; |
| } else { |
| ratioSelector.querySelectorAll('.ratio-option').forEach(opt => opt.classList.remove('active')); |
| selectedOption.classList.add('active'); |
| selectedRatio = ratioValue; |
| } |
| }); |
| |
| document.getElementById('close-custom-modal-btn').addEventListener('click', () => { customSizeModal.style.display = 'none'; }); |
| document.getElementById('confirm-custom-size-btn').addEventListener('click', () => { |
| customWidth = parseInt(document.getElementById('custom-width-input').value, 10); |
| customHeight = parseInt(document.getElementById('custom-height-input').value, 10); |
| |
| selectedRatio = 'custom'; |
| ratioSelector.querySelectorAll('.ratio-option').forEach(opt => opt.classList.remove('active')); |
| document.querySelector('.ratio-option[data-ratio="custom"]').classList.add('active'); |
| document.getElementById('custom-ratio-label-value').textContent = `(${customWidth}x${customHeight})`; |
| customSizeModal.style.display = 'none'; |
| }); |
| |
| |
| document.addEventListener('DOMContentLoaded', () => { |
| const canvas = document.getElementById('neural-network-canvas'); |
| if(!canvas) return; const header = canvas.parentElement; const ctx = canvas.getContext('2d'); |
| let particles = []; const particleCount = 20; const maxDistance = 100; |
| const particleColor = '#8B5CF6'; const lineColor = '#8A94A6'; |
| function resizeCanvas() { canvas.width = header.clientWidth; canvas.height = header.clientHeight; init(); } |
| 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(); } } |
| function init() { particles = []; for (let i = 0; i < particleCount; i++) { particles.push(new Particle()); } } |
| 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; } |
| function animate() { if(!ctx) return; ctx.clearRect(0, 0, canvas.width, canvas.height); particles.forEach(particle => { particle.update(); particle.draw(); }); connectParticles(); requestAnimationFrame(animate); } |
| window.addEventListener('resize', resizeCanvas); resizeCanvas(); animate(); |
| }); |
| </script> |
| </body> |
| </html> |