Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / 03-Practice-24.10.2022 / Problem 0304.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 0304.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, 100 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0304.html100
diff --git a/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0304.html b/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0304.html
new file mode 100644
index 0000000..de68f89
--- /dev/null
+++ b/Year 2/Computer Graphics with WebGL/03-Practice-24.10.2022/Problem 0304.html
@@ -0,0 +1,100 @@
+<!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 aAngleCount;
+ #define PI 3.14159
+ #define BUMPS 6.0
+ #define RADIUS 0.7
+ #define FLUCT 0.18
+ #define COIL_FLUCT 0.04
+
+ #define ANGLE_UNIT (2.0 * PI / aAngleCount)
+ #define MULTIPLICITY (6.0 * PI / 180.0)
+
+ void main ()
+ {
+ // Нормална точка от "звездата"
+ float r = RADIUS + FLUCT * sin(aAngle * BUMPS);
+ gl_Position = vec4(r * cos(aAngle)/1.5, r * sin(aAngle),0,1);
+
+ // Височината на отместване за намотката
+ float coilHeight = COIL_FLUCT * sin(aAngle / ANGLE_UNIT * MULTIPLICITY);
+ // Тангенциалния вектор на сегашната точка от синусоидата на звездата
+ vec2 p = vec2(-cos(aAngle * BUMPS) * BUMPS);
+ // Обръщаме тангенциалният вектор за да компенсираме за кръговидното поставяне на синусоидата на звездата
+ float rotateBy = aAngle - PI / 2.0;
+ p = mat2(cos(rotateBy), -sin(rotateBy), sin(rotateBy), cos(rotateBy)) * p;
+
+ gl_Position = vec4(normalize(p) * coilHeight, 0, 0) + gl_Position;
+
+
+ // float angle = aAngle - cos(aAngle * BUMPS) * coilHeight;
+
+ }
+ </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");
+ aAngleCount = gl.getAttribLocation(glprog, "aAngleCount");
+
+ gl.clearColor(1,1,1,1);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ // точки по реотана
+ var n = 24 * 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.vertexAttrib1f(aAngleCount, n);
+ 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>