-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoolanimaltion.html
More file actions
73 lines (63 loc) · 2.13 KB
/
coolanimaltion.html
File metadata and controls
73 lines (63 loc) · 2.13 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Infinite Zooming Fractal</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="fractalCanvas"></canvas>
<script>
const canvas = document.getElementById('fractalCanvas');
const ctx = canvas.getContext('2d');
// Set canvas size
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Set initial parameters
const centerX = -0.5;
const centerY = 0;
const initialZoom = 2;
let zoom = initialZoom;
// Function to draw the Mandelbrot set
function drawMandelbrot() {
for (let x = 0; x < canvas.width; x++) {
for (let y = 0; y < canvas.height; y++) {
const zx = 1.5 * (x - canvas.width / 2) / (0.5 * zoom * canvas.width) + centerX;
const zy = (y - canvas.height / 2) / (0.5 * zoom * canvas.height) + centerY;
let zx2 = zx;
let zy2 = zy;
let iteration = 0;
while (iteration < 100 && zx2 + zy2 < 4) {
const temp = zx2 * zx2 - zy2 * zy2 + zx;
zy2 = 2 * zx2 * zy2 + zy;
zx2 = temp;
iteration++;
}
const color = iteration === 100 ? 'black' : `hsl(${iteration * 3}, 100%, 50%)`;
ctx.fillStyle = color;
ctx.fillRect(x, y, 1, 1);
}
}
}
// Function to handle zooming
function handleZoom(event) {
const scale = event.deltaY > 0 ? 1.1 : 0.9;
zoom *= scale;
drawMandelbrot();
}
// Add event listener for zooming
canvas.addEventListener('wheel', handleZoom);
// Initial drawing
drawMandelbrot();
</script>
</body>
</html>