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