This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun generateFern(n: Int): FloatArray { | |
val random = Random() | |
points = kotlin.FloatArray(n) | |
for (i: Int in 2..n - 1 step 2) { | |
val r = random.nextFloat() | |
val p1 = matrix[F1]!![P]!! | |
val p2 = matrix[F2]!![P]!! | |
val p3 = matrix[F3]!![P]!! | |
var function: String | |
if (r <= p1) { | |
function = F1 | |
} else if (r <= p1 + p2) { | |
function = F2 | |
} else if (r <= p1 + p2 + p3) { | |
function = F3 | |
} else { | |
function = F4 | |
} | |
this.points[i] = newX(function, i) | |
this.points[i + 1] = newY(function, i) | |
} | |
return this.points.map { it * 100 }.toFloatArray() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment