-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.js
193 lines (141 loc) · 4.63 KB
/
js.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
$(document).foundation();
//add .on-section to section currently on scrolltop, remove .onsection from neighboring sections
if (scrollTop > aboutPoint && scrollTop < (portfolioPoint - navHeight)) {
$('#about-btn').addClass('on-section');
$('#portfolio-btn').removeClass('on-section');
} else if (scrollTop > (portfolioPoint - navHeight) && scrollTop < (contactPoint - navHeight)) {
$('#about-btn').removeClass('on-section');
$('#portfolio-btn').addClass('on-section');
$('#contact-btn').removeClass('on-section');
} else if (scrollTop > (contactPoint - navHeight)) {
$('#portfolio-btn').removeClass('on-section');
$('#contact-btn').addClass('on-section');
}
$('document').ready(function() {
var lineBorder = parseInt($('.section-seperator').css('border-top-width'), 10);
//nav buttons animate html and body(for cross-browser comp.) to anchors, anchors modified for navbar and <hr> that seperates sections
$('.to-home').click(function() {
$('html, body').animate({
scrollTop: $('#Home').offset().top - navHeight
}, 600);
});
$('.to-about').click(function() {
$('html,body').animate({
scrollTop: $('#about-anchor').offset().top - navHeight - aboutPadding + lineBorder
}, 600);
});
$('.to-portfolio').click(function() {
$('html, body').animate({
scrollTop: $('#portfolio-anchor').offset().top - navHeight + lineBorder
}, 600);
});
$('.to-contact').click(function() {
$('html, body').animate({
scrollTop: $('#contact-anchor').offset().top - navHeight + lineBorder
}, 600);
});
});
var fov = 2000;
var canvas = document.querySelector(".render");
var width = window.innerWidth;
var height = window.innerHeight;
var context = canvas.getContext("2d");
canvas.setAttribute("width", width);
canvas.setAttribute("height", height);
canvas.addEventListener('mousemove',getMouse,false);
var mouseX=0;
var mouseY=0;
var point = [];
var points = [];
var point3d = [];
var angleX = 0;
var angleY = 0;
var HALF_WIDTH = width / 2;
var HALF_HEIGHT = height / 2;
var x3d = 90;
var y3d = 10;
var z3d = 10;
var counter=1000;
var lastx2d = 0;
var lasty2d = 0;
var dim = 50;
var spacing = ((Math.PI * 2) / dim);
var numPoints = dim * dim;
var size = 300;
function draw() {
counter= 0.07;
var points = [];
for (var i = 0; i < numPoints; i++) {
var z = size * Math.sin(spacing * i);
var s = size * Math.cos(spacing * i);
point = [Math.cos(spacing * i * mouseX) * Math.sin(spacing * i * counter) * s,
Math.sin(spacing * i * mouseY) * Math.sin(spacing * i * counter) * s,z];
points.push(point);
}
context.globalAlpha = "10";
context.fillStyle = "rgba(255, 255, 255)";
context.fillRect(0, 0, width, height);
angleX+=((mouseX/width)-0.5)/4;
angleY+=((mouseY/height)-0.5)/4;
z3d = point3d[2];
point3d[2] = z3d;for (var i = 0; i < numPoints; i++) {
point3d = points[i];
rotateX(point3d,angleX);
rotateY(point3d,angleY);
x3d = point3d[0];
y3d = point3d[1];
z3d = point3d[2];
var scale = fov / (fov + z3d);
var x2d = (x3d * scale) + HALF_WIDTH;
var y2d = (y3d * scale) + HALF_HEIGHT;
if (scale>20) scale =20;
context.lineWidth = scale;
context.strokeStyle = "rgba(0, 57, 245)";
context.beginPath();
context.moveTo(x2d-30, y2d);
context.lineTo(lastx2d-30, lasty2d);
context.stroke();
lastx2d=x2d;
lasty2d=y2d;
}
}
setInterval(draw, 10);
function rotateX(point3d,angleX) {
var x = point3d[0];
var z = point3d[2];
var cosRY = Math.cos(angleX);
var sinRY = Math.sin(angleX);
var tempz = z;
var tempx = x;
x= (tempx*cosRY)+(tempz*sinRY);
z= (tempx*-sinRY)+(tempz*cosRY);
point3d[0] = x;
point3d[2] = z;
}
function rotateY(point3d,angleY) {
var y = point3d[1];
var z = point3d[2];
var cosRX = Math.cos(angleY);
var sinRX = Math.sin(angleY);
var tempz = z;
var tempy = y;
y= (tempy*cosRX)+(tempz*sinRX);
z= (tempy*-sinRX)+(tempz*cosRX);
point3d[1] = y;
point3d[2] = z;
}
function getMouse (mousePosition) {
if (mousePosition.layerX || mousePosition.layerX === 0) { // Firefox?
mouseX = mousePosition.layerX;
mouseY = mousePosition.layerY;
} else if (mousePosition.offsetX || mousePosition.offsetX === 0) { // Opera?
mouseX = mousePosition.offsetX;
mouseY = mousePosition.offsetY;
}
}
var lastOut=0;
function lowPassFilter(input,coeff){
var output = lastOut+coeff*(input-lastOut);
lastOut=output;
return output;
}