Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / 02-Practice-17.10.2022 / Problem 0205.html
diff options
context:
space:
mode:
Commit4e1941908000424b26713c185e2cf907d8428e43 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-10-22 21:59:24 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-10-22 21:59:24 +0300
Files809f32a507cbe7bf6fe4b255a44a67dd979b672d /Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0205.html
uni-projects-4e1941908000424b26713c185e2cf907d8428e43.tar
uni-projects-4e1941908000424b26713c185e2cf907d8428e43.tar.gz
uni-projects-4e1941908000424b26713c185e2cf907d8428e43.zip
Parent083017dac65fda5c171ca0b223686f0f1773a157 (diff)
[WGL/P02] Solved practicum exercises
1 files changed, 79 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0205.html79
diff --git a/Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0205.html b/Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0205.html
new file mode 100644
index 0000000..37c4127
--- /dev/null
+++ b/Year 2/Computer Graphics with WebGL/02-Practice-17.10.2022/Problem 0205.html
@@ -0,0 +1,79 @@
+<!DOCTYPE html>
+
+<head>
+ <meta charset="utf-8"/>
+ <title>GLSL пеперуда</title>
+
+ <script src="webgl-fmi.js"></script>
+
+ <script id="vshader" type="x-shader/x-vertex">
+ #define PI 3.1415926538
+ #define ASPECT_RATIO 1.5
+
+ attribute float aPoint;
+ attribute float aPointCnt;
+
+ attribute vec3 aRGB;
+ varying vec3 vRGB;
+
+ void main ()
+ {
+ float alpha = aPoint * (360.0 / aPointCnt) * (PI / 180.0);
+ float mag = (exp(cos(alpha)) - 2.0 * cos(4.0 * alpha) + pow(sin(alpha / 15.0), 5.0)) / 2.475;
+ gl_Position = vec4(mag * sin(alpha) / ASPECT_RATIO, mag * cos(alpha) - 0.268, 0, 1);
+ gl_PointSize = 4.0;
+ vRGB = aRGB;
+ }
+ </script>
+
+ <script id="fshader" type="x-shader/x-fragment">
+ precision mediump float;
+ varying vec3 vRGB;
+ void main( )
+ {
+ gl_FragColor = vec4(vRGB,1);
+ }
+ </script>
+
+ <script>
+ function start( )
+ {
+ gl = getContext("picasso");
+ glprog = getProgram("vshader","fshader");
+
+ aPoint = gl.getAttribLocation(glprog, "aPoint");
+ aPointCnt = gl.getAttribLocation(glprog, "aPointCnt");
+ aRGB = gl.getAttribLocation(glprog,"aRGB");
+
+ gl.clearColor(1,1,1,1);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ var n = 250;
+ var data = [ ];
+ for(var i=0; i<n; i++) data.push(i);
+
+ var buf = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER,buf);
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW);
+
+ gl.vertexAttrib3f(aRGB,1,0.2,0);
+
+ gl.vertexAttribPointer(aPoint, 1, gl.FLOAT, false, 0, 0);
+ gl.enableVertexAttribArray(aPoint);
+ gl.vertexAttrib1f(aPointCnt, n);
+ gl.drawArrays(gl.LINE_LOOP,0,n);
+ }
+ </script>
+</head>
+
+<body onload="start()">
+ <h2>GLSL пеперуда</h2>
+
+ <noscript>
+ Искаме JavaScript, но няма!
+ </noscript>
+
+ <canvas id="picasso" width="600" height="400" style="border: solid;">
+ Искаме canvas, но няма!
+ </canvas>
+</body>