2017-09-26 20:11:20 +02:00
|
|
|
console.log("Hello, Sky!");
|
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
/**** ☭☭☭☭☭☭☭☭☭☭☭☭ ******
|
|
|
|
/☭☭☭☭ Parametri razni ☭☭☭☭ *
|
|
|
|
******☭☭☭☭☭☭☭☭☭☭☭☭******/
|
|
|
|
|
|
|
|
// Odmik kamere
|
|
|
|
var odmik_kamere = 100;
|
|
|
|
|
|
|
|
// Rotacija kamere
|
2017-10-05 02:33:44 +02:00
|
|
|
var cam_rot_offset = 1;
|
2017-10-05 02:12:16 +02:00
|
|
|
|
|
|
|
// Vidni kot
|
|
|
|
var FOV = 140;
|
|
|
|
|
|
|
|
// Sirina in visina objektov
|
|
|
|
var width = 2;
|
|
|
|
var height = 2;
|
|
|
|
|
2017-10-05 02:52:46 +02:00
|
|
|
// Limit stevila objektov
|
2017-10-06 23:20:52 +02:00
|
|
|
var obj_limit = 1000;
|
2017-10-05 02:52:46 +02:00
|
|
|
|
2017-10-05 02:33:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
// Prvotno prazno polje objektov. Lahko bi kak buffer to bil pozneje
|
|
|
|
var objekti = [];
|
|
|
|
|
2017-10-05 02:33:44 +02:00
|
|
|
// Stevec, za razno animiranje
|
|
|
|
var stevec = 0;
|
2017-10-05 02:12:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Parametri animacije
|
|
|
|
var rotacijaX = 0.006;
|
|
|
|
var rotacijaY = 0.001;
|
|
|
|
var rotacijaZ = 0.003;
|
|
|
|
|
2017-10-05 02:52:46 +02:00
|
|
|
// Premik obstojecih barv
|
|
|
|
var zamikBarve = 0.0000666;
|
|
|
|
|
|
|
|
// Zamik pri novem objektu
|
|
|
|
var barva_mod = 0.333;
|
|
|
|
var saturacija = 1;
|
|
|
|
var svetlost = 0.4;
|
2017-10-05 02:12:16 +02:00
|
|
|
|
|
|
|
var wDiff = 0.5;
|
|
|
|
var hDiff = 0.5;
|
|
|
|
|
2017-10-05 02:52:46 +02:00
|
|
|
var gostota_obj = 2;
|
|
|
|
|
2017-09-26 20:11:20 +02:00
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Scena, kamera in render
|
2017-09-26 20:11:20 +02:00
|
|
|
scene = new THREE.Scene;
|
|
|
|
|
2017-10-05 03:15:33 +02:00
|
|
|
camera = new THREE.PerspectiveCamera(FOV, window.innerWidth / window.innerHeight, 0.1, 2000);
|
2017-10-05 02:12:16 +02:00
|
|
|
camera.position.z = odmik_kamere;
|
2017-09-26 20:11:20 +02:00
|
|
|
|
|
|
|
renderer = new THREE.WebGLRenderer({
|
|
|
|
alpha: true
|
|
|
|
});
|
|
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
2017-10-05 01:37:36 +02:00
|
|
|
|
|
|
|
// Belo ozadje
|
|
|
|
//renderer.setClearColor(0xFFFFFF, 1);
|
|
|
|
// Črno ozadje
|
|
|
|
renderer.setClearColor(0x000000, 1);
|
|
|
|
|
2017-09-26 20:11:20 +02:00
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
|
|
|
|
|
2017-10-05 02:33:44 +02:00
|
|
|
|
|
|
|
function render () {
|
|
|
|
requestAnimationFrame(render);
|
|
|
|
|
|
|
|
stevec += 1;
|
|
|
|
|
|
|
|
// Dodaj objekt vcasih
|
2017-10-05 02:52:46 +02:00
|
|
|
if (stevec % gostota_obj === 0) {
|
2017-10-05 02:33:44 +02:00
|
|
|
addObj(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
|
|
|
|
objAnim();
|
|
|
|
|
|
|
|
camRotate();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Funkcija za animacijo objektov
|
|
|
|
function objAnim() {
|
2017-10-05 02:12:16 +02:00
|
|
|
objekti.map(function (obj) {
|
|
|
|
obj.rotation.y += rotacijaY;
|
|
|
|
obj.rotation.z += rotacijaZ;
|
|
|
|
obj.rotation.x += rotacijaX;
|
2017-10-05 02:52:46 +02:00
|
|
|
|
|
|
|
obj.scale.z += wDiff;
|
|
|
|
obj.scale.y += wDiff;
|
|
|
|
obj.scale.x += wDiff;
|
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
obj.material.color.offsetHSL(zamikBarve, 0, 0);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Funkcija za dodajanje novih objektov
|
|
|
|
function addObj(w, h) {
|
2017-09-26 20:11:20 +02:00
|
|
|
var col = new THREE.Color();
|
2017-10-05 02:52:46 +02:00
|
|
|
col.setHSL(stevec * barva_mod, saturacija, svetlost);
|
2017-09-26 20:11:20 +02:00
|
|
|
|
|
|
|
var mat = new THREE.LineBasicMaterial({
|
|
|
|
color: col
|
|
|
|
});
|
|
|
|
|
|
|
|
var geo = new THREE.Geometry();
|
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
var offset = h / 2;
|
2017-09-26 20:11:20 +02:00
|
|
|
|
|
|
|
geo.vertices.push(new THREE.Vector3(-offset, 0, 0), new THREE.Vector3(0, offset, 0));
|
|
|
|
geo.vertices.push(new THREE.Vector3(-offset, 0, 0), new THREE.Vector3(0, -offset, 0));
|
|
|
|
geo.vertices.push(new THREE.Vector3(offset, 0, 0), new THREE.Vector3(0, offset, 0));
|
|
|
|
geo.vertices.push(new THREE.Vector3(offset, 0, 0), new THREE.Vector3(0, -offset, 0));
|
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
var obj = new THREE.Line(geo, mat, THREE.LineSegments);
|
2017-09-26 20:11:20 +02:00
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
scene.add(obj);
|
2017-10-05 02:52:46 +02:00
|
|
|
|
|
|
|
// Pocisti za seboj
|
|
|
|
if (objekti.push(obj) > obj_limit) {
|
2017-12-02 21:25:04 +01:00
|
|
|
while (objekti.length > obj_limit) {
|
|
|
|
scene.remove(objekti[0]);
|
|
|
|
objekti.shift();
|
|
|
|
}
|
2017-10-05 02:52:46 +02:00
|
|
|
}
|
2017-09-26 20:11:20 +02:00
|
|
|
};
|
|
|
|
|
2017-10-05 03:15:33 +02:00
|
|
|
var xAksa = new THREE.Vector3(0, 1, 0);
|
2017-09-26 20:11:20 +02:00
|
|
|
function camRotate () {
|
2017-10-05 01:37:36 +02:00
|
|
|
// rotiraj po z osi
|
2017-10-05 02:12:16 +02:00
|
|
|
camera.translateX(cam_rot_offset);
|
|
|
|
camera.translateZ(odmik_kamere - Math.sqrt(Math.pow(odmik_kamere, 2) + Math.pow(cam_rot_offset, 2)));
|
2017-10-05 01:37:36 +02:00
|
|
|
|
2017-10-06 23:20:52 +02:00
|
|
|
/*
|
2017-10-05 02:12:16 +02:00
|
|
|
camera.translateY(cam_rot_offset);
|
|
|
|
camera.translateX(odmik_kamere - Math.sqrt(Math.pow(odmik_kamere, 2) + Math.pow(cam_rot_offset, 2)));
|
2017-10-05 01:37:36 +02:00
|
|
|
|
2017-10-05 02:12:16 +02:00
|
|
|
camera.translateY(cam_rot_offset);
|
|
|
|
camera.translateX(odmik_kamere - Math.sqrt(Math.pow(odmik_kamere, 2) + Math.pow(cam_rot_offset, 2)));
|
2017-10-05 03:15:33 +02:00
|
|
|
|
2017-10-06 23:20:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
camera.position.x = Math.sin((stevec % 10) / 10) * cam_rot_offset;
|
|
|
|
camera.position.y = Math.cos((stevec % 10) / 10) * cam_rot_offset;
|
2017-10-05 01:37:36 +02:00
|
|
|
*/
|
|
|
|
|
2017-10-05 03:22:01 +02:00
|
|
|
camera.lookAt(scene.position);
|
2017-09-26 20:11:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Inicializiraj
|
|
|
|
document.onreadystatechange = function () {
|
|
|
|
if (document.readyState === 'complete') {
|
|
|
|
document.getElementById("anim-container").appendChild(renderer.domElement);
|
|
|
|
|
|
|
|
render();
|
|
|
|
}
|
2017-10-05 01:37:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Lep risajz
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
2017-09-26 20:11:20 +02:00
|
|
|
}
|
2017-10-05 01:37:36 +02:00
|
|
|
window.addEventListener('resize', onWindowResize, false);
|