summaryrefslogtreecommitdiff
path: root/threshold.html
blob: c32f738d45d86cf42cf6bf9b717d19ad6969e48a (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
<!doctype html>
<html>
<head>
<title>Threshold</title>
</head>
<body>
<div>
threshold <input type="range" min="0" max="1" step="0.01" value="0.5" id="threshold">
</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 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;
  document.getElementById("threshold").onchange = build
  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)
  var thresh = parseFloat(document.getElementById("threshold").value)
  console.log(thresh)
  cc.drawImage(img, 0, 0, w, h);
  cc.threshold( thresh )
  cc.appendTo("#images")
}
</script>
</html>