| 1 | package codewhale.pet |
| 2 | |
| 3 | import java.io.File |
| 4 | |
| 5 | fun main(args: Array<String>) { |
| 6 | require(args.isNotEmpty()) { "Usage: points.tsv [--reduced-motion]; tape on stdin" } |
| 7 | val points = File(args[0]).readLines().filter { it.isNotBlank() }.map { row -> |
| 8 | val c = row.split('\t').map { it.toDouble() }; require(c.size == 2); Pair(c[0], c[1]) |
| 9 | } |
| 10 | val sim = PetSim(points, expressionVersion = if (args.contains("--legacy")) 1 else 2); var frame = 0 |
| 11 | generateSequence(::readlnOrNull).forEach { row -> |
| 12 | val c = row.split('\t') |
| 13 | if (c.size >= 10 && c[0] != "dt") { |
| 14 | val state = PetState(c[1].toDouble(), c[2].toDouble(), c[3].toDouble(), c[4], c[5].toDouble(), |
| 15 | c[6].toDouble(), c[7].toDouble(), c[8].toDouble(), c[9].toDouble()) |
| 16 | sim.step(c[0].toDouble(), state, !args.contains("--reduced-motion")) |
| 17 | if (frame % 30 == 0) println("f${frame.toString().padStart(4, '0')} ${petDigest(sim)} ${state.channel}") |
| 18 | frame++ |
| 19 | } |
| 20 | } |
| 21 | println("final ${petDigest(sim)}") |
| 22 | } |
| 23 |