2 <title>Canvas test:
2d.transformation.transform.skewed
</title>
3 <!-- Testing: transform() with skewy matrix transforms correctly -->
4 <script src=
"/MochiKit/MochiKit.js"></script>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
8 <canvas id=
"c" width=
"100" height=
"50"><p class=
"fallback">FAIL (fallback content)
</p></canvas>
10 function isPixel(ctx
, x
,y
, r
,g
,b
,a
, pos
, colour
, d
) {
11 var pixel
= ctx
.getImageData(x
, y
, 1, 1);
12 var pr
= pixel
.data
[0],
16 ok(r
-d
<= pr
&& pr
<= r
+d
&&
17 g
-d
<= pg
&& pg
<= g
+d
&&
18 b
-d
<= pb
&& pb
<= b
+d
&&
19 a
-d
<= pa
&& pa
<= a
+d
,
20 "pixel "+pos
+" is "+pr
+","+pg
+","+pb
+","+pa
+"; expected "+colour
+" +/- "+d
);
23 SimpleTest
.waitForExplicitFinish();
24 MochiKit
.DOM
.addLoadEvent(function () {
26 var canvas
= document
.getElementById('c');
27 var ctx
= canvas
.getContext('2d');
29 // Create green with a red square ring inside it
30 ctx
.fillStyle
= '#0f0';
31 ctx
.fillRect(0, 0, 100, 50);
32 ctx
.fillStyle
= '#f00';
33 ctx
.fillRect(20, 10, 60, 30);
34 ctx
.fillStyle
= '#0f0';
35 ctx
.fillRect(40, 20, 20, 10);
37 // Draw a skewed shape to fill that gap, to make sure it is aligned correctly
38 ctx
.transform(1,4, 2,3, 5,6);
39 // Post-transform coordinates:
40 // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]];
41 // Hence pre-transform coordinates:
42 var pts
=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2],
43 [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2],
46 ctx
.moveTo(pts
[0][0], pts
[0][1]);
47 for (var i
= 0; i
< pts
.length
; ++i
)
48 ctx
.lineTo(pts
[i
][0], pts
[i
][1]);
50 isPixel(ctx
, 21,11, 0,255,0,255, "21,11", "0,255,0,255", 0);
51 isPixel(ctx
, 79,11, 0,255,0,255, "79,11", "0,255,0,255", 0);
52 isPixel(ctx
, 21,39, 0,255,0,255, "21,39", "0,255,0,255", 0);
53 isPixel(ctx
, 79,39, 0,255,0,255, "79,39", "0,255,0,255", 0);
54 isPixel(ctx
, 39,19, 0,255,0,255, "39,19", "0,255,0,255", 0);
55 isPixel(ctx
, 61,19, 0,255,0,255, "61,19", "0,255,0,255", 0);
56 isPixel(ctx
, 39,31, 0,255,0,255, "39,31", "0,255,0,255", 0);
57 isPixel(ctx
, 61,31, 0,255,0,255, "61,31", "0,255,0,255", 0);