forked from ggorlen/mb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
230 lines (191 loc) · 6.35 KB
/
index.html
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Course page for Mission Bit at Lincoln HS">
<meta name="author" content="Topher Lin">
<meta name="keywords" content="mission, bit, gateway">
<title>Mission Bit at Lincoln HS</title>
<!-- Favicon -->
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- CSS -->
<link rel="stylesheet" href="css/style.css">
<noscript>
<style>body { display: block; opacity: 1; }</style>
</noscript>
<!-- Style for front page only -->
<style>
h1 {
display: block;
flex-shrink: 1; // trying to fix wrapping in ie
box-sizing: border-box; /* 2 */
max-width: 100%; /* 1 */
}
html, body {
height: 100%;
user-select: none;
}
main {
flex: 1 0 0;
}
footer i {
flex: 1 1 0;
margin: 0.4em;
color: #444;
}
footer a,
footer a:link,
footer a:visited,
footer a:hover,
footer a:active,
footer a:focus {
border: 0;
font-size: 1em;
}
#wrapper {
display: flex;
flex-flow: column wrap;
align-items: center;
height: 100%;
}
@media screen and (max-width: 900px) {
main {
flex: 0 1 auto;
}
div#wrapper {
height: 80%;
}
}
</style>
</head>
<body>
<div id="wrapper">
<nav>
<a href="modules/">Modules</a>
<a href="resources/">Resources</a>
<a href="projects/">Projects</a>
<a href="about/">About</a>
</nav>
<main style="background: transparent; margin: 0;">
<h1 style="color: #444;">Mission Bit at Lincoln HS</h1>
</main>
<footer>
<a href="https://www.github.com/clizzin" title="github"><i class="fa fa-github fa-2x"></i></a>
</footer>
</div>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js">
</script>
<!-- Global JS script -->
<script src="js/global.js"></script>
<!-- Matter.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.12.0/matter.min.js"></script>
<script>
"use strict";
const rad = d => d * Math.PI / 180;
const canvas = document.createElement("canvas");
canvas.width = parseInt(getComputedStyle(document.body).width);
canvas.height = parseInt(getComputedStyle(document.body).height);
canvas.style.position = "absolute";
canvas.style.top = 0;
canvas.style.zIndex = -1;
document.body.appendChild(canvas);
const ctx = canvas.getContext("2d");
ctx.lineWidth = 1;
const Engine = Matter.Engine;
const World = Matter.World;
const Vector = Matter.Vector;
const Bodies = Matter.Bodies;
const engine = Engine.create();
const MouseConstraint = Matter.MouseConstraint;
const mouseConstraint = MouseConstraint.create(engine);
const setMouseOffset = () => {
const rect = canvas.getBoundingClientRect();
Matter.Mouse.setOffset(mouseConstraint.mouse, {
x: -rect.x, y: -rect.y
});
};
setMouseOffset();
document.addEventListener("mousemove", e =>
setTimeout(setMouseOffset, 500)
);
World.add(engine.world, mouseConstraint);
// Create body arrays
const boxes = [];
const ledges = [
Bodies.rectangle(
canvas.width / 2, canvas.height + 25,
canvas.width, 50,
{ isStatic: true }
)
];
//Matter.Body.rotate(ledges[0], rad(35));
//Matter.Body.rotate(ledges[1], rad(-25));
// Add bodies to the world
World.add(engine.world, ledges);
//Engine.run(engine);
const draw = (body, ctx) => {
ctx.fillStyle = body.color || "#999";
ctx.beginPath();
body.vertices.forEach(e => ctx.lineTo(e.x, e.y));
ctx.closePath();
ctx.fill();
ctx.stroke();
};
const inBounds = (body, canvas) => {
for (let i = 0; i < body.vertices.length; i++) {
if (body.vertices[i].x < canvas.width &&
body.vertices[i].x > 0 &&
body.vertices[i].y < canvas.height //&&
/*body.vertices[i].y > 0*/) {
return true;
}
}
return false;
};
(function update() {
if ((boxes.length < 25 || Math.random() < 0.0001) && boxes.length < 100) {
boxes.unshift(Bodies.rectangle(
canvas.width / 2, -130, Math.random() * 60 + 5,
Math.random() * 60 + 5,
{ frictionAir: 0.01, friction: 0.1, restitution: 0.6 }
));
boxes[0].color = "hsl(" + (Math.random() * 100 + 100) +
", 50%, " + (Math.random() * 40 + 40) + "%)";
World.add(engine.world, [boxes[0]]);
Matter.Body.rotate(boxes[0], rad(Math.random() * 360));
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = boxes.length - 1; i >= 0; i--) {
draw(boxes[i], ctx);
if (!inBounds(boxes[i], canvas)) {
World.remove(engine.world, boxes[i]);
boxes.splice(i, 1);
}
}
ledges.forEach(e => draw(e, ctx));
Engine.update(engine); // instead of a single call to Engine.run(engine)
requestAnimationFrame(update);
})();
let timeout;
window.addEventListener("resize", e => {
clearTimeout(timeout);
timeout = setTimeout(e => {
canvas.width = parseInt(getComputedStyle(document.body).width);
canvas.height = parseInt(getComputedStyle(document.body).height);
World.remove(engine.world, ledges[0]);
ledges[0] = Bodies.rectangle(
canvas.width / 2, canvas.height + 25,
canvas.width, 50,
{ isStatic: true }
);
World.add(engine.world, ledges);
ctx.lineWidth = 5;
}, 500);
});
</script>
</body>
</html>