Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / 03-Practice-24.10.2022 / Problem 0302.html
diff options
context:
space:
mode:
Commit2fb13b2c94e73ae8a4112df8ad98d092906e76ba (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-10-24 19:54:15 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-10-24 19:54:15 +0300
Files3ba635616a587d88cc5d9649547a1acdb9409e07 /Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0302.html
uni-projects-2fb13b2c94e73ae8a4112df8ad98d092906e76ba.tar
uni-projects-2fb13b2c94e73ae8a4112df8ad98d092906e76ba.tar.gz
uni-projects-2fb13b2c94e73ae8a4112df8ad98d092906e76ba.zip
Parentb9a7524716a2e9d4ab1d92fe7fb954265d3ce3a4 (diff)
[WGL/P03] Added work from practicum
1 files changed, 82 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0302.html82
diff --git a/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0302.html b/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0302.html
new file mode 100644
index 0000000..9d60b02
--- /dev/null
+++ b/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0302.html
@@ -0,0 +1,82 @@
+<!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;
+ #define PI 3.14159
+ #define TEETH 30.0
+ #define RADIUS 0.8
+
+ void main ()
+ {
+ // тук трябва да се сметне точния радиус
+ float r = RADIUS - mod(aAngle, 2.0 * PI / TEETH) * 0.4;
+ float angle = aAngle;
+ if (r == RADIUS) angle -= 100.0;
+ if (angle < 0.0) angle = 0.0; // ugly
+ gl_Position = vec4(r*cos(angle)/1.5,r*sin(angle),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");
+
+ aAngle = gl.getAttribLocation(glprog,"aAngle");
+ uColor = gl.getUniformLocation(glprog,"uColor");
+
+ gl.clearColor(1,1,1,1);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ // точки по зъбното колело
+ var n = 360;
+
+ // 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.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>