Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active September 28, 2024 08:58
Show Gist options
  • Save dacr/a4dc2ceb1ae5836670038b8ee20ef890 to your computer and use it in GitHub Desktop.
Save dacr/a4dc2ceb1ae5836670038b8ee20ef890 to your computer and use it in GitHub Desktop.
Playing basics vector graphics using doodle library. / published by https://github.com/dacr/code-examples-manager #21cf7cd4-e493-4375-ade4-9aa82568daae/89b871b5696143fc5a5ddd673e5169b5ab49839c
// summary : Playing basics vector graphics using doodle library.
// keywords : scala, vector-graphics, doodle
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 21cf7cd4-e493-4375-ade4-9aa82568daae
// created-on : 2019-06-25T16:47:49Z
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.5.1"
//> using dep "org.creativescala::doodle:0.25.0"
// ---------------------
// doodle home page : https://github.com/creativescala/doodle/tree/master
// more info : https://www.youtube.com/watch?v=ENiyUi2IWJE
// Adapted example coming from https://www.creativescala.org/doodle/
import doodle.core.*
import doodle.syntax.*
import doodle.image.*
// Extension methods
import doodle.image.syntax.*
import doodle.syntax.all.*
import doodle.image.syntax.all.*
import cats.effect.unsafe.implicits.global
// Render to a window using Java2D (must be running in the JVM)
import doodle.java2d.*
val blackSquare = Image.rectangle(30, 30).fillColor(Color.black)
val redSquare = Image.rectangle(30, 30).fillColor(Color.red)
// A chessboard, broken into steps showing the recursive construction
val twoByTwo = (redSquare.beside(blackSquare)).above(blackSquare.beside(redSquare))
val fourByFour = (twoByTwo.beside(twoByTwo)).above(twoByTwo.beside(twoByTwo))
val chessboard = (fourByFour.beside(fourByFour)).above(fourByFour.beside(fourByFour))
val drawn = chessboard.rotate(45.degrees).draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment