-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
181 lines (159 loc) · 4.96 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
<!doctype html>
<head>
<meta charset="utf-8">
<title>Galaxy</title>
<!-- Re-use my Galaxy thing from http://www.andronikos.id.au, since it seems appropriate-->
<script>
window.onload = function() {
"use strict"
var canvas = document.getElementById('canvas');
var ctxt = canvas.getContext('2d');
var width = window.innerWidth;
var height = 500;
ctxt.canvas.width = width;
ctxt.canvas.height = height;
var mid = {x: width / 2, y: height / 2};
var angles = [0, 60, 180, 250];
var extra_colours = ["#aaa", "red", "yellow", "cyan", "blue"];
var spread = 200;
var tightness = 1;
function deg2rad(angle_deg) {
return Math.PI / 180 * angle_deg;
}
function rotate_point(p, angle_rad) {
return {
"x": p.x * Math.cos(angle_rad) - p.y * Math.sin(angle_rad),
"y": p.x * Math.sin(angle_rad) + p.y * Math.cos(angle_rad)
};
}
// r is the radius of the spiral, t is the distance from the center.
function point_on_logarithmic_spiral(r, t) {
var rad = deg2rad(t);
return {
"x": r * t * Math.cos(rad),
"y": r * t * Math.sin(rad)
};
}
// draws a star close but randomly distant to a point. Has a higher
// probability of being close to the point given.
function draw_star(p, col) {
ctxt.fillStyle = col || "#333";
ctxt.globalCompositeOperation = "lighter";
// subtracting random from random results in a distribution between
// -1 and 1, with higher distribution frequency close to 0.
var nx = p.x + (Math.random() - Math.random()) * 20;
var ny = p.y + (Math.random() - Math.random()) * 20;
ctxt.fillRect(nx + mid.x, ny + mid.y, 3, 3);
}
function draw_galaxy() {
ctxt.clearRect(0, 0, width, height);
for (var i = 0; i < spread; i++) {
var p = point_on_logarithmic_spiral(tightness, i);
for (var angle of angles) {
draw_star(rotate_point(p, deg2rad(angle)));
if (Math.random() < 1 - (i / spread)) {
draw_star(
rotate_point(p, deg2rad(angle)),
Math.random() > 0.02 ? extra_colours[0] :
extra_colours[Math.random() * (extra_colours.length - 1) + 1|0]
);
}
}
}
};
draw_galaxy();
}
</script>
<style>
/* @import url('https://fonts.googleapis.com/css?family=Press+Start+2P'); */
@import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono');
body {
margin: 0;
margin-bottom: 2rem;
background: black;
font-family: 'Share Tech Mono', sans-serif;
font-variant: small-caps;
word-spacing: -50%;
}
h1, h2 {
/* Ode to Vintageous! */
font-size: 5rem;
text-shadow: rgb(16, 54, 30) 3px 3px 0px;
color: rgb(45, 110, 84);
text-align: center;
margin-bottom: 5px;
}
h2 {
font-size: 2rem;
text-shadow: rgb(16, 54, 30) 3px 3px 0px;
color: rgb(45, 110, 84);
}
canvas {
background: black;
}
.fullscreenish {
height: 100vh;
}
#start {
display: block;
text-align: center;
font-size: 2rem;
color: #999;
font-size: 2rem;
text-shadow: rgb(16, 54, 30) 3px 3px 0px;
}
#start::before {
content: "\00B7 \00B7 \00B7 ";
}
#start::after {
content: " \00B7 \00B7 \00B7";
}
#start:hover {
color: red;
}
.menu {
text-align: center;
color: #555;
}
.menu > .submenu > h2 {
display: inline;
}
a:visited, a {
color: #555;
font-weight: bold;
text-decoration: none;
}
a:not(:first-of-type):before {
content: " \00B7 " ;
color: #555;
}
a:hover {
color: cyan;
}
</style>
</head>
<body>
<div class="fullscreenish">
<h1>Space Battle</h1>
<canvas id="canvas" width="400" height="400"></canvas>
<a id="start" href="https://nikosandronikos.github.io/spacebattle/src/">Go</a>
</div>
<div class="menu">
<div class="submenu">
<h2>Prototypes</h2> [
<a href="https://nikosandronikos.github.io/spacebattle/prototype/gameloop.html">Game loop</a>
<a href="https://nikosandronikos.github.io/spacebattle/prototype/collision.html">Collision detection 1</a>
<a href="https://nikosandronikos.github.io/spacebattle/prototype/collision-lines.html">2</a>
<a href="https://nikosandronikos.github.io/spacebattle/prototype/balls.html">3</a>
<a href="https://nikosandronikos.github.io/spacebattle/prototype/collision-damage.html">4</a>
]
</div>
<div class="submenu">
<h2>Links</h2> [
<a href="https://github.com/nikosandronikos/spacebattle">View on GitHub</a>
<a href="https://twitter.com/nandronikos">Twitter</a>
]
</div>
</div>
</body>
</html>