Last active
October 18, 2018 04:27
-
-
Save nakamuuu/cef3d64b75e06ed3d0c1c643a929c848 to your computer and use it in GitHub Desktop.
草の渦
This file contains hidden or 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
import kotlin.math.* | |
const val size = 15 | |
const val interval = 3 | |
fun main(args: Array<String>) { | |
val center = Point(size / 2, size / 2) | |
repeat(size) { y -> | |
repeat(size) { x -> | |
val distance = Point(x, y).distance(center) | |
val angle = Point(x, y).angle(center) | |
val gap = interval * angle | |
if ((distance - gap).roundToInt() % interval == 0) { | |
print(":wwww:") | |
} else { | |
print(arrayListOf(":celery:", ":mizuna:", ":komatsuna:", ":hourensou:").shuffled().first()) | |
} | |
} | |
print("\n") | |
} | |
} | |
data class Point(val x: Int, val y: Int) { | |
// 💩 : 0度->360度を0->1で無理やり表す | |
fun angle(from: Point) = (atan2((x - from.x).toDouble(), (y - from.y).toDouble()) / PI + 1) / 2 | |
fun distance(from: Point) = sqrt((x - from.x).toDouble().pow(2) + (y - from.y).toDouble().pow(2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment