手记

用for循环来绘制时钟的数字,不用写那么多重复的

function render(context) {
    var hours = 12;
    var minutes = 34;
    var seconds = 56;

    var number = [hours / 10, hours % 10, minutes / 10, minutes % 10, seconds / 10, seconds % 10];
    var colonDis = 0;
    for (var i = 0; i < number.length; i++) {
        renderDigit(MARGIN_LEFT + i * (15 * (RADIUS + 1)) + colonDis, MARGIN_TOP, parseInt(number[i]), context);
        if (i != number.length - 1 && i % 2 != 0) {
            renderDigit(MARGIN_LEFT + (i + 1) * (15 * (RADIUS + 1)) + colonDis, MARGIN_TOP, 10, context);
            colonDis += (9 * (RADIUS + 1));
        }
    }
}
3人推荐
随时随地看视频
慕课网APP