-
Notifications
You must be signed in to change notification settings - Fork 0
/
anim.js
179 lines (137 loc) · 3.86 KB
/
anim.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Visina in sirina animacije
var width = window.innerWidth;
var height = window.innerHeight;
// Interaktivnost
var socket = io();
// Inicializiraj kamero, sceno, render
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.z = 50; // Zoom out da se kaj vidi
var renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(width, height);
renderer.setClearColor(0xffffff);
//controls = new THREE.TrackballControls( camera );
//controls.target.set( 0, 0, 0 );
document.onreadystatechange = function () {
if (document.readyState === 'complete') {
document.getElementById("anim-container").appendChild(renderer.domElement);
}
var node = document.createElement("span");
node.innerHTML = "sz3";
node.style.position = "absolute";
node.style.left = "50%";
node.style.top = "50%";
node.style["z-index"] = 1;
node.style.opacity = .5;
node.style.cursor = "default";
node.style["user-select"] = "none";
document.getElementById("anim-container").appendChild(node);
};
var objekti = [];
// Render l00p
function render() {
requestAnimationFrame(render);
// Animiraj zadeve
animirajStuff();
renderer.render(scene, camera);
}
function animirajStuff () {
// uizi premikaj kvadrate
objekti.map(function (o) {
var randSpan = function() {
return Math.random() * .005 - .0025;
};
o.rx += randSpan();
o.ry += randSpan();
o.rz += randSpan();
o.position.x += o.rx;
o.position.y += o.ry;
o.position.z += o.rz;
o.rotateX(o.rx);
o.rotateY(o.ry);
o.rotateZ(o.rz);
// Glitch rotacija!
//o.applyMatrix( pivot.matrixWorld );
});
}
function randomMat() {
var mat = new THREE.MeshBasicMaterial({
color: Math.random() * 0xffffff,
transparent: true
});
mat.opacity = Math.random();
return mat;
}
var mat1 = randomMat();
// Dodaj kvader
function kvader(dolzina, sirina, debelina = 1, mat = mat1) {
var geo = new THREE.BoxBufferGeometry(dolzina, sirina, debelina);
var kvader = new THREE.Mesh(geo, mat);
return kvader;
}
function randomKvadrat() {
var m = randomMat();
var d = Math.random() * 20
var k = kvader(d, d, d, m);
return k;
}
/*
objekti.push(randomKvadrat());
objekti.map(function (o) {
scene.add(o);
});
*/
render();
var pivot = new THREE.Object3D();
function dodajRandomKvadrat() {
var razpon = 20;
var k = randomKvadrat();
k.position.x += (Math.random() * razpon) - razpon / 2;
k.position.y += (Math.random() * razpon) - razpon / 2;
k.position.z += (Math.random() * razpon) - razpon / 2;
k.rx = 0;
k.ry = 0;
k.rz = 0;
objekti.push(k);
pivot.add(k);
scene.add(k);
}
scene.add(pivot);
var pageX = window.innerWidth;
var pageY = window.innerHeight;
function premikMiske(ev) {
//return;
//var movX = ev.movementX;
//var movY = ev.movementY;
var oX = ev.pageX;
var oY = ev.pageY;
var percentX = oX / pageX * 100;
var percentY = oY / pageY * 100;
// Prestavi kurzor
//kurzor.
//pivot.rotateX(movX / 1000);
//pivot.rotateY(movY / 1000);
}
// Glitch rotacija!
window.addEventListener('mousemove', premikMiske);
window.addEventListener('click', ustvariKvadrat);
window.addEventListener('touchend', ustvariKvadrat);
function ustvariKvadrat() {
//dodajRandomKvadrat();
socket.emit('dodajKvadrat', "lal");
}
function dodajEnga() {
dodajRandomKvadrat();
}
setInterval(dodajEnga, 1500);
socket.on('dodajKvadrat', function(msg){
dodajRandomKvadrat();
});
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', onWindowResize, false);