-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (57 loc) · 2.01 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
document.addEventListener("DOMContentLoaded", function() {
const canvas = document.getElementById("buddhistFlag");
const context = canvas.getContext("2d");
// Flag dimensions
const width = canvas.width;
const height = canvas.height;
const bandWidth = width / 6;
// Colors
const colors = [
"#0033cc",
"#ffcc00",
"#ff3300",
"#ffffff",
"#ff9933",
];
// Draw each color band
function drawBand(color, index, callback) {
setTimeout(() => {
context.fillStyle = color;
context.fillRect(index * bandWidth, 0, bandWidth, height);
if (callback) callback();
}, index * 1000); // Delay in milliseconds
}
// Draw the combined color band
function drawCombinedBand(callback) {
const combinedColors = colors.concat(colors[0]);
const combinedBandStart = 5 * bandWidth;
const combinedBandHeight = height / 5;
combinedColors.forEach((color, index) => {
setTimeout(() => {
context.fillStyle = color;
context.fillRect(combinedBandStart, index * combinedBandHeight, bandWidth, combinedBandHeight);
if (index === combinedColors.length - 1 && callback) {
callback();
}
}, index * 500);
});
}
// Clear the canvas and start the drawing process
function startDrawing() {
context.clearRect(0, 0, width, height);
// Draw each color band in sequence
colors.forEach((color, index) => {
drawBand(color, index, () => {
if (index === colors.length - 1) {
setTimeout(() => {
drawCombinedBand(() => {
setTimeout(startDrawing, 1000);
});
}, 1000);
}
});
});
}
// Start the drawing process
startDrawing();
});