translate() メソッド
実行結果
コード
/* 元の矩形を赤色で描く */ ctx.fillStyle = "red"; ctx.fillRect(10, 10, 40, 30); /* 右に40、下に40ピクセル移動した矩形を青色で描く */ ctx.translate(40, 40); ctx.fillStyle = "blue"; ctx.fillRect(10, 10, 40, 30);
/* 元の矩形を赤色で描く */ ctx.fillStyle = "red"; ctx.fillRect(10, 10, 40, 30); /* 右に40、下に40ピクセル移動した矩形を青色で描く */ ctx.translate(40, 40); ctx.fillStyle = "blue"; ctx.fillRect(10, 10, 40, 30);