-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
61 lines (58 loc) · 2.01 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
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixelate</title>
<link rel="stylesheet" type="text/css" href="normalize.css" />
<link rel="stylesheet" type="text/css" href="default.css">
<style type="text/css">
.thumb{margin-left: 5em;}
.thumb img{max-width: 400px;}
</style>
<!--[if IE]>
<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<header class="htmleaf-header">
<h1><span>Pixelate an image with <canvas> a la Chuck Close</span></h1>
</header>
<div class="content bgcolor-8">
<p class="center">Change pixel resolution <input type="range" min="4" max="100" value="32" id="range" /> <span id="output">32</span></p>
<div class="thumb">
<img src="img/1.jpg" id="dolly1" />
<img src="img/2.jpg" id="dolly2" />
<img src="img/3.jpg" id="dolly3" />
</div>
</div>
</div>
<script src="close-pixelate.js"></script>
<script>
window.onload = function() {
var dolly1 = document.getElementById('dolly1')
var dolly2 = document.getElementById('dolly2')
var dolly3 = document.getElementById('dolly3')
var pixelOpts = [ { resolution: 32 } ]
var pixelDolly1 = dolly1.closePixelate( pixelOpts )
var pixelDolly2 = dolly2.closePixelate( pixelOpts )
var pixelDolly3 = dolly3.closePixelate( pixelOpts )
var range = document.getElementById('range')
var output = document.getElementById('output')
range.addEventListener( 'change', function( event ) {
var res = parseInt( event.target.value, 10 )
res = Math.floor( res / 2 ) * 2
res = Math.max( 4, Math.min( 100, res ) )
output.textContent = res
// console.log( res );
pixelOpts = [ { resolution: res } ]
pixelDolly1.render( pixelOpts )
pixelDolly2.render( pixelOpts )
pixelDolly3.render( pixelOpts )
}, false )
}
</script>
</body>
</html>