-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
124 lines (106 loc) · 3.44 KB
/
script.js
File metadata and controls
124 lines (106 loc) · 3.44 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function calculateAnnualFees()
{
let creditHours = parseFloat(document.getElementById('creditHours').value);
let isSSE = document.getElementById('isSSE').checked;
let perCreditHourFee = 37070;
let registrationFeePerSemester = 48210;
let sseFeePerSemester = isSSE ? 115620 : 0;
let semesterFees = registrationFeePerSemester + sseFeePerSemester;
let annualFees = Math.round((creditHours * perCreditHourFee) + semesterFees * 2);
let formattedFees = annualFees.toLocaleString();
document.getElementById('annualFees').textContent = formattedFees;
}
const canvas = document.getElementById('backgroundCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const footerHeight = 40;
window.addEventListener('resize', function()
{
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
initBoxes();
}
);
let boxes = [];
const numBoxes = 20;
class Box
{
constructor(x, y, size, dx, dy, rotationSpeed, type)
{
this.x = x;
this.y = y;
this.size = size;
this.dx = dx;
this.dy = dy;
this.rotation = 0;
this.rotationSpeed = rotationSpeed;
this.type = type;
}
draw()
{
ctx.save();
ctx.translate(this.x + this.size / 2, this.y + this.size / 2);
ctx.rotate(this.rotation);
switch (this.type)
{
case 'triangle':
ctx.beginPath();
ctx.moveTo(0, -this.size / 2);
ctx.lineTo(this.size / 2, this.size / 2);
ctx.lineTo(-this.size / 2, this.size / 2);
ctx.closePath();
ctx.fillStyle = '#FFD700';
ctx.fill();
break;
case 'square':
ctx.fillStyle = '#008000';
ctx.fillRect(-this.size / 2, -this.size / 2, this.size, this.size);
break;
case 'dinosaur':
ctx.font = `${this.size}px Arial`;
ctx.fillText('🦕', -this.size / 2, this.size / 2);
break;
}
ctx.restore();
}
update()
{
this.x += this.dx;
this.y += this.dy;
this.rotation += this.rotationSpeed;
if (this.x + this.size > canvas.width || this.x < 0)
{
this.dx = -this.dx;
}
if (this.y + this.size > canvas.height - footerHeight || this.y < 0)
{
this.dy = -this.dy;
}
}
}
function initBoxes()
{
boxes = [];
for (let i = 0; i < numBoxes; i++)
{
let size = Math.random() * 20 + 30;
let x = Math.random() * (canvas.width - size);
let y = Math.random() * (canvas.height - size - footerHeight);
let dx = (Math.random() - 0.5) * 4;
let dy = (Math.random() - 0.5) * 4;
let rotationSpeed = Math.random() * 0.04 - 0.02;
let types = ['triangle', 'square', 'dinosaur'];
let type = types[Math.floor(Math.random() * types.length)];
boxes.push(new Box(x, y, size, dx, dy, rotationSpeed, type));
}
}
function animate()
{
requestAnimationFrame(animate);
ctx.clearRect(0, 0, canvas.width, canvas.height);
boxes.forEach(box => box.update());
boxes.forEach(box => box.draw());
}
initBoxes();
animate();