您的位置:首页 > Web前端 > HTML5

html5绘制变换图形-旋转图形

2016-05-08 21:17 323 查看
<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>图形的旋转</title>

<script>

function draw(id){

var c=document.getElementById('canvas');

if(c==null)

return false;

var cxt=c.getContext("2d");

cxt.fillStyle="aquamarine";

cxt.fillRect(0,0,400,300);

cxt.translate(200,50);

cxt.fillStyle="blue";

for(var i=0;i<500;i++){

cxt.rotate(Math.PI/15);//指定一个角度,改变画布坐标

cxt.fillRect(0,0,100,50);

}

}

</script>

</head>

<body onload="draw('canvas')">

<h1>图形的旋转</h1>

<canvas id="canvas" width="400" height="300" style="border:1px solid blue;"></canvas>

</body>

</html>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: