-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathani3.html
133 lines (113 loc) · 4.46 KB
/
ani3.html
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
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MAAS Network Animation</title>
<style>
body { margin: 0; overflow: hidden; background: white; }
canvas { display: block; position: absolute; }
#textCanvas {
position: absolute;
top: 0;
left: 0;
pointer-events: none; /* Allow interactions with WebGL */
}
</style>
</head>
<body>
<canvas id="glCanvas"></canvas>
<canvas id="textCanvas"></canvas> <!-- Separate canvas for text -->
<script>
const canvas = document.getElementById("glCanvas");
const textCanvas = document.getElementById("textCanvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
textCanvas.width = window.innerWidth;
textCanvas.height = window.innerHeight;
const gl = canvas.getContext("webgl");
const ctx = textCanvas.getContext("2d"); // 2D context for text
if (!gl) {
alert("WebGL not supported");
}
gl.clearColor(1.0, 1.0, 1.0, 1.0); // White background
gl.clear(gl.COLOR_BUFFER_BIT);
// WebGL Shader Programs
const vertexShaderSource = `
attribute vec2 a_position;
void main() {
gl_Position = vec4(a_position, 0.0, 1.0);
}
`;
const fragmentShaderSource = `
precision mediump float;
uniform vec4 u_color;
void main() {
gl_FragColor = u_color;
}
`;
function createShader(gl, type, source) {
const shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
console.error("Shader compile failed", gl.getShaderInfoLog(shader));
gl.deleteShader(shader);
return null;
}
return shader;
}
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
const program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.error("Program link failed", gl.getProgramInfoLog(program));
}
gl.useProgram(program);
const positionLocation = gl.getAttribLocation(program, "a_position");
const colorLocation = gl.getUniformLocation(program, "u_color");
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.enableVertexAttribArray(positionLocation);
gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);
function drawRectangle(x, y, width, height, color) {
const x1 = x, x2 = x + width;
const y1 = y, y2 = y - height;
const vertices = new Float32Array([
x1, y1, x2, y1, x1, y2,
x2, y1, x2, y2, x1, y2
]);
gl.uniform4fv(colorLocation, color);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
gl.drawArrays(gl.TRIANGLES, 0, 6);
}
function drawText() {
ctx.clearRect(0, 0, textCanvas.width, textCanvas.height);
ctx.fillStyle = 'white';
ctx.font = '30px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText('Region', textCanvas.width * 0.2, textCanvas.height * 0.3);
}
function render() {
gl.clear(gl.COLOR_BUFFER_BIT);
// Draw Region Controller (Blue Box)
drawRectangle(-0.9, 0.6, 0.3, 0.2, [0.0, 0.0, 1.0, 1.0]);
// Draw Rack Controller (Green Box)
drawRectangle(-0.3, 0.3, 0.2, 0.2, [0.0, 1.0, 0.0, 1.0]);
// Draw Machines in Rack (Gray Boxes)
let machineX = -0.1;
for (let i = 0; i < 5; i++) {
drawRectangle(machineX, -0.2, 0.15, 0.15, [0.5, 0.5, 0.5, 1.0]);
machineX += 0.2;
}
drawText();
requestAnimationFrame(render);
}
render();
</script>
</body>
</html>