-
Notifications
You must be signed in to change notification settings - Fork 6
/
tg.html
221 lines (206 loc) · 5.9 KB
/
tg.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Friday horse!</title>
<style>
body {
font-family: "Comic Sans MS", cursive, sans-serif;
font-size: 0.8em;
}
</style>
</head>
<body onload="initIt();" style="margin: 0px;">
<img id="horse" style="display: none; width: 100%; position: absolute; left: 0px; right: 0px; z-index: -1;">
<canvas id="hiddenCanvas" width="1000" height="10" style="display: none; position: absolute; z-index: 1000 "></canvas>
<!--
I'll use blink if you complain about <center>.
-->
<center id="blah">
<h1 style="margin-top: 0;">tg.friday.horse</h1>
<h1 style="margin-top: 0;">The Gathering opens <div id="output1" style="display: inline;"></div></h1>
<h4 id="attribution"></h4>
</center>
<p style="font-size: xx-small; position: absolute; right: 0px; bottom: 0px;"><a href="https://github.com/KristianLyng/friday.horse">Friday horses as a service</a></p>
<script>
/*
* This is all essentially a lesson in "MEEEEH, can't be bothered".
*
* That said, I've written it all, and I'm fully aware that it probably
* makes some people cringe. That's part of the fun. CRINGE I TELL YOU.
*
* You may want to look at http://kly.no for something slightly
* more constructive.
*/
/*
* Add new horses here. Attribution can be HTML if needed.
*/
var horsies = [
{ horse: "horse-1.jpg", attribution: "N/A" },
{ horse: "horse-2.jpg", attribution: "N/A" },
{ horse: "horse-3.jpg", attribution: "N/A" },
{ horse: "horse-4.jpg", attribution: "N/A" },
{ horse: "horse-5.jpg", attribution: "N/A" },
{ horse: "horse-6.jpg", attribution: "N/A" },
{ horse: "horse-7.jpg", attribution: "N/A" },
{ horse: "horse-8.jpg", attribution: "N/A" },
{ horse: "horse-9.jpg", attribution: "N/A" },
{ horse: "horse-10.jpg", attribution: "N/A" },
{ horse: "horse-11.jpg", attribution: "N/A" },
{ horse: "horse-12.jpg", attribution: "N/A" },
{ horse: "horse-13.jpg", attribution: "N/A" },
{ horse: "horse-15.jpg", attribution: '<a href="https://www.pexels.com/photo/animal-silhouette-horizon-horse-9797/">link</a>' },
{ horse: "horse-16.jpg", attribution: '<a href="http://www.publicdomainpictures.net/view-image.php?image=112139&picture=horse-head-through-window">link</a>' },
{ horse: "horse-17.jpg", attribution: '<a href="https://www.flickr.com/photos/82182478@N00/5210454901">flickr-link</a>' }
];
var fontHandler = 0;
var ctx;
var col = 0;
var multi = 1;
var degreeOfHelj = 1.0;
var horses = new Array();
function initCache()
{
var i;
for (i=0; i<horsies.length; i++) {
var e = document.createElement("IMG");
e.src = horsies[i].horse;
horses.push(e);
}
}
function printDiff(t)
{
var str = "";
if (t.d > 1)
str = t.d + " days";
else if (t.d == 1)
str = t.d + " day";
if (t.h > 1)
str += " " + t.h + " hours";
else if (t.h == 1)
str += " " + t.h + " hour";
else if (t.d > 0)
str += " 0 hours";
if (t.m > 1)
str += " " + t.m + " minutes";
else if (t.m == 1)
str += " " + t.m + " minute";
else if (t.d > 0 || t.h > 0)
str += " 0 minutes";
if (t.s > 1)
str += " " + t.s + " seconds";
else if (t.s == 1)
str += " " + t.s + " second";
else if (t.d > 0 || t.h > 0 || t.m > 0)
str += " 0 seconds";
return str;
}
var fredda = 0;
var helj = 0;
function diffTime(thent) {
var n = new Date();
var t = new Date(thent);
var difft = t.getTime() - n.getTime();
difft = difft/1000;;
var diff = {
d:parseInt((difft/60/60/24)),
h:parseInt((difft/60/60)%24),
m:parseInt((difft/60)%60),
s:parseInt(difft%60)
}
return diff;
}
function doit()
{
var diff = diffTime("2024-03-22T09:00:00+0100");
var out1 = document.getElementById("output1");
out1.innerHTML = "in " + printDiff(diff);
}
function pickHorsy()
{
var horse = document.getElementById("horse");
var at = document.getElementById("attribution");
var n = parseInt(1+Math.random()*13);
horse.src = horsyHorse.horse;
at.innerHTML = "Picture attribution: " + horsyHorse.attribution;
horse.style.display = "";
horse.style.left = "30%";
horse.style.top = "170px";
horse.style.width = "40%"
horse.onclick = clickHandler;
}
function clickHandler() {
rotateHorsy();
pickHorsy();
}
function horsy()
{
pickHorsy();
}
function initIt() {
ctx = document.getElementById("hiddenCanvas").getContext('2d');
drawGradient(["blue","red","green","white","black","orange","purple","pink", "brown", "pink", "red" ]);
rotateHorsy();
horsy();
setInterval(rotateHorsy,60 * 1000);
setInterval(doit, 1000);
doit();
document.onclick = clickHandler;
setTimeout(initCache,10000);
}
function setFontColor() {
var e = document.getElementById('blah');
e.style.color = getColorStop(col);
col = col + multi;
if (col == 1000 || col == 0) {
multi = multi * -1;
}
}
function drawGradient(gradients)
{
var gradient = ctx.createLinearGradient(0,0,1000,0);
var stops = gradients.length - 1;
for (var color in gradients) {
var i = color / stops;
gradient.addColorStop(i, gradients[color]);
}
ctx.beginPath();
ctx.strokeStyle = gradient;
ctx.moveTo(0,0);
ctx.lineTo(1000,0);
ctx.lineWidth = 10;
ctx.closePath();
ctx.stroke();
ctx.moveTo(0,0);
}
/*
* Get the color of a gradient, range is from 0 to 999 (inclusive).
*/
function getColorStop(x) {
x = parseInt(x);
if (x > 999)
x = 999;
if (x < 0)
x = 0;
return getColor(x,0);
}
/*
* Get the color on the hidden canvas at a specific point. Could easily be
* made generic.
*/
function getColor(x,y) {
var imageData = ctx.getImageData(x, y, 1, 1);
var data = imageData.data;
if (data.length < 4)
return false;
var ret = 'rgb(' + data[0] + ',' + data[1] + ',' + data[2] + ')';
return ret;
}
var horsyHorse;
function rotateHorsy() {
var n = parseInt(Math.random()*horsies.length);
horsyHorse = horsies[n];
}
</script>
</body>
</html>