Javascript 未在画布中绘制的线

Javascript 未在画布中绘制的线,javascript,html,canvas,Javascript,Html,Canvas,小行星 常数FPS=30;//每秒帧数 施工船舶尺寸=30;//船舶高度(像素) /*@type{HTMLCanvasElement}*/ var canv=document.getElementById('gameCanvas'); var ctx=canv.getContext(“2d”); var船舶={ x:canv.width/2, y:canv高度/2, r:船舶尺寸/2, a:90/180*Math.pi//转换为弧度 } //设置游戏循环 设置间隔(更新,1000/FPS); 函


小行星
常数FPS=30;//每秒帧数
施工船舶尺寸=30;//船舶高度(像素)
/*@type{HTMLCanvasElement}*/
var canv=document.getElementById('gameCanvas');
var ctx=canv.getContext(“2d”);
var船舶={
x:canv.width/2,
y:canv高度/2,
r:船舶尺寸/2,
a:90/180*Math.pi//转换为弧度
}
//设置游戏循环
设置间隔(更新,1000/FPS);
函数更新(){
//抽离
ctx.fillStyle=“黑色”;
ctx.fillRect(0,0,canv.width,canv.height);
//画三角船
ctx.strokeStyle=“白色”;
ctx.lineWidth=船舶尺寸/20;
ctx.beginPath();
ctx.moveTo(//船头
ship.x+4/3*ship.r*数学cos(ship.a),
ship.y-4/3*ship.r*Math.sin(ship.a)
);
ctx.lineTo(//左后
ship.x-ship.r*(2/3*数学cos(ship.a)+数学sin(ship.a)),
ship.y+ship.r*(2/3*数学sin(ship.a)-数学cos(ship.a))
);
ctx.lineTo(//右后
ship.x-ship.r*(2/3*数学cos(ship.a)-数学sin(ship.a)),
ship.y+ship.r*(2/3*数学sin(ship.a)+数学cos(ship.a))
);
ctx.closePath();
ctx.stroke();
//轮换船
//开船
//中心点
ctx.fillStyle=“红色”;
ctx.fillRect(ship.x-1,ship.y-1,2,2);
}

它不是
Math.pi
,它是Math.pi

使用
Math.pi
会产生
NaN
,因此不会绘制线

把它改成

a:90/180*Math.PI//转换为弧度