0

我希望从 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() 或其他东西?

谢谢。

4

1 回答 1

2

这个的等效声明:

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 个半径参数,使其更通用,因为您可以绘制椭圆弧。

于 2013-08-06T23:09:39.270 回答