-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstipple.html
45 lines (37 loc) · 1.43 KB
/
stipple.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
<html>
<head>
<title>stipple</title>
<script type="text/javascript" src="stippler.js"></script>
</head>
<body>
<canvas id="canvas-out" width="800" height="800"></canvas>
<img id="image-in" src="./image1.jpg" style="display:none"/>
<script type="text/javascript">
function $(id) { return document.getElementById(id); }
var imgIn = $("image-in");
imgIn.onload = function() {
var canvasOut = $("canvas-out");
// Set output canvas proportions
if (imgIn.height < imgIn.width) {
canvasOut.height = canvasOut.width * imgIn.height/imgIn.width;
} else {
canvasOut.width = canvasOut.height * imgIn.width/imgIn.height;
}
// Scale image onto input canvas
var canvasIn = document.createElement("canvas");
canvasIn.width = canvasOut.width;
canvasIn.height = canvasOut.height;
var ctxIn = canvasIn.getContext("2d");
ctxIn.drawImage(imgIn,
0,0,imgIn.width,imgIn.height,
0,0,canvasIn.width, canvasIn.height);
var imgDataIn = ctxIn.getImageData(0,0,canvasIn.width,canvasIn.height);
var stippler = new Stippler(imgDataIn, canvasOut);
canvasOut.onclick = function() {
stippler.stop();
}
stippler.start();
}
</script>
</body>
</html>