/
index.image-and-simplify.html
97 lines (77 loc) · 1.73 KB
/
index.image-and-simplify.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
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/normalize.min.css">
<link rel="stylesheet" href="css/main.css">
<style>
p
{
position: absolute;
left: 0;
top: 0;
z-index:100;
margin: 0;
background: yellow;
}
svg
{
width: 700px;
height: 500px;
background: gray;
margin: 50px;
/* position:fixed;
left:0;
top:0;
margin:0;*/
}
html
{
height: 2000px;
}
</style>
</head>
<body>
<p id="pl">px box</p>
<p id="pg">global px box</p>
<div id="zsvg">ZSVG</div>
<script src="zsvg.js"></script>
<script>
var stage = new ZVG.Stage('zsvg').size(1000, 400);
var i = new ZVG.Image();
i.attr({width:'100%',height:'100%'});
stage.append(i);
i.src('http://i.imgur.com/sWE4ay8.png');
var p;
var path;
var drawing = false;
var listener = function(event) {
if(!drawing) return;
pt = stage.pxPointToSvgPoint(event.offsetX, event.offsetY);
p.pen.lineTo(pt.x, pt.y);
path.pen.lineTo(pt.x, pt.y);
};
stage.on('mousedown', function(event) {
drawing = true;
p = new ZVG.Polygon();
path = new ZVG.Path();
stage.append(p);
stage.append(path);
p.stroke('red', 10).fill('', 0);
path.stroke('white', 10, 0.5).fill('', 0);
})
stage.on('mouseup', function(event) {
p.simplify(5);
drawing = false;
})
stage.on('mousemove', listener);
stage.on('click', function(event) {
p.simplify(5);
});
</script>
</body>
</html>