diff options
[WGL/P02] Solved practicum exercises
1 files changed, 64 insertions, 0 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0201.html | 64 |
diff --git a/Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0201.html b/Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0201.html new file mode 100644 index 0000000..f0f22bf --- /dev/null +++ b/Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0201.html @@ -0,0 +1,64 @@ +<!DOCTYPE html>
+
+<head>
+ <meta charset="utf-8"/>
+ <title>Септагон</title>
+
+ <script src="webgl-fmi.js"></script>
+
+ <script id="vshader" type="x-shader/x-vertex">
+ attribute vec2 aXY;
+ void main ()
+ {
+ gl_Position = vec4(aXY,0,1);
+ gl_PointSize = 10.0;
+ }
+ </script>
+
+ <script id="fshader" type="x-shader/x-fragment">
+ void main( )
+ {
+ gl_FragColor = vec4(0,0,0,1);
+ }
+ </script>
+
+ <script>
+ function start( )
+ {
+ gl = getContext("picasso");
+ glprog = getProgram("vshader","fshader");
+
+ aXY = gl.getAttribLocation(glprog,"aXY");
+
+ gl.clearColor(1,1,1,1);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ var data = [ ]; // В този масив трябва да са 7-те точки
+ const aspectRatio = 600 / 400;
+ const n = 7;
+ const r = 0.8;
+
+ for (var i = 1; i <= n; i++)
+ data.push(Math.sin(2.0 * Math.PI * i / n) * r / aspectRatio, Math.cos(2.0 * Math.PI * i / n) * r);
+
+ var buf = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, buf);
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW);
+ gl.vertexAttribPointer(aXY, 2, gl.FLOAT, false, 0, 0);
+ gl.enableVertexAttribArray(aXY);
+ gl.drawArrays(gl.POINTS, 0, n);
+ }
+ </script>
+</head>
+
+<body onload="start()">
+ <h2>Септагон</h2>
+
+ <noscript>
+ Искаме JavaScript, но няма!
+ </noscript>
+
+ <canvas id="picasso" width="600" height="400" style="border: solid;">
+ Искаме canvas, но няма!
+ </canvas>
+</body>
|
