Skip to content

Instantly share code, notes, and snippets.

@hudsonb
Created September 8, 2018 22:23
Show Gist options
  • Save hudsonb/bee3f7f42c50ce15073734d296ec8140 to your computer and use it in GitHub Desktop.
Save hudsonb/bee3f7f42c50ce15073734d296ec8140 to your computer and use it in GitHub Desktop.
import javafx.animation.AnimationTimer
import javafx.application.Application
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.SnapshotParameters
import javafx.scene.image.ImageView
import javafx.scene.image.WritableImage
import javafx.scene.paint.Color
import javafx.scene.shape.ClosePath
import javafx.scene.shape.LineTo
import javafx.scene.shape.MoveTo
import javafx.scene.shape.Path
import javafx.stage.Stage
class Test : Application() {
override fun start(stage: Stage?) {
val width = 960.0
val height = 600.0
val group = Group()
val wi = WritableImage(width.toInt(), height.toInt())
group.children += ImageView(wi)
val path = Path()
group.children += path
val params = SnapshotParameters()
params.fill = Color.TRANSPARENT
val t = object : AnimationTimer() {
override fun handle(now: Long) {
group.snapshot(params, wi)
path.elements.clear()
path.stroke = Color.BLACK
path.elements += MoveTo(0.0, 0.0)
path.elements += LineTo(0.0, height)
path.elements += LineTo(width, height)
path.elements += LineTo(width, 0.0)
path.elements += LineTo(0.0, 0.0)
path.elements += ClosePath()
}
}
t.start()
val scene = Scene(group)
stage?.width = width
stage?.height = height
stage?.scene = scene
stage?.show()
}
}
fun main(args: Array<String>) {
Application.launch(Test::class.java, *args)
}
@hudsonb
Copy link
Author

hudsonb commented Sep 8, 2018

output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment