Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This program displays the output of fib-matrix mentioned in my blog
import java.awt.BorderLayout
import java.awt.Color
import java.awt.Graphics
import java.io.File
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.WindowConstants
/**
* Created by ice1000 on 2017/3/18.
*
* @author ice1000
*/
fun log(x: Int) = (Math.log(x.toDouble() + 1) * 3).toInt() + 4
fun main(args: Array<String>) {
val txt = File("out.txt")
.readText()
.split("\r\n")
.map { it.split(":").last() }
JFrame("Fib Matrix Viewer").run a@ {
setSize(700, 200)
layout = BorderLayout()
defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
add(object : JPanel() {
override fun paintComponent(g: Graphics?) {
super.paintComponent(g)
txt.forEachIndexed { x, y ->
try {
g?.run {
color = Color.BLACK
val _1_ = y.toInt() * 5
val _2_ = log(x) * 5
drawRect(x, this@a.height - _1_, 1, 1)
color = Color.BLUE
drawRect(x, this@a.height - _2_, 1, 1)
if (_1_ >= _2_) println("Fail at $x, y1 = $_1_, y2 = $_2_")
}
} catch (e: Exception) {
}
}
}
}, BorderLayout.CENTER)
isVisible = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.