html5-canvas rect(路径命令)
示例
context.rect(leftX, topY, width, height)
在给定的左上角以及宽度和高度的情况下绘制一个矩形。
<!doctype html>
<html>
<head>
<style>
body{ background-color:white; }
#canvas{border:1px solid red; }
</style>
<script>
window.onload=(function(){
//获取对canvas元素及其上下文的引用
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
//论点
var leftX=25;
var topY=25;
var width=40;
var height=25;
// A rectangle drawn using the "rect" command.
ctx.beginPath();
ctx.rect(leftX, topY, width, height);
ctx.stroke();
}); //结束window.onload
</script>
</head>
<body>
<canvas id="canvas" width=200 height=150></canvas>
</body>
</html>该context.rect是一个独特的绘图命令,因为它增加了断开的矩形。
这些断开的矩形不会自动通过线连接。
<!doctype html>
<html>
<head>
<style>
body{ background-color:white; }
#canvas{border:1px solid red; }
</style>
<script>
window.onload=(function(){
//获取对canvas元素及其上下文的引用
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
//论点
var leftX=25;
var topY=25;
var width=40;
var height=25;
// Multiple rectangles drawn using the "rect" command.
ctx.beginPath();
ctx.rect(leftX, topY, width, height);
ctx.rect(leftX+50, topY+20, width, height);
ctx.rect(leftX+100, topY+40, width, height);
ctx.stroke();
}); //结束window.onload
</script>
</head>
<body>
<canvas id="canvas" width=200 height=150></canvas>
</body>
</html>
热门推荐
10 简短元宵节祝福语
11 新郎朋友祝福语简短大气
12 幼师离别祝福语老师简短
13 虎年元旦祝福语大全 简短
14 开锁祝福语简短走心
15 送病人简短的祝福语
16 夜雨祝福语简短10字
17 鼠年同事祝福语简短创意
18 女孩结婚祝福语大全简短