我希望转换HTML5 Canvas中使用的JavaScript语句,例如:
ctx.arc(x, y, (rad+5)*factor, 0, Math.PI*2, true);
到JavaFX中的等效语句。
它会是什么样子?
作为参考,在HTML5 Canvas中,arc()方法定义为:
x The x-coordinate of the center of the circle
y The y-coordinate of the center of the circle
r The radius of the circle
sAngle The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle)
eAngle The ending angle, in radians
counterclockwise Optional. Specifies whether the drawing should be counterclockwise or clockwise. False=clockwise, true=counter-clockwise
但在JavaFX中,它被定义为:
public void arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)
Adds path elements to the current path to make an arc that uses Euclidean degrees. This Euclidean orientation sweeps from East to North, then West, then South, then back to East.
Parameters:
centerX - the center x position of the arc.
centerY - the center y position of the arc.
radiusX - the x radius of the arc.
radiusY - the y radius of the arc.
startAngle - the starting angle of the arc in the range 0-360.0
length - the length of the baseline of the arc.
有人可以告诉我JavaFX arc()语句的样子并解释如何在这两者之间进行转换吗?或者我应该完全使用arcTo()还是其他东西?
感谢。
答案 0 :(得分:1)
对此的等效陈述:
var rad=10;
var factor=5;
context.beginPath();
context.arc(x, y, (rad+5)*factor, 0, Math.PI*2, true);
javafx中的将是:
int rad=10;
int factor=5;
graphicsContext.strokeArc(x, y, (rad+5)*factor,(rad+5)*factor, 0, 360, ArcType.OPEN);
HTML5中的角度以弧度表示,Java中的角度以度为单位。 Java也有2个半径参数,因为它可以绘制椭圆弧。