問題:キャンバスに宇宙船を描いています。 x/yを上に乗せると、宇宙船の兵器の角度と範囲(現在の砲撃/向こうの宇宙船を考慮して)を示すキャンバスに円弧を描いています。現在、決定された角度は緑色で描かれており、兵器の範囲値が許す限り広がっています。角度/円弧を描く、キャンバスで放射光で満たされていますか?
しかし、私は、精度の低下を示すために決定された弧を塗りつぶすためにグラデーションを使用したいと考えています(つまり、勾配が緑色から始まり、オレンジ色に移動し、宇宙船から離れて赤色に変わります) 。
しかし、描画された円弧上のストックctx.fill()をグラデーションで置き換える方法がわかりません。
var ship {
loc: {x, y}, // lets say 100, 100
facing: facing // lets say facing 0, i.e. straight right
weapons: objects (range, startArc, endArc) // lets say 50, 300, 60 -> 120 degree angle, so -60 and +60 from facing (0/360)
}
for (var i = 0; i < weapon.arc.length; i++){
var p1 = getPointInDirection(weapon.range, weapon.arc[i][0] + angle, pos.x, pos.y);
var p2 = getPointInDirection(weapon.range, weapon.arc[i][1] + angle, pos.x, pos.y)
var dist = getDistance({x: pos.x, y: pos.y}, p1);
var rad1 = degreeToRadian(weapon.arc[i][0] + angle);
var rad2 = degreeToRadian(weapon.arc[i][1] + angle);
fxCtx.beginPath();
fxCtx.moveTo(pos.x, pos.y);
fxCtx.lineTo(p1.x, p1.y);
fxCtx.arc(pos.x, pos.y, dist, rad1, rad2, false);
fxCtx.closePath();
fxCtx.globalAlpha = 0.3;
fxCtx.fillStyle = "green";
fxCtx.fill();
fxCtx.globalAlpha = 1;
}
はそれはとてもグラジエント型のフローを使用の代わりに、それが固定され、もしそうなら、どのように色付けされている?記入/アーク/ globalalphaを交換することが可能ですかちょうど楽しみのためのアニメーション勾配でアークを埋めるために
おかげ
神聖なたわごと。それはすごくすごいです。あなたにもっと力を与える。ありがとう。 – user431806