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循环出每个数组的每个圆的位置
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();
}
}
}
}
你应该还发现了你出来的不是圆,所以在renderDigit函数里找问题。画圆设参数时圆心y坐标那里y+j*2*。。。那里是i。是y+i*2.。。