【发布时间】:2017-01-04 09:55:03
【问题描述】:
请看我关于这个问题的 jsfiddle
https://jsfiddle.net/gL4m2z6v/
这是一个画布中的分数计算器,应该显示两个分数之间的最大公因数。您将需要在小提琴中展开视口并重新运行才能正确查看。
相关代码摘录 - 查看完整的小提琴
labelGCF: function(a, b){
var b = a % b;
if (b != 0) {
console.log(a, window.innerWidth*0.8, winH50, textObj.fontSize);
ctx.fillText(a, window.innerWidth*0.8, winH50, textObj.fontSize);
} else {
tableObj.labelGCF(b, a % b);
}
}
// Exec
(function loop(){
window.requestAnimationFrame(loop);
// Draw Canvas Background
c.width = canWidth;
c.height = canHeight;
ctx.fillStyle = "#fff";
ctx.fillRect(0,0,canWidth,canHeight);
// Draw Arrows
arrowObj.draw(arrowObj[0]);
arrowObj.draw(arrowObj[1]);
arrowObj.draw(arrowObj[2]);
arrowObj.draw(arrowObj[3]);
coordsObj.arrows =
[arrowObj.getCoords(arrowObj[0]), arrowObj.getCoords(arrowObj[1]), arrowObj.getCoords(arrowObj[2]), arrowObj.getCoords(arrowObj[3])];
// console.log("coordsObj.arrows: "+coordsObj.arrows);
// Draw Table
tableObj.draw();
tableObj.labelXAxis();
tableObj.labelYAxis();
tableObj.labelTable();
tableObj.drawGrid();
tableObj.labelGCF(tableObj.xCount, tableObj.yCount);
})();
此代码似乎可以执行,并且变量已正确排除。我不知道为什么 fillText 不起作用。
【问题讨论】:
-
ctx.fillText之前console.log的输出是什么?
-
看看这个documentation 并纠正你的论点。 "0" 将绘制在位置 (1536, 489.5)
-
是的,但对我来说没有出现。您是否尝试过小提琴或 dl 代码并全屏使用。即使坐标在视口内,它也不会在屏幕上绘制 0。
标签: javascript canvas