为了账号安全,请及时绑定邮箱和手机立即绑定

请问为什么显示不出来

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<style type="text/css">

#cvs{

/*border: solid 1px red;*/

display: block;

margin: 0 auto;

}

</style>

</head>

<body>

<canvas id="cvs"></canvas>

<script type="text/javascript">

var tang =[

{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"#dddddd"},

{p:[{x:0,y:0},{x:400,y:400},{x:0,y:800}],color:"#dddddd"},

{p:[{x:800,y:0},{x:800,y:400},{x:600,y:600},{x:600,y:200}],color:"#dddddd"},

{p:[{x:600,y:200},{x:600,y:600},{x:400,y:400}],color:"#dddddd"},

{p:[{x:400,y:400},{x:600,y:600},{x:400,y:800},{x:200,y:600}],color:"#dddddd"},

{p:[{x:200,y:600},{x:400,y:800},{x:0,y:800}],color:"#dddddd"},

{p:[{x:800,y:400},{x:800,y:800},{x:400,y:800}],color:"#ed4259"}

]

window.onload = function(){

console.log(tang);

var canvas =document.getElementById("cvs");

canvas.width = 800;

canvas.height  =800;

var context  =canvas.getContext("2d");

for(var i =0;i<tang.length;i++){

draw(tang[i],context)

}

}

function draw(nums,ctx){

ctx.beginPath();

ctx.moveTo(nums.p[0].x,nums.p[0].y);

for(var i=1;i<nums.p.legth;i++){

ctx.lineTo(nums.p[i].x,nums.p[i].y);

}

ctx.closePath();

ctx.fillStyle=nums.color;

ctx.fill();

}

</script>

</body>

</html>


正在回答

1 回答

function draw(nums,ctx){
        ctx.beginPath();
        ctx.moveTo(nums.p[0].x,nums.p[0].y);
        for(var i=1;i<nums.p.legth;i++){//  for(var i=1;i<nums.p.length;i++){
            ctx.lineTo(nums.p[i].x,nums.p[i].y);
        }
        ctx.closePath();
        ctx.fillStyle=nums.color;
        ctx.fill();
}

在上述代码中需要将nums.p.legth改为nums.p.length 单词拼写错误

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请问为什么显示不出来

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信