4-5练习 对吗
来源:4-5 编程练习
qq_紾悕_1
2019-05-30 16:30:32
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvasL</title>
<style>
canvas{background-color:lightblue;}
</style>
</head>
<body>
<canvas id="canvas" width="600px" height="600px">您的浏览器不支持</canvas>
<script>
// 在此处写出代码
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.translate(200,300);
ctx.rotate(Math.PI/3);
ctx.scale(0.5,0.5);
ctx.fillStyle="yellow";
ctx.fillRect(100,100,200,300);
</script>
</body>
</html>
1回答
你好,代码中是有问题的,题目中要求:
是圆点在(200,300)的位置,不是移动(200,300)哦。
translate()是移动的距离,开始矩形圆点在(100,100)的位置,那么需要移动100,200才会到(200,300)的位置,所以需要修改为:
可以重新测试下,祝学习愉快!