This repository was archived by the owner on Jul 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHack_NCStateJS.js
More file actions
195 lines (160 loc) · 6.14 KB
/
Hack_NCStateJS.js
File metadata and controls
195 lines (160 loc) · 6.14 KB
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
194
195
let oldHeight = 0
let oldWidth = 0
//document ready
$(document).ready(function () {
window.scrollTo(0, 1);
//Globals
var canvasBackgroundColor = "rgb(204, 0, 0)",
canvasTextColor = "rgb(255, 255, 255)",
activeImage = "Hack_NCState_Logo.png",
activeCodeBlackImage = "Code_Black_Merge_2024/Code_Black.png"
// Falling binary effect
// ** Adapted from matrix rain animation courtesy of thecodeplayer
// ** Link: http://thecodeplayer.com/walkthrough/matrix-rain-animation-html5-canvas-javascript
var c = document.getElementById("c");
var ctx = c.getContext("2d");
var font_size = 10;
if (window.innerWidth < 600) {
font_size = 7;
}
var columns;
var drops;
function resize() {
oldHeight = window.innerHeight
oldWidth = window.innerWidth
c.height = window.innerHeight;
c.width = window.innerWidth;
}
// Function to set canvas dimensions and update columns and drops
function setCanvasDimensions() {
if ((oldHeight == 0 && oldWidth == 0) || (window.innerWidth > oldWidth || window.innerHeight > oldHeight)) {
resize()
}
columns = Math.floor(c.width / font_size); // number of columns for the rain
drops = []; // an array of drops - one per column
// x below is the x coordinate
// Initialize y coordinate of the drop randomly
for (var x = 0; x < columns; x++) drops[x] = Math.floor(Math.random() * c.height / font_size);
}
// Set initial canvas dimensions
setCanvasDimensions();
// Update canvas dimensions on window resize
window.addEventListener('resize', setCanvasDimensions);
//binary characters - do you know what is says?
var binary =
"010100000110000101100011011010110100100001100001011000110110101101110011";
//converting the string into an array of single characters
binary = binary.split("");
//drawing the characters
function draw() {
// Recalculate columns and drops if canvas size changes
var newColumns = Math.floor(c.width / font_size);
if (newColumns !== columns) {
columns = newColumns;
drops = [];
for (var x = 0; x < columns; x++) drops[x] = Math.floor(Math.random() * c.height / font_size);
}
//Black BG for the canvas
//translucent BG to show trail
ctx.globalAlpha = 0.08; //opacity
ctx.fillStyle = canvasBackgroundColor;
ctx.fillRect(0, 0, c.width, c.height);
ctx.globalAlpha = 0.6; //opacity
ctx.fillStyle = canvasTextColor; //white, semi-transparent text
ctx.font = font_size + "px arial";
//looping over drops
for (var i = 0; i < drops.length; i++) {
//a random binary character to print
var text = binary[Math.floor(Math.random() * binary.length)];
//x = i*font_size, y = value of drops[i]*font_size
ctx.fillText(text, i * font_size, drops[i] * font_size);
//sending the drop back to the top randomly after it has crossed the screen
//adding a randomness to the reset to make the drops scattered on the Y axis
if (drops[i] * font_size > c.height && Math.random() > 0.975)
drops[i] = 0;
//incrementing Y coordinate
drops[i]++;
}
}
var time = 33;
if (isiPhone()) {
time = 24;
}
setInterval(draw, time);
function isiPhone() {
return (
navigator.platform.indexOf("iPhone") != -1 ||
navigator.platform.indexOf("iPod") != -1
);
}
$("#theme-pullout").click(function () {
$(".theme-picker").toggleClass("active-theme-picker");
});
$(".color-ball").click(function () {
// If you selected the same theme again, do nothing
if ($(this).hasClass("active-theme")) return;
// Otherwise, switch which theme is active to the one selected
$(".color-ball").removeClass("active-theme");
$(this).addClass("active-theme");
canvasBackgroundColor = $(this).css("background-color");
canvasTextColor = $(this).css("border-color");
// If using white (really any light) background theme
if ($(".color-ball").index(this) == 1) {
activeImage = "images/Hack_NCState_Logo_Red.png";
activeCodeBlackImage = "images/Code_Black_Merge_2024/Code_Black_Red.png";
document.documentElement.style.setProperty("--primary", canvasTextColor);
document.documentElement.style.setProperty(
"--secondary",
canvasBackgroundColor
);
} else {
activeImage = "images/Hack_NCState_Logo.png";
activeCodeBlackImage = "images/Code_Black_Merge_2024/Code_Black.png";
document.documentElement.style.setProperty(
"--primary",
canvasBackgroundColor
);
document.documentElement.style.setProperty(
"--secondary",
canvasTextColor
);
}
// Set the background wolf image. It'll need to change if going to/from white bg
$("#banner-logo").attr("src", activeImage);
$("#code-black-banner-logo").attr("src", activeCodeBlackImage);
$(".below-banner-text").css("color", canvasTextColor);
// Set the link text normally to be opposite of canvas
$(".button-link").css("background-color", canvasTextColor);
$(".button-link").css("color", canvasBackgroundColor);
$("#theme-pullout").css("color", canvasTextColor);
// When hovering over button, change button bg color and link text color
$(".button-link").hover(function (e) {
$(this).css(
"background-color",
e.type === "mouseenter" ? canvasBackgroundColor : canvasTextColor
);
$(this).css(
"color",
e.type === "mouseenter" ? canvasTextColor : canvasBackgroundColor
);
});
});
});
// Highlight current section user is viewing in the side navbar
$(window).scroll(function () {
var pageScrollTop = $(window).scrollTop() + $(window).height() / 2;
if ($("section:first").offset().top > pageScrollTop) return;
$("#sideNav a").each(function () {
var section = $(this).attr("href");
var sectionScrollTop = $(section).offset().top;
var sectionScrollBottom = sectionScrollTop + $(section).outerHeight(true);
var isInSection =
sectionScrollTop < pageScrollTop && pageScrollTop < sectionScrollBottom;
if (isInSection) {
if (!$(this).hasClass("active")) {
$("#sideNav a").removeClass("active");
$(this).addClass("active");
}
}
});
});