-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
138 lines (123 loc) · 4.01 KB
/
main.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
var renderer, contain, camera, scene, material, mesh, cube;
var shape;
var shapesArr = [];
var a, b, c, d, e;
var width = window.innerWidth;
var height = window.innerHeight;
var controls;
var uniforms = {
time: {
type: "f",
value: 1.0
},
size: {
type: "v2",
value: new THREE.Vector2(width, height)
}
};
var paused = false;
var date = new Date().getTime();
var fragmentShader;
var vertexShader;
function writeFragmentShader(value1, value2) {
fragmentShader = "varying float vZ;" +
"uniform float time;" +
"uniform vec2 size;" +
"void main() {" +
"vec2 d = gl_FragCoord.xy - (0.5+0.01*sin(time))*size;" +
"float a = sin(time*0.2)*1.0*3.14159;" +
"d = vec2( d.x*cos(a) + d.y*sin(a)," +
"-d.x*sin(a) + d.y*cos(a));" +
"vec2 rg = vec2(1.0)-abs(d)/(0.6*size.xx);" +
"float b = abs(vZ)/ 180.0;" +
"gl_FragColor = vec4(b,rg +" + value1 + ", " + value2 + ");" +
"}";
}
function writeVertexShader(value1, value2, value3, value4) {
vertexShader =
"varying float vZ;" +
"uniform float time;" +
"void main() {" +
"vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);" +
"mvPosition.y += " + value3 + "*sin(time*0.1+mvPosition.x/" + value4 + ");" +
"mvPosition.x += " + value1 + "*cos(time*0.1+mvPosition.y/" + value2 + ");" +
"vec4 p = projectionMatrix * mvPosition;" +
"vZ = p.z;" +
"gl_Position = p;" +
"}"
}
function generateValue(min, max) {
return Math.random() * (max - min) + min;
}
window.addEventListener('load', init);
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(70, width / height, 10, 1000);
camera.position.z = 100;
controls = new THREE.OrbitControls(camera);
controls.update();
scene.add(camera);
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(width, height);
renderer.setClearColor(0xffffff);
contain = renderer.domElement;
document.body.appendChild(contain);
$.get("small-data.csv")
.pipe(CSV.parse)
.done(function(rows) {
for (var i = 1; i < rows.length; i++) {
a = rows[i][0];
b = rows[i][1];
c = rows[i][2];
d = rows[i][3];
d = (d + generateValue(100, 400)) / 1000;
e = (b + generateValue(10, 30)) / 100;
if (i % 2 == 0) {
writeVertexShader(a, b, c - 4, b);
writeFragmentShader(d, e);
shape = new THREE.Mesh(
new THREE.SphereGeometry(b, a, c),
new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: fragmentShader
}));
} else {
writeVertexShader(a, b, c, b);
writeFragmentShader(e, d);
shape = new THREE.Mesh(
new THREE.SphereGeometry(a, b, c),
new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: fragmentShader
}));
}
shapesArr.push(shape);
}
for (var j = 0; j < shapesArr.length; j++) {
scene.add(shapesArr[j]);
}
});
render();
}
function render(t) {
if (!paused) {
last = t;
uniforms.time.value += 0.05;
renderer.clear();
}
controls.update();
requestAnimationFrame(render);
renderer.render(scene, camera);
}
$(document).ready(function() {
$('.ui-dialog').css('background-color', 'rgba(255,255,255,0.5)');
$('#modal').on('click', function() {
$('#info').dialog({
show: 'fade'
});
});
});