svgcanvas/test/example/transform.js

25 lines
610 B
JavaScript
Raw Normal View History

2021-05-23 00:58:30 +08:00
window.C2S_EXAMPLES['transform'] = function(ctx) {
// case 1
ctx.fillStyle = "rgba(255, 0, 0, 0.5)";
ctx.setTransform(1,1,0,1,0,0);
ctx.fillRect(0,0,100,100);
2021-06-04 23:49:08 +08:00
ctx.resetTransform();
2021-05-23 00:58:30 +08:00
// case 2
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 50, 50);
2021-06-04 23:49:08 +08:00
ctx.resetTransform();
2021-05-23 00:58:30 +08:00
// case 3
ctx.fillStyle = "rgba(0, 0, 255, 0.5)";
2021-06-04 22:54:18 +08:00
ctx.beginPath();
2021-05-23 00:58:30 +08:00
ctx.moveTo(0, 0);
ctx.lineTo(100, 0)
ctx.transform(2, 0, 0, 2, 0, 0)
ctx.lineTo(100, 100)
2021-06-04 22:54:18 +08:00
ctx.transform(2, 0, 0, 1, 0, 0)
ctx.lineTo(100, 100)
2021-05-23 00:58:30 +08:00
ctx.closePath()
ctx.fill()
2021-06-04 23:49:08 +08:00
ctx.resetTransform();
2021-05-23 00:58:30 +08:00
}