Hi,
I’m playing around with the GraphicsPath class and trying to translate sample source code from the Mozilla site. I have the following code (https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes) and translated it to Xojo. Unfortunately the results differ (see picture).
Java
[code]for (var i = 0; i < 4; i++) {
for (var j = 0; j < 3; j++) {
ctx.beginPath();
var x = 25 + j * 50; // x coordinate
var y = 25 + i * 50; // y coordinate
var radius = 20; // Arc radius
var startAngle = 0; // Starting point on circle
var endAngle = Math.PI + (Math.PI * j) / 2; // End point on circle
var anticlockwise = i % 2 !== 0; // clockwise or anticlockwise
ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise);
if (i > 1) {
ctx.fill();
} else {
ctx.stroke();
}
}
}[/code]
Xojo
[code]Const kPi = 3.1415926535
Var path As GraphicsPath
Var x, y, radius, startAngle, endAngle As Double
Var anticlockwise As Boolean
radius = 20 // Arc radius
startAngle = 0 // Starting point on circle
g.DrawingColor = Color.TextColor
For i As Integer = 0 To 3
For j As Integer = 0 To 2
path = New GraphicsPath
x = 25 + j * 50 // x coordinate
y = 25 + i * 50 // y coordinate
endAngle = kPi + (kPi * j) / 2 // End point on circle
anticlockwise = i Mod 2 <> 0 // clockwise or anticlockwise
path.AddArc(x, y, radius, startAngle, endAngle, anticlockwise)
If (i > 1) Then
g.FillPath(path)
Else
g.DrawPath(path)
End If
Next
Next[/code]