OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head></head> | |
4 <body> | |
5 <canvas id="mycanvas" width="400" height="200"></canvas> | |
6 <script> | |
7 //This tests checks that ellipse can draw correct circumferences with lineTo. | |
8 var canvas = document.getElementById('mycanvas'); | |
9 var ctx = canvas.getContext('2d'); | |
10 | |
11 ctx.lineWidth = 7; | |
12 ctx.fillStyle = 'rgb(255, 255, 255)'; | |
13 ctx.strokeStyle = 'rgb(0, 0, 0)'; | |
14 ctx.fillRect(0, 0, canvas.width, canvas.height); | |
15 | |
16 // Check clockwise circumference. | |
17 // 1. sweepAngle == 2PI | |
18 ctx.save(); | |
19 ctx.beginPath(); | |
20 ctx.moveTo(0, 10); | |
21 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, -Math.PI, Math.PI, false); | |
22 ctx.lineTo(0, 90); | |
23 ctx.stroke(); | |
24 ctx.restore(); | |
alph
2013/07/10 13:38:04
Again, as for the arc test, I suggest drawing a 2d
dshwang
2013/07/10 14:19:57
Yes, I think your idea is great.
| |
25 | |
26 // 2. sweepAngle == PI | |
27 ctx.translate(100, 0); | |
28 ctx.save(); | |
29 ctx.beginPath(); | |
30 ctx.moveTo(0, 10); | |
31 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, -Math.PI, 0, false); | |
32 ctx.lineTo(0, 90); | |
33 ctx.stroke(); | |
34 ctx.restore(); | |
35 | |
36 // 3. sweepAngle > 2PI | |
37 ctx.translate(100, 0); | |
38 ctx.save(); | |
39 ctx.beginPath(); | |
40 ctx.moveTo(0, 10); | |
41 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, -Math.PI, Math.PI * 2.5, false); | |
42 ctx.lineTo(0, 90); | |
43 ctx.stroke(); | |
44 ctx.restore(); | |
45 | |
46 // 4. sweepAngle < 0 | |
47 ctx.translate(100, 0); | |
48 ctx.save(); | |
49 ctx.beginPath(); | |
50 ctx.moveTo(0, 10); | |
51 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, Math.PI * 1.5, -Math.PI, false); | |
52 ctx.lineTo(0, 90); | |
53 ctx.stroke(); | |
54 ctx.restore(); | |
55 | |
56 // Check anticlockwise circumference. | |
57 // 1. sweepAngle == 2PI | |
58 ctx.translate(-300, 100); | |
59 ctx.save(); | |
60 ctx.beginPath(); | |
61 ctx.moveTo(0, 10); | |
62 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, Math.PI, -Math.PI, true); | |
63 ctx.lineTo(0, 90); | |
64 ctx.stroke(); | |
65 ctx.restore(); | |
66 | |
67 // 2. sweepAngle == PI | |
68 ctx.translate(100, 0); | |
69 ctx.save(); | |
70 ctx.beginPath(); | |
71 ctx.moveTo(0, 10); | |
72 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, Math.PI, 0, true); | |
73 ctx.lineTo(0, 90); | |
74 ctx.stroke(); | |
75 ctx.restore(); | |
76 | |
77 // 3. sweepAngle > 2PI | |
78 ctx.translate(100, 0); | |
79 ctx.save(); | |
80 ctx.beginPath(); | |
81 ctx.moveTo(0, 10); | |
82 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, Math.PI, Math.PI * -1.5, true); | |
83 ctx.lineTo(0, 90); | |
84 ctx.stroke(); | |
85 ctx.restore(); | |
86 | |
87 // 4. sweepAngle < 0 | |
88 ctx.translate(100, 0); | |
89 ctx.save(); | |
90 ctx.beginPath(); | |
91 ctx.moveTo(0, 10); | |
92 ctx.ellipse(60, 50, 30, 20, Math.PI / 6, Math.PI * -1.5, Math.PI, true); | |
93 ctx.lineTo(0, 90); | |
94 ctx.stroke(); | |
95 ctx.restore(); | |
96 | |
97 </script> | |
98 </body> | |
99 </html> | |
100 | |
OLD | NEW |