blob: a88bdc1c8659db1114c6b5f67d42e199828d9f79 (
plain)
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
|
<!doctype html>
<html>
<head>
<title>Dither</title>
</head>
<body>
<div>
<button id="random">random</button>
<button id="pattern2">pattern2</button>
<button id="pattern3">pattern3</button>
<button id="pattern4">pattern4</button>
<button id="pattern2Lite">pattern2lite</button>
<button id="pattern3Lite">pattern3lite</button>
<button id="pattern4Lite">pattern4lite</button>
<button id="floydSteinberg">floyd-steinberg</button>
<button id="right">right</button>
</div>
<div id="images"></div>
</body>
<script type="text/javascript" src="js/vendor/canvasquery.js"></script>
<script type="text/javascript" src="js/canvasquery.dither.js"></script>
<script type="text/javascript">
var algo = 'random';
var urls = ["img/abyss.png","img/building.png","img/gradient.jpg"]
var imgs = []
var complete = 0
urls.forEach(function(src){
var img = new Image ()
img.onload = ready
img.src = src
imgs.push(img)
if (img.complete) ready()
})
function ready(){
complete += 1
if (complete < imgs.length) return;
var buttons = document.getElementsByTagName("button")
for (var i = 0; i < buttons.length; i++) {
(function(n){
buttons[n].onclick = function(){
algo = buttons[n].id;
build()
}
})(i)
}
build()
}
function build(){
document.getElementById("images").innerHTML = ""
imgs.forEach(dither)
}
function dither(img){
var w = img.naturalWidth, h = img.naturalHeight;
var cc = cq(w, h)
cc.drawImage(img, 0, 0, w, h);
cc[algo + "Dither"]( )
cc.appendTo("#images")
}
</script>
</html>
|