Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / 03-Practice-24.10.2022 / Problem 0303.html
diff options
context:
space:
mode:
Commitac8f5cfaa7a1752e7ba0e62aa40d4bc785e5be34 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-10-25 18:32:17 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-10-25 18:32:17 +0300
Filesf5b0b7fb011750eabdc96a9d8266b5931349f599 /Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0303.html
uni-projects-ac8f5cfaa7a1752e7ba0e62aa40d4bc785e5be34.tar
uni-projects-ac8f5cfaa7a1752e7ba0e62aa40d4bc785e5be34.tar.gz
uni-projects-ac8f5cfaa7a1752e7ba0e62aa40d4bc785e5be34.zip
Parenta45f695ebd7b64dfe5cdb911c51d65a5c8eb2cbe (diff)
[WGL/P04] Solved exercises 2-5
1 files changed, 103 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0303.html103
diff --git a/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0303.html b/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0303.html
new file mode 100644
index 0000000..f99c783
--- /dev/null
+++ b/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0303.html
@@ -0,0 +1,103 @@
+<!DOCTYPE html>
+
+<head>
+ <meta charset="utf-8"/>
+ <title>Зъбно колело</title>
+
+ <script src="webgl-fmi.js"></script>
+
+ <script id="vshader" type="x-shader/x-vertex">
+ // ъгъл по зъбното колело
+ attribute float aAngle;
+
+ attribute float aMin;
+ attribute float aMax;
+ attribute float aRadius;
+ attribute float aFluct;
+ #define TEETH 11.0
+
+ void main ()
+ {
+ // тук да се оправи да се рисуват елементите на
+ // зъбното колело - както зъбчатата част, така
+ // и кръглата и плътно кръглата
+ float r = aRadius + aFluct * clamp(sin(aAngle * TEETH), aMin, aMax);
+
+ gl_Position = vec4(r * cos(aAngle)/1.5, r * sin(aAngle),0,1);
+ }
+ </script>
+
+ <script id="fshader" type="x-shader/x-fragment">
+ precision mediump float;
+ uniform vec3 uColor;
+ void main( )
+ {
+ gl_FragColor = vec4(uColor,1);
+ }
+ </script>
+
+ <script>
+ function start( )
+ {
+ gl = getContext("picasso");
+ glprog = getProgram("vshader","fshader");
+
+ uColor = gl.getUniformLocation(glprog,"uColor");
+ aAngle = gl.getAttribLocation(glprog,"aAngle");
+ aMin = gl.getAttribLocation(glprog, "aMin");
+ aMax = gl.getAttribLocation(glprog, "aMax");
+ aRadius = gl.getAttribLocation(glprog, "aRadius");
+ aFluct = gl.getAttribLocation(glprog, "aFluct");
+
+ gl.clearColor(1,1,1,1);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ // точки по зъбното колело
+ var n = 500;
+
+ // n ъгъла от 0 до 2*pi
+ var data = [];
+ for(var i=0; i<n; i++) data.push(2*Math.PI*i/n);
+
+ var buf = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER,buf);
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW);
+
+ gl.uniform3f(uColor,0.3,0.7,0.2);
+ gl.enableVertexAttribArray(aAngle);
+ gl.vertexAttribPointer(aAngle,1,gl.FLOAT,false,0,0);
+
+ gl.vertexAttrib1f(aRadius, 0.8);
+ gl.vertexAttrib1f(aFluct, 0.2);
+ gl.vertexAttrib1f(aMin, -0.5);
+ gl.vertexAttrib1f(aMax, 0.5);
+ gl.drawArrays(gl.LINE_LOOP,0,n);
+
+ gl.vertexAttrib1f(aRadius, 0.55);
+ gl.vertexAttrib1f(aFluct, 0.0);
+ gl.drawArrays(gl.LINE_LOOP,0,n);
+
+ gl.vertexAttrib1f(aRadius, 0.52);
+ gl.drawArrays(gl.LINE_LOOP,0,n);
+
+ var radius = 0.1;
+ var steps = 100;
+ for (var i = 0; i < 100; i++) {
+ gl.vertexAttrib1f(aRadius, radius * i / steps);
+ gl.drawArrays(gl.LINE_LOOP,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>