Ver Código Fonte

support importing the pixl world.

neat.
Lucas Stadler 12 anos atrás
pai
commit
5c71152a0c
1 arquivos alterados com 31 adições e 0 exclusões
  1. 31 0
      js/pixl/public/trixl.html

+ 31 - 0
js/pixl/public/trixl.html

@ -70,6 +70,17 @@
70 70
				return l + i;
71 71
			});
72 72
		}
73
74
		var rgbFromCss = function(color) {
75
			var el = document.createElement('div');
76
			el.style.color = color;
77
			var style = getComputedStyle(el);
78
			var rgb = style.getPropertyCSSValue('color').getRGBColorValue();
79
			var f = function(val) {
80
				return val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
81
			}
82
			return [f(rgb.red), f(rgb.green), f(rgb.blue), f(rgb.alpha)];
83
		}
73 84
	</script>
74 85
	<script>
75 86
		window.trixl = {};
@ -315,6 +326,26 @@
315 326
			gl.viewport(0, 0, trixl.window.w, trixl.window.h);
316 327
			trixl.redraw();
317 328
		}
329
330
		trixl.importPixls = function(url) {
331
			var xhr = new XMLHttpRequest();
332
			xhr.open('GET', url || 'http://pixl.papill0n.org/world');
333
			xhr.onreadystatechange = function() {
334
				if (xhr.readyState == 4) {
335
					var world = JSON.parse(xhr.responseText);
336
					var keys = Object.keys(world);
337
					for (var i = 0; i < keys.length; i++) {
338
						var key = keys[i];
339
						var coords = key.split(',').map(function(n) { return parseInt(n); });
340
						var color = rgbFromCss(world[key].color)
341
						trixl.world.set([-coords[0], -coords[1], 0],
342
							{color: [color[0] / 255.0, color[1] / 255, color[2] / 255, color[3]]});
343
					}
344
				}
345
			}
346
			xhr.send();
347
		}
348
318 349
	</script>
319 350
</body>
320 351
</html>