Last active
September 29, 2025 17:49
-
-
Save spamegg1/af22caa29faba54b4306935e4f77bcc3 to your computer and use it in GitHub Desktop.
Doodle Reactor, works in SBT on the Terminal, and as a worksheet in Metals, shows pop-up image; but not as `@main` method, neither in Metals nor on Terminal with `scala run ...`
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
| //> using dep org.creativescala::doodle:0.31.0 | |
| import cats.effect.unsafe.implicits.global | |
| import concurrent.duration.FiniteDuration | |
| import doodle.reactor.Reactor | |
| import doodle.image.Image | |
| import doodle.core.* | |
| import doodle.syntax.all.* | |
| import doodle.java2d.* | |
| import doodle.core.Color.{deepSkyBlue, red} | |
| val frame = Frame.default | |
| .withSize(600, 600) | |
| .withBackground(deepSkyBlue) | |
| .withTitle("Space Invaders") | |
| .withCenterAtOrigin | |
| val TickRate = FiniteDuration(50, "milliseconds") | |
| val image = Image.square(300).fillColor(red) | |
| // This works with SBT on the Terminal, but not Scala-cli. | |
| // Does not launch the pop-up window of Reactor when run, | |
| // either in Metals (click "run | debug") or Terminal (`scala run reactor.scala`) | |
| @main | |
| def hello: Unit = | |
| Reactor | |
| .init[Int](0) | |
| .withOnTick(identity) | |
| .withRender(_ => image) | |
| .withOnMouseClick((p, w) => w) | |
| .withOnMouseMove((p, w) => w) | |
| .withStop(_ => false) | |
| .withTickRate(TickRate) | |
| .run(frame) |
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
| //> using dep org.creativescala::doodle:0.31.0 | |
| import cats.effect.unsafe.implicits.global | |
| import concurrent.duration.FiniteDuration | |
| import doodle.reactor.Reactor | |
| import doodle.image.Image | |
| import doodle.core.* | |
| import doodle.syntax.all.* | |
| import doodle.java2d.* | |
| import doodle.core.Color.{deepSkyBlue, red} | |
| val frame = Frame.default | |
| .withSize(600, 600) | |
| .withBackground(deepSkyBlue) | |
| .withTitle("Space Invaders") | |
| .withCenterAtOrigin | |
| val TickRate = FiniteDuration(50, "milliseconds") | |
| val image = Image.square(300).fillColor(red) | |
| // This works just fine in Metals. | |
| Reactor | |
| .init[Int](0) | |
| .withOnTick(identity) | |
| .withRender(_ => image) | |
| .withOnMouseClick((p, w) => w) | |
| .withOnMouseMove((p, w) => w) | |
| .withStop(_ => false) | |
| .withTickRate(TickRate) | |
| .run(frame) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worksheet works:
SBT on the Terminal works:
@mainmethod and running does not work:Terminal:
Metals: