[orx-shapes] use phase parameter in regularStar (#168)

This commit is contained in:
Steven van den Broek
2021-02-04 08:45:24 +01:00
committed by GitHub
parent cc766b6db1
commit d6dbf2a6d7

View File

@@ -9,10 +9,11 @@ import kotlin.math.sin
fun regularStar(points: Int, innerRadius: Double, outerRadius: Double, center: Vector2 = Vector2.ZERO, phase: Double = 0.0): ShapeContour { fun regularStar(points: Int, innerRadius: Double, outerRadius: Double, center: Vector2 = Vector2.ZERO, phase: Double = 0.0): ShapeContour {
return contour { return contour {
val theta = Math.toRadians(phase)
val phi = PI * 2.0 / (points * 2) val phi = PI * 2.0 / (points * 2)
for (i in 0 until points * 2 step 2) { for (i in 0 until points * 2 step 2) {
val outerPoint = Vector2(cos(i * phi), sin(i * phi)) * outerRadius + center val outerPoint = Vector2(cos(i * phi + theta), sin(i * phi + theta)) * outerRadius + center
val innerPoint = Vector2(cos((i + 1) * phi), sin((i + 1) * phi)) * innerRadius + center val innerPoint = Vector2(cos((i + 1) * phi + theta), sin((i + 1) * phi + theta)) * innerRadius + center
moveOrLineTo(outerPoint) moveOrLineTo(outerPoint)
lineTo(innerPoint) lineTo(innerPoint)
} }