Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / 06-Practice-07.11.2022 / 05.js
diff options
context:
space:
mode:
Commitde44ffda470905c350a1edb4bce4f0107f1d7742 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-11-08 13:50:09 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-11-08 13:50:09 +0200
Filese5353a708ba8eacc25a26f155a4b08a0ce8b1d07 /Year 2/Computer Graphics Fundamentals/06-Practice-07.11.2022/05.js
uni-projects-de44ffda470905c350a1edb4bce4f0107f1d7742.tar
uni-projects-de44ffda470905c350a1edb4bce4f0107f1d7742.tar.gz
uni-projects-de44ffda470905c350a1edb4bce4f0107f1d7742.zip
Parent9290c864ffa683cbeb4d5cb3f75399284a6a9cb2 (diff)
[OKG/P06] Solved exercises
1 files changed, 50 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics Fundamentals/06-Practice-07.11.2022/05.js50
diff --git a/Year 2/Computer Graphics Fundamentals/06-Practice-07.11.2022/05.js b/Year 2/Computer Graphics Fundamentals/06-Practice-07.11.2022/05.js
new file mode 100644
index 0000000..b99c736
--- /dev/null
+++ b/Year 2/Computer Graphics Fundamentals/06-Practice-07.11.2022/05.js
@@ -0,0 +1,50 @@
+// Задача: направете ... биберон от синусоида.
+// Заготовката по-долу, ако я пуснете, трябва
+// само да покаже зелен екран, нищо повече
+
+
+var renderer = new THREE.WebGLRenderer({antialias:true});
+renderer.setSize( window.innerWidth, window.innerHeight );
+renderer.setAnimationLoop( drawFrame );
+document.body.appendChild( renderer.domElement );
+
+var scene = new THREE.Scene();
+scene.background = new THREE.Color( 'seagreen' );
+
+var aspect = window.innerWidth/window.innerHeight;
+var camera = new THREE.PerspectiveCamera( 30, aspect );
+camera.position.set( 0, 10, 40 );
+camera.lookAt( new THREE.Vector3() );
+
+
+// профил на биберона
+var profile = [];
+
+const points = 30;
+const height = 10;
+for (var y = 0; y < height; y += height / points) {
+ profile.push(new THREE.Vector2( Math.sin(2 * Math.PI * y / height * 2 + Math.PI) + 4.3, y - height / 2 ).rotateAround(new THREE.Vector2(), Math.PI / 4));
+}
+
+// създаване на 3D формата на биберона
+var geometry = new THREE.LatheGeometry(profile, 32);
+var pacifier = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( {specular: 'linen'} ) );
+scene.add(pacifier);
+
+// светлини
+var light = new THREE.PointLight( 'white' );
+light.position.set( 100, 50, 0 );
+scene.add( light );
+
+light = new THREE.PointLight( 'white' );
+light.position.set( -100, 50, 0 );
+scene.add( light );
+
+function drawFrame()
+{
+ pacifier.rotation.x += 0.003;
+ pacifier.rotation.y += 0.003;
+ pacifier.rotation.z += 0.003;
+
+ renderer.render( scene, camera );
+}