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

无法出现七巧板,怎么回事?

无法出现七巧板,怎么回事?

qq_无意间哼出的旋律_0 2016-05-27 10:59:49
<!doctype html><html><head>    <meta charset="utf-8">    <script type="text/javascript" src="jquery-1.8.2.min.js"></script>    <title>tes6--H5关于七巧板</title>    <style type="text/css">    #myCanvas{display:block;border:1px solid #f00; margin:50px auto;}    </style></head><body>    <canvas id="myCanvas" width="800" height="800"></canvas></body><script type="text/javascript">$(document).ready(function(){    var sev=[        {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:"#67beef"},        {p:[{x:800,y:0},{x:800,y:400},{x:600,y:600},{x:600,y:200}],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},{x:200,y:600}],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},{x:600,y:200}],color:"#f6ca29"}    ]    window.onload=function(){        var box=document.getElementById('myCanvas');        var picture=box.getContext('2d');        for(i=0;i<sev.length;i++){            draw(sec[i],picture);        }    }    function draw(piece,pic){        pic.beginPath();        pic.moveTo(piece.p[0].x,piece.p[0].y);        for(i=0;i<piece.p.length;i++){            pic.lineTo(piece[i].x,piece[i].y)        }         pic.closePath();        pic.fillStyle=piece.color;        pic.fill();    }})</script></html>
查看完整描述

1 回答

?
蜂之谷

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

<script type="text/javascript">

var sev=[
	{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:"#67beef"},
	{p:[{x:800,y:0},{x:800,y:400},{x:600,y:600},{x:600,y:200}],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},{x:200,y:600}],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},{x:600,y:200}],color:"#f6ca29"}
]
var box=document.getElementById("myCanvas");
var picture=box.getContext('2d');                         
for(var i=0;i<sev.length;i++){
	draw(sev[i],picture);//这里sev写成了sec
}

function draw(piece,pic){
	pic.beginPath();
	pic.moveTo(piece.p[0].x,piece.p[0].y);
	for(var i=1;i<piece.p.length;i++){
		picture.lineTo(piece.p[i].x,piece.p[i].y);//这里应该是piece.p[i].x和piece.p[i].y
	}
	pic.closePath();
	pic.fillStyle=piece.color;
	pic.strokeStyle=piece.color;
	pic.fill();
	pic.stroke();
}	   

</script>

对着看看吧

查看完整回答
1 反对 回复 2016-05-27
  • 1 回答
  • 0 关注
  • 1226 浏览

添加回答

举报

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