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

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

context在這里是全局變量吧,那么是不是在draw函數(shù)中就可以直接使用context來進(jìn)行繪制了,為什么還要在把context的值傳給cxt呢?求指點(diǎn)

$("#tangram").bind("click",function tangram() {
? ?var canvas = document.getElementById("canvas");
? ? canvas.width = 800;
? ? canvas.height = 700;
? ?if (canvas.getContext("2d")) {
? ? ? ?var context = canvas.getContext("2d");
? ?}
? ?else {
? ? ? ?alert("當(dāng)前瀏覽器不支持Canvas,推薦使用Chrome瀏覽器")
? ?}
? ?var tangram=[
? ? ? ?{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"red"},
? ? ? ?{p:[{x:0,y:0},{x:400,y:400},{x:0,y:800}],color:"yellow"},
? ? ? ?{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"red"},
? ? ? ?{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"red"},
? ? ? ?{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"red"},
? ? ? ?{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"red"},
? ? ? ?{p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"red"},
? ?]
? ?for (var i=0;i<tangram.length;i++){
? ? ? ?draw(tangram[i]);
? ?}
? ?function draw(piece){
? ? ? ?context.beginPath();
? ? ? ?context.moveTo(piece.p[0].x,piece.p[0].y);
? ? ? ?for (var i=1;i<piece.length;i++){
? ? ? ? ? ?context.lineTo(piece[i].x,piece[i].y);
? ? ? ?}
? ? ? ?context.closePath();
? ? ? ?context.fillStyle=tangram[0].color;
? ? ? ?context.fill();
? ?}

正在回答

1 回答

我的理解是對的,之所以沒畫出來,我的代碼錯(cuò)在這里了:

for (var i=1;i<piece.length;i++){
? ? ? ? ? ?context.lineTo(piece[i].x,piece[i].y);
? ? ? ?}

應(yīng)該是

i<piece.p.length

context.lineTo(piece.p[i].x,piece.p[i].y)



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

舉報(bào)

0/150
提交
取消

context在這里是全局變量吧,那么是不是在draw函數(shù)中就可以直接使用context來進(jìn)行繪制了,為什么還要在把context的值傳給cxt呢?求指點(diǎn)

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

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

幫助反饋 APP下載

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

公眾號

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