-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
92 lines (81 loc) · 2.8 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
document.getElementById('send-button').addEventListener('click', sendMessage);
function sendMessage() {
const input = document.getElementById('message-input');
const message = input.value.trim();
if (message) {
displayMessage(message, 'user');
input.value = '';
// Send the message to the Flask backend
fetch('/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: message }),
})
.then(response => response.json())
.then(data => {
displayMessage(data.response, 'bot');
})
.catch(error => {
console.error('Error:', error);
});
}
}
function displayMessage(message, sender) {
const chatBox = document.getElementById('chat-box');
const messageDiv = document.createElement('div');
messageDiv.className = sender === 'user' ? 'user-message' : 'bot-message';
messageDiv.textContent = message;
chatBox.appendChild(messageDiv);
chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
}
const canvas = document.getElementById('particle-canvas');
const ctx = canvas.getContext('2d');
let particles = [];
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
class Particle {
constructor(x, y, dx, dy, size) {
this.x = x;
this.y = y;
this.dx = dx;
this.dy = dy;
this.size = size;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false);
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
ctx.fill();
}
update() {
if (this.x + this.size > canvas.width || this.x - this.size < 0) {
this.dx = -this.dx;
}
if (this.y + this.size > canvas.height || this.y - this.size < 0) {
this.dy = -this.dy;
}
this.x += this.dx;
this.y += this.dy;
this.draw();
}
}
function initParticles() {
particles = [];
for (let i = 0; i < 100; i++) {
const size = Math.random() * 5 + 1;
const x = Math.random() * (canvas.width - size * 2) + size;
const y = Math.random() * (canvas.height - size * 2) + size;
const dx = (Math.random() - 0.5) * 2;
const dy = (Math.random() - 0.5) * 2;
particles.push(new Particle(x, y, dx, dy, size));
}
}
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(particle => particle.update());
requestAnimationFrame(animateParticles);
}
initParticles();
animateParticles();