課程
/前端開(kāi)發(fā)
/Html5
/炫麗的倒計(jì)時(shí)效果Canvas繪圖與動(dòng)畫(huà)基礎(chǔ)
給最后一個(gè)for循環(huán)后面的加上{},效果不顯示了出來(lái)。請(qǐng)問(wèn)這是為什么?
2016-02-07
源自:炫麗的倒計(jì)時(shí)效果Canvas繪圖與動(dòng)畫(huà)基礎(chǔ) 2-2
正在回答
我的是可以的...檢查一下?
?? ???? var tangram = [?? ??? ?//二維數(shù)組,頂點(diǎn)坐標(biāo),顏色?? ??? ??? ?{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},{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}],color:"#f6ca29"}?? ??? ?];?? ??? ?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)?? ??? ??? ?}?? ??? ?}?? ??? ?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();?? ??? ??? ?cxt.strokeStyle = "black";?? ??? ??? ?cxt.lineWidth = 3;?? ??? ??? ?cxt.stroke();?? ??? ?}
for后面的括號(hào)會(huì)不會(huì)是位置發(fā)錯(cuò)了呢?
for(var?i=0?;i<digit[num].length;i++) ????for(var?j=0;j<digit[num][i].length;j++) ????????if(digit[num][i][j]?==?1){ ????????????cxt.beginPath(); ????????????cxt.arc(x+j*2*(RADIUS+1)+(RADIUS+1),y+i*2*(RADIUS+1)+(RADIUS+1),RADIUS,0,2*Math.PI) ????????????cxt.closePath() ????????????cxt.fill() ????????}
舉報(bào)
學(xué)習(xí)HTML5中最激動(dòng)人心的技術(shù)Canvas,徹底釋放自己的創(chuàng)造力
5 回答為什么for循環(huán)不加大括號(hào),加上后就出不來(lái)效果??
1 回答for循環(huán)
1 回答為什么for循環(huán)只顯示最后一個(gè)
1 回答draw里面的for循環(huán)為什么不用加{ }
1 回答關(guān)于for循環(huán)遍歷
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-03-01
我的是可以的...檢查一下?
?? ???? var tangram = [
?? ??? ?//二維數(shù)組,頂點(diǎn)坐標(biāo),顏色
?? ??? ??? ?{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},{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}],color:"#f6ca29"}
?? ??? ?];
?? ??? ?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)
?? ??? ??? ?}
?? ??? ?}
?? ??? ?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();
?? ??? ??? ?cxt.strokeStyle = "black";
?? ??? ??? ?cxt.lineWidth = 3;
?? ??? ??? ?cxt.stroke();
?? ??? ?}
2016-02-09
for后面的括號(hào)會(huì)不會(huì)是位置發(fā)錯(cuò)了呢?