/
index.html
166 lines (129 loc) · 4.11 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
<!--
http://graphical.weather.gov/xml/
http://graphical.weather.gov/sectors/midatlantic.php#tabs
http://openweathermap.org/api
-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
* { margin:0; padding:0; }
html, body { width:100%; height:100%; }
canvas { display:block; }
</style>
</head>
<body>
<canvas id="mainCanvas" style="border:none;">you're using a toaster.</canvas>
<script id="vs-ScreenSpace" type="x-shader/x-vertex">
attribute vec2 vTexCoord;
attribute vec4 vPosition;
varying vec2 v_texCoord;
void main()
{
gl_Position = vec4(vPosition.xy, 0.,1.);
v_texCoord = vec2(vTexCoord.s ,1. - vTexCoord.t);
}
</script>
<script id="fs-FontSampler" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D font;
uniform vec2 screenResolution;
uniform float time;
varying vec2 v_texCoord;
const float INV_256 = 0.00390625;
const float SQ_256 = 256. * 256.;
const vec2 TILE_SIZE = vec2(16.,16.);
const vec2 TEXTURE_SIZE = vec2(4096.);
float timeSeed(){ return floor((mod (time, 1000.) + 1000.) * 0.012 ); }
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233)) - timeSeed()) * 43758.5453);
}
void main()
{
float t = time * 0.005;
vec2 texCoord = vec2(v_texCoord.s, 1.0 - v_texCoord.t);
vec2 screen_to_texture_ratio = TEXTURE_SIZE / screenResolution;
//HACK (OS): Not using actual pixels but proportions I acquire from the browser
vec2 screenSpace_cornerUL = (floor(texCoord * screenResolution / 16.) * 16.) / screenResolution;
vec2 screenSpace_coordinate = texCoord; //TODO (OS): fill in later
float idx = floor( rand(screenSpace_cornerUL) * SQ_256 );
vec2 textureSpace_cornerUL = vec2(mod(idx, 256.), idx * INV_256) * INV_256;
vec2 sampleCoord = textureSpace_cornerUL + (screenSpace_coordinate - screenSpace_cornerUL) / screen_to_texture_ratio;
vec4 color = texture2D(font, sampleCoord);
color.xyz = 1. - color.xyz;
gl_FragColor = color;
}
</script>
<script id="fs-Main" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D mainTex;
uniform sampler2D bg;
varying vec2 v_texCoord;
uniform vec2 screenResolution;
uniform float image_presence;
const float SPREAD_SIZE = 0.001;
void main()
{
vec2 uv = v_texCoord * 0.5;
vec2 uv_norm = gl_FragCoord.xy / screenResolution.xy;
vec2 uv_norm_flipy = vec2(uv_norm.x, 1. - uv_norm.y);
float spread = 0.;
for (int j = -1 ; j <= 1; j++)
{
for (int i = -1 ; i <= 1; i++)
{
spread = max(spread, texture2D(mainTex, vec2(i,j) * SPREAD_SIZE + uv).r);
}
}
vec4 color = texture2D(mainTex, uv);
color.a = color.x;
color += spread * vec4(0.,0.,0.,1.);
color = clamp(color, vec4(0.), vec4(1.));
vec3 bg_color = vec3(0.,0.,0.6);
vec3 bg_imgcolor = mix(bg_color, texture2D(bg, uv_norm_flipy).xyz, image_presence);
color.xyz = color.a * color.xyz + bg_imgcolor.xyz * (1. - color.a);
// color.xyz = bg_imgcolor.xyz;
color.a = 1.;
gl_FragColor = color;
}
</script>
<script src="js/request.js"></script>
<script src="js/keys.js"></script>
<script src="js/timer.js"> </script>
<script src="js/main.js"> </script>
<script type="text/javascript">
RequestLocationFromRemoteService()
.then(JSON.parse, Error)
.then(x => Flickr.RequestSearchByLatLong(x.location.lat, x.location.lng))
.then(JSON.parse, Error)
.then(x => {
//select a photo randomly
let pic = x.photos.photo[Math.floor(Math.random() * x.photos.photo.length)]
return Flickr.RequestGetSizes(pic.id)
})
.then(JSON.parse, Error)
.then(x => {
let img_src = x.sizes.size[Math.max(x.sizes.size.length - 2, 0)].source
LoadTextureFromSource("bg", img_src, {
"min" : gl.LINEAR,
"mag": gl.LINEAR,
"wrap": gl.CLAMP_TO_EDGE,
"generateMipmap" : false})
})
.then(x => {
BindTextureAt(textures["bg"], gl.TEXTURE_2D, 2)
}, Error)
//Wait for bind
.then(x => Timer.Count(2000))
//fade
.then(x => Timer.Count(500, (rel, abs, del, rem) => {
let pgm = programs.get("Main")
let val = Math.min(rel / 200., 1.)
WithProgram(pgm, () => {
gl.uniform1f(gl.getUniformLocation(pgm, "image_presence"), val)
})
}))
</script>
</body>
</html>