Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:24
Show Gist options
  • Select an option

  • Save dacr/f2d934a6cd43c3bef9c9aae80b90f53f to your computer and use it in GitHub Desktop.

Select an option

Save dacr/f2d934a6cd43c3bef9c9aae80b90f53f to your computer and use it in GitHub Desktop.
plotting with smile / published by https://github.com/dacr/code-examples-manager #2b837969-72e0-49a7-a257-d09c6d5c091b/7d75553bd7c3049a1101776675f548d2e5e7a2ff
// summary : plotting with smile
// keywords : smile, plotting
// publish : gist
// authors : smile documentation
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 2b837969-72e0-49a7-a257-d09c6d5c091b
// created-on : 2020-10-11T17:33:19Z
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
//> using dep "com.github.haifengl::smile-scala:3.1.1"
// ---------------------
import scala.math.*
import java.awt.Color.RED
// those smile imports (and many more) are available by default in REPL mode
import smile.plot.*
import smile.plot.swing.*
implicit val renderer:Canvas=>Unit = JWindow.apply
val heart = -314 to 314 map { i =>
val t = i / 100.0
val x = 16 * pow(sin(t), 3)
val y = 13 * cos(t) - 5 * cos(2*t) - 2 * cos(3*t) - cos(4*t)
Array(x, y)
}
show(line(heart.toArray, color = RED))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment