forked from arhea/brushjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
128 lines (100 loc) · 2.75 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>HTML5 Canvas SVG</title>
<script src="canvassvg.js"></script>
</head>
<body>
<canvas id="SVG" width="600" height="600" style="border: solid 1px #999999; float: left;">Your browser does not support canvas.</canvas>
<div id="xml" style="border: solid 1px #999999; float: left;"></div>
<script>
(function() {
var ctx = new CanvasSVG( "#SVG" );
ctx.beginPath();
ctx.fillStyle = "#333333";
ctx.fillRect( 10 , 10 , 50 , 50 );
ctx.closePath();
ctx.beginPath();
var centerX = 288;
var centerY = 160;
var radius = 75;
var startingAngle = 1.1 * Math.PI;
var endingAngle = 1.9 * Math.PI;
var counterclockwise = false;
ctx.arc(centerX, centerY, radius, startingAngle,
endingAngle, counterclockwise);
ctx.lineWidth = 15;
ctx.strokeStyle = "black";
ctx.stroke();
ctx.closePath();
ctx.beginPath();
var controlX = 488;
var controlY = 0;
var endX = 588;
var endY = 150;
ctx.moveTo(388, 150);
ctx.quadraticCurveTo(controlX, controlY, endX, endY);
ctx.lineWidth = 5;
ctx.strokeStyle = "black";
ctx.stroke();
ctx.closePath();
ctx.beginPath();
ctx.moveTo(188, 330);
var controlX1 = 140;
var controlY1 = 310;
var controlX2 = 388;
var controlY2 = 310;
var endX = 388;
var endY = 470;
ctx.bezierCurveTo(controlX1, controlY1, controlX2,
controlY2, endX, endY);
ctx.lineWidth = 10;
ctx.strokeStyle = "black"; // line color
ctx.stroke();
ctx.closePath();
ctx.beginPath();
var centerX = 388;
var centerY = 200;
var radius = 70;
var lineWidth = 5;
ctx.arc(centerX, centerY, radius, 0, Math.PI, false);
ctx.lineWidth = lineWidth;
ctx.fillStyle = "#8ED6FF";
ctx.fill();
ctx.strokeStyle = "black";
ctx.stroke();
ctx.closePath();
ctx.fillStyle = "#333333";
ctx.fillText( "Sample Text" , 400 , 10 );
roundRect( ctx , 200 , 200, 25, 25, 3, true , false );
document.getElementById( "xml" ).innerHTML = ctx.toDataURL( "image/svg+xml" );
function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
if (typeof stroke == "undefined" ) {
stroke = true;
}
if (typeof radius === "undefined") {
radius = 5;
}
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
if (stroke) {
ctx.stroke();
}
if (fill) {
ctx.fill();
}
ctx.closePath();
}
})();
</script>
</body>
</html>