-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
143 lines (133 loc) · 3.92 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
<!doctype html>
<html>
<head>
<title>What Color is the Sky in Berlin?</title>
<meta charset="utf8">
<meta name="viewport" content="width=device-width">
<style>
html, body {
padding: 0;
margin: 0;
color: #333;
}
html {
font-family: sans-serif;
text-align: center;
font-size: 12px;
height: 100%;
}
body {
background-repeat: no-repeat;
background-position: center center;
background-size: contain;
}
a {
color: inherit;
}
h1 {
font-size: 15px;
}
strong {
font-size: 55px;
display: block;
position: fixed;
top: 50%;
margin-top: -80px;
width: 100%;
}
footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
opacity: .5;
}
</style>
<script>
var yql = 'http://query.yahooapis.com/v1/public/yql?format=json&callback=imageLoaded&q=',
query = 'select * from data.uri where url="http://www.met.fu-berlin.de/wetter/webcam/Cam00_prev.jpg"',
img = new Image,
canvas = document.createElement("canvas"),
head = document.querySelector('head'),
favicon;
function init() {
loadImage();
}
function loadImage() {
var script = document.createElement('script');
script.src = yql + encodeURIComponent(query);
head.appendChild(script);
}
function imageLoaded(response) {
img.src = response.query.results.url;
}
function setFavicon(color) {
if(! favicon) {
favicon = document.createElement('link');
favicon.type = 'image/x-icon';
favicon.rel = 'icon';
head.appendChild(favicon);
}
var canvas = document.createElement('canvas'),
ctx;
if (canvas.getContext) {
canvas.height = canvas.width = 16; // set the size
ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(' + color.join(',') + ')';
ctx.fillRect(0, 0, 16, 16);
favicon.href = canvas.toDataURL('image/png');
}
}
function setBackgroundImage(color) {
var svg = document.getElementById('svg');
document.body.style.backgroundImage = 'url("data:image/svg+xml;utf8,'
+ encodeURIComponent(svg.parentNode.innerHTML) + '")';
}
img.onload = function() {
var color = getSkyColor(img, canvas);
// show color
document.body.style.backgroundColor = 'rgb(' + color.join(',') + ')';
document.body.style.color = 'rgb(' + color.map(function(c) { return 255 - c; }).join(',') + ')';
var target = document.getElementById('color');
target.innerHTML = '#' + hex(color)
+ '<br>' + findNearest(color);
// update favicon
setFavicon(color);
setBackgroundImage(color);
}
</script>
</head>
<body title="Yeah, that's the color of it...">
<header>
<h1>What Color is the Sky in Berlin?</h1>
</header>
<strong id="color">Loading...</strong>
<footer>
<p>
Follow <a href="https://twitter.com/skyofberlin" target="_blank">@skyofberlin on Twitter</a> •
data source <a href="http://www.met.fu-berlin.de/de/wetter/webcam/" target="_blank">Met FU Berlin</a> •
<a href="http://salomvary.github.io/whatcoloristheskyinsf">SF edition</a> •
brought to you by <a href="http://twitter.com/salomvary" target="_blank">@salomvary</a>
</p>
</footer>
<div style="display:none">
<svg width="50" height="500" version="1.1"
xmlns="http://www.w3.org/2000/svg" id="svg" fill="#fff">
<g opacity="0.2">
<polygon points="25,0 40,500 10,500"/>
<circle r="25" cx="25" cy="190"/>
</g>
</svg>
</div>
<script src="colors.js"></script>
<script>init();</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-26943877-4', 'salomvary.github.io');
ga('send', 'pageview');
</script>
</body>
</html>