Skip to content

Instantly share code, notes, and snippets.

@jezinka

jezinka/Fern.kt Secret

Last active Jul 24, 2017
Embed
What would you like to do?
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