Skip to content

Instantly share code, notes, and snippets.

@jezinka

jezinka/Fern.kt Secret

Last active July 24, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezinka/25df03832d4e0c9c9c677837e344e886 to your computer and use it in GitHub Desktop.
Save jezinka/25df03832d4e0c9c9c677837e344e886 to your computer and use it in GitHub Desktop.
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