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

画不出七巧板,是不是代码出错了?

画不出七巧板,是不是代码出错了?

游赛腾 2017-02-05 14:17:12
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title></title></head><body><canvas id="canvas1" style = "border:1px solid #aaa"></canvas><script> var tangram = [ {p:[{x:0,y:0},{x:800,y:0},{x:400,y:400},color:"#caff67"]}, {p:[{x:0,y:0},{x:400,y:400},{x:0,y:800},color:"#67becf"]}, {p:[{x:800,y:0},{x:800,y:400},{x:600,y:600},color:"#ef3d61"]}, {p:[{x:600,y:200},{x:600,y:600},{x:400,y:400},color:"#f9f51a"]}, {p:[{x:400,y:400},{x:600,y:600},{x:400,y:800},color:"#a594c0"]}, {p:[{x:200,y:600},{x:400,y:800},{x:0,y:800},color:"#fa8ecc"]}, {p:[{x:800,y:400},{x:800,y:800},{x:400,y:800},color:"#f6ca29"]} ]//设置七块板 window.onload = function(){ var canvas = document.getElementById("canvas1"); canvas.width = 1024; canvas.height = 1024; var context = canvas.getContext("2d"); for(var i=0;i < tangram.length;i++){ drwa(tangram[i],context); } } function drwa(ps,ctx){ ctx.beginPath(); ctx.moveTo(ps.p[0].x,ps.p[0].y); for(var i = 1; i < ps.p.length;i++){ ctx.lineTo(ps.p[i].x,ps.p[i].y); } ctx.closePath(); ctx.fillStyle = ps.color; ctx.fill(); }//画图函数</script></body></html>
查看完整描述

3 回答

已采纳
?
蜂之谷

TA贡献564条经验 获得超863个赞

中括号的位置错了

var tangram = [
{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"#caff67"},
{p:[{x:0,y:0},{x:400,y:400},{x:0,y:800}],color:"#67becf"},
{p:[{x:800,y:0},{x:800,y:400},{x:600,y:600}],color:"#ef3d61"},
{p:[{x:600,y:200},{x:600,y:600},{x:400,y:400}],color:"#f9f51a"},
{p:[{x:400,y:400},{x:600,y:600},{x:400,y:800}],color:"#a594c0"},
{p:[{x:200,y:600},{x:400,y:800},{x:0,y:800}],color:"#fa8ecc"},
{p:[{x:800,y:400},{x:800,y:800},{x:400,y:800}],color:"#f6ca29"}
]//设置七块板


查看完整回答
反对 回复 2017-02-06
  • 3 回答
  • 0 关注
  • 1511 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信