下面的代码没有画出一个圆,并且再画了一下(当我从HTML页面按run时),它将先前绘制的函数绘制为红色,并且仍然没有按预期显示该圆。
我提到了this question,但仍然无法解决我的问题。
var canvas = document.getElementById("mycanvas");
var c = canvas.getContext("2d");
var c1 = canvas.getContext("2d");
canvas.height = $canvasDiv.innerHeight();
canvas.width = $canvasDiv.innerWidth();
function crtanjeGrede(l)
{
var oslonac1 = parseInt(l) + 30;
c.beginPath();
c.fillRect(30, 30, l, 5);
c.beginPath();
c.moveTo(oslonac1, 35);
c.lineTo(oslonac1 + 25, 45);
c.lineTo(oslonac1 - 25, 45);
c.lineTo(oslonac1, 35);
c.moveTo(oslonac1 + 25, 50);
c.lineTo(oslonac1 - 25, 50);
c.stroke();
c.beginPath();
c.moveTo(30, 35);
c.stroke();
c.lineTo(55, 45);
c.stroke();
c.lineTo(5, 45);
c.stroke();
c.lineTo(30, 35);
c.stroke();
c.moveTo(30, 55);
c.lineTo(30, 400);
c.moveTo(oslonac1, 55);
c.lineTo(oslonac1, 400);
c.closePath();
c.stroke();
}
function crtanjeGerbera1(q){
var gerber1 = parseInt(q) + 30;
c1.beginPath();
c1.arc(q, 32, 44, 0, 2 * Math.PI); // length is inserted by user (variable q) and
// the starting point Y has to be directly on rectangle (has to be lined over the
// previous maded rectangle, that's why I wrote 32)
c1.fillStyle = 'red';
c1.fill();
c1.lineWidth = 1;
c1.strokeStyle = 'red';
c1.stroke();
c1.closePath();
}
crtanjeGrede(duzina);
crtanjeGerbera1();