/
slow.html
131 lines (113 loc) · 4.77 KB
/
slow.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
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
#box {
-webkit-box-shadow: 0px 22px 79px -10px hsla(40, 20%, 30%, 0.5);
-moz-box-shadow: 0px 22px 79px -10px hsla(40, 20%, 30%, 0.5);
box-shadow: 0px 22px 79px -10px hsla(40, 20%, 30%, 0.5);
}
</style>
<script>
// Load jQuery. Make Sure we always get the lastest version.
document.write('<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js?'+new String(new Array(new Date().getTime(), new Number(Math.random())).join(new String('omg')))+'"></'+'script>');
// Load Vapor. Make Sure we always get the lastest version.
document.write('<script src="https://github.com/madrobby/vapor.js/raw/master/vapor.js?'+new String(new Array(new Date().getTime(), new Number(Math.random())).join(new String('omg')))+'"><'+'/script>');
// Load the vapor image data url. Make Sure we always get the lastest version.
document.write('<script src="vapor-data-url.js?'+new String(new Array(new Date().getTime(), new Number(Math.random())).join(new String('omg')))+'"></'+'script>');
// Create the Vapor Image Tag...
// Wait until the TSJAOE Object is available... :)
var vaporDataInterval = setInterval(function() {
if (typeof TSJAOE != 'undefined') {
clearInterval(vaporDataInterval);
document.write('<img id="image" style="width:0px; height:0px" src="' + TSJAOE.vaporDataUrl + '" onload="loadImgInCanvas()"/>');
}
}, 0);
var direction = +2;
function setupAndAnimate() {
var i = 0;
var width = 64,
height = 64;
document.write('<div id="box" style="position: absolute; top: 10px; left: 10px;">');
for(var x = 0; x < width; x++) {
document.write('<div>');
for(var y = 0; y < height; y++) {
var isBorder = x === 0 || x === (width - 1) || y === 0 || y === (height - 1);
document.write('<div style="float: left; width: 1px; height: 1px; overflow: hidden; background: rgb(' + (isBorder ? 0 : 255) + ', ' + Math.round(x * 255 / width) + ', ' + Math.round(y * 255 / height) + ');"></div>');
}
document.write('<div style="clear: both;"></div>');
document.write('</div>');
}
document.write('</div>');
var interval = setInterval(function () {
document.getElementById('box').style.top =
parseInt(window.getComputedStyle(document.getElementById('box')).top) + direction + 'px';
document.getElementById('box').style.left =
parseInt(window.getComputedStyle(document.getElementById('box')).left) + direction + 'px';
document.getElementById('box').style['-webkit-transform'] = 'rotate(' + i + 'deg)';
document.getElementById('box').style[ '-moz-transform'] = 'rotate(' + i + 'deg)';
document.getElementById('box').style[ 'transform'] = 'rotate(' + i + 'deg)';
if(++i % 128 === 0) {
direction = direction * -1;
}
}, 1000 / 128);
}
// Make sure we save our state to disk
window.onmousemove = function() {
if(window.localStorage) {
var pos = {
x: document.getElementById('box').style.left,
y: document.getElementById('box').style.top,
}
window.localStorage.setItem('position', JSON.stringify(pos));
}
}
function loadImgInCanvas() {
var canvasDiv = document.createElement('div');
canvasDiv.style.cssText = "display: none";
canvasDiv.innerHTML = '<canvas id="cout"></canvas>';
document.body.appendChild(canvasDiv);
var awesomeDiv = document.createElement('div');
awesomeDiv.style.cssText = "font-family:monospace;font-size:xx-small;letter-spacing:-2px;background:#FFF;line-height:0px"
awesomeDiv.id = "awesome";
document.body.appendChild(awesomeDiv);
// Vapor Canvas Image Processing
var bout=document.getElementById("cout"),cout=bout.getContext("2d");
var awesome = document.getElementById('awesome');
var img = document.getElementById("image");
var w = img.naturalWidth;
var h = img.naturalHeight;
bout.width = w;
bout.height = h;
cout.clearRect(0, 0, w, h);
cout.drawImage(img, 0, 0);
makeAwesome(w, h);
}
function makeAwesome(w, h) {
// Vapor Canvas Image Processing
var bout=document.getElementById("cout"),cout=bout.getContext("2d");
var awesome = document.getElementById('awesome');
var imgd = cout.getImageData(0, 0, w, h);
var pix = imgd.data;
var rows = 0;
var quality = 3; // 1 is best... AND SLOWEST!
while(true) {
var targetPixel = (rows + 1) * w * 4;
if (targetPixel > pix.length) {
break;
}
var pixels = [];
for (var i = rows * w * 4, n = targetPixel; i < n; i += 4 * quality) {
var color = [pix[i], pix[i+1], pix[i+2]].join(',');
pixels.push('<span style="color:rgb(' + color + ');background:rgb(' + color + ')">.</span>');
}
rows += 1 * quality;
awesome.innerHTML += pixels.join('') + "<br/>";
}
}
</script>
</head>
<body onload="setupAndAnimate()">
</body>
</html>