2013-08-06 60 views
0

我想从JavaScript在HTML5画布使用的语句转化,如:如何将HTML5 Canvas弧()转换为JavaFX 2.x Canvas arc()?

ctx.arc(x, y, (rad+5)*factor, 0, Math.PI*2, true); 

在JavaFX的等效声明。

它会是什么样子?

作为参考,在HTML5画布弧()方法被定义为:

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的圆弧()语句看起来像并解释如何在这两者之间进行转换?或者我应该使用arcTo()或其他的东西?

谢谢。

回答

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个半径参数可以使它更一般,因为你可以绘制椭圆弧。

+0

酷感谢阿毛里,正是我所期待的! – Qu0ll