第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么會(huì)沒(méi)有結(jié)果呢?求大神指點(diǎn)

<!DOCTYPE?html>
<html>
<head>
	<meta?charset?=?"utf-8">
	<title>canvas繪制七巧板</title>
</head>
<body>
	<canvas?id?=?"canvas"?style="display:block;?margin:0px?auto;?border:1px,solid,#ccc;"></canvas>

	<script>
	//定義變量數(shù)組
	var?tangram?=?[
		{p:[{x:250,y:50},{x:750,y:50},{x:500,y:300}],color:"#DE9D9D"},
		{p:[{x:250,y:50},{x:250,y:550},{x:500,y:300}],color:"#94B892"},
		{p:[{x:375,y:425},{x:250,y:550},{x:500,y:550}],color:"#E2BB47"},
		{p:[{x:375,y:425},{x:500,y:550},{x:625,y:375},{x:500,y:300}],color:"#7B5287"},
		{p:[{x:500,y:550},{x:625,y:375},{x:750,y:550}],color:"#587CA6"},
		{p:[{x:625,y:375},{x:750,y:550},{x:500,y:550}],color:"#437240"},
		{p:[{x:625,y:375},{x:625,y:125},{x:750,y:50},{x:750,y:300}],color:"#5970A4"}
	]

	//繪制
	window.onload?=?function(){

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

		canvas.width?=?800;
		canvas.height?=?800;

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

		for(var?i?=?0?;i?<?tangram.length;i?++)
			draw(tangram[i],context);
	}

	//繪制函數(shù)
	function?draw(piece,cxt){
		
		cxt.beginPath();

		cxt.movtTo(piece.p[0].x,piece.p[0].y);

		for(var?i?=?1;i?<?piece.p.length;i?++)
			cxt.lineTo(piece.p[i].x,piece.p[i].y);
		
		cxt.closePath();	

		cxt.fillStyle?=?piece.color;
		cxt.fill();
	}
	</script>
</body>
</html>


正在回答

4 回答

好多函數(shù)名都寫錯(cuò)了啊。。。

<!DOCTYPE html>

<html>

<head>

? ? <meta charset = "utf-8">

? ? <title>canvas繪制七巧板</title>

</head>

<body>

? ? <canvas id = "canvas" style="display:block; margin:0px auto; border:1px,solid,#ccc;"></canvas>

?

? ? <script>

? ? //定義變量數(shù)組

? ? var tangram = [

? ? ? ? {p:[{x:250,y:50},{x:750,y:50},{x:500,y:300}],color:"#DE9D9D"},

? ? ? ? {p:[{x:250,y:50},{x:250,y:550},{x:500,y:300}],color:"#94B892"},

? ? ? ? {p:[{x:375,y:425},{x:250,y:550},{x:500,y:550}],color:"#E2BB47"},

? ? ? ? {p:[{x:375,y:425},{x:500,y:550},{x:625,y:375},{x:500,y:300}],color:"#7B5287"},

? ? ? ? {p:[{x:500,y:550},{x:625,y:375},{x:750,y:550}],color:"#587CA6"},

? ? ? ? {p:[{x:625,y:375},{x:750,y:550},{x:500,y:550}],color:"#437240"},

? ? ? ? {p:[{x:625,y:375},{x:625,y:125},{x:750,y:50},{x:750,y:300}],color:"#5970A4"}

? ? ]

?

? ? //繪制

? ? window.onload = function(){

?

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

?

? ? ? ? canvas.width = 800;

? ? ? ? canvas.height = 800;

?

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

?

? ? ? ? for(var i = 0 ;i < tangram.length;i ++)

? ? ? ? ? ? draw(tangram[i],context);

? ? ? ? ? ? // console.log(context);

? ? }

?

? ? //繪制函數(shù)

? ? function draw(piece,cxt){

? ? ? ? ?

? ? ? ? cxt.beginPath();

?

? ? ? ? cxt.moveTo(piece.p[0].x,piece.p[0].y);

?

? ? ? ? for(var i = 1;i < piece.p.length;i ++)

? ? ? ? ? ? cxt.lineTo(piece.p[i].x,piece.p[i].y);

? ? ? ? ?

? ? ? ? cxt.closePath(); ??

?

? ? ? ? cxt.fillStyle = piece.color;

? ? ? ? cxt.fill();

? ? }

? ? </script>

</body>

</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

不想采蜜的工蜂 提問(wèn)者

非常感謝!
2016-07-19 回復(fù) 有任何疑惑可以回復(fù)我~

數(shù)組的遍歷是從0開始的,最后一個(gè)數(shù)的位置是length-1.。。。。

0 回復(fù) 有任何疑惑可以回復(fù)我~

for 循環(huán)中i是從0開始的,而不是1

0 回復(fù) 有任何疑惑可以回復(fù)我~


//定義變量數(shù)組

var tangram = [

? ? {p:[{x:0,y:0},{x:600,y:0},{x:300,y:300}],color:"#CAFF67"},

? ? {p:[{x:0,y:0},{x:0,y:600},{x:300,y:300}],color:"#67BECF"},

? ? {p:[{x:600,y:0},{x:600,y:300},{x:450,y:450},{x:450,y:150}],color:"#EF3D61"},

? ? {p:[{x:450,y:150},{x:450,y:450},{x:300,y:300}],color:"#F9F51A"},

? ? {p:[{x:300,y:300},{x:450,y:450},{x:300,y:600},{x:150,y:450}],color:"#A594C0"},

? ? {p:[{x:150,y:450},{x:300,y:600},{x:0,y:600}],color:"#FA8CCC"},

? ? {p:[{x:600,y:600},{x:300,y:600},{x:600,y:300}],color:"#F6CA29"}

]


//繪制

window.onload = function(){


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


? ? canvas.width = 600;

? ? canvas.height = 600;


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


? ? for(var i = 0 ;i < tangram.length;i ++)

? ? ? ? draw(tangram[i],context);

? ? ? ? // console.log(context);

}


//繪制函數(shù)

function draw(piece,cxt){

? ? ?

? ? cxt.beginPath();


? ? cxt.moveTo(piece.p[0].x,piece.p[0].y);


? ? for(var i = 1;i < piece.p.length;i ++)

? ? ? ? cxt.lineTo(piece.p[i].x,piece.p[i].y);

? ? ?

? ? cxt.closePath(); ??


? ? cxt.fillStyle = piece.color;

? ? cxt.fill();

}

完整的JS部分

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

飛天意大利面神獸

這個(gè)數(shù)組才是對(duì)的。
2016-10-20 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么會(huì)沒(méi)有結(jié)果呢?求大神指點(diǎn)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)