為什么最后顯示出來的全是1,而且還是斜著的呢
var window_width=1024;
var window_height=768;
var radius=8;
var margin_top=60;
var margin_left=30;
window.onload=function(){
var canvas=document.getElementById("canvas");
var context=canvas.getContext("2d");
canvas.width=window_width;
canvas.height=window_height;
render(context);
}
function render(cxt){
var hours=12;
var minutes=36;
var seconds=56;
renderDigit(margin_left,margin_top,parseInt(hours/10),cxt);
renderDigit(margin_left+15*(radius+1),margin_top,parseInt(hours%10),cxt);
renderDigit(margin_left+30*(radius+1),margin_top,10,cxt);
renderDigit(margin_left+39*(radius+1),margin_top,parseInt(minutes%10),cxt);
renderDigit(margin_left+54*(radius+1),margin_top,parseInt(minutes%10),cxt);
renderDigit(margin_left+69*(radius+1),margin_top,10,cxt);
renderDigit(margin_left+78*(radius+1),margin_top,parseInt(seconds%10),cxt);
renderDigit(margin_left+93*(radius+1),margin_top,parseInt(seconds%10),cxt);
}
function renderDigit(x,y,num,cxt){
cxt.fillStyle="red";
//x循環(huán)出每個(gè)數(shù)組的每個(gè)圓的位置
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+j*2*(radius+1)+(radius+1),radius, 0,2*Math.PI);
cxt.closePath();
cxt.fill();
}
}
}
}
2016-09-28
你應(yīng)該還發(fā)現(xiàn)了你出來的不是圓,所以在renderDigit函數(shù)里找問題。畫圓設(shè)參數(shù)時(shí)圓心y坐標(biāo)那里y+j*2*。。。那里是i。是y+i*2.。。