1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 );
}
|