2013-08-06 75 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