Skip to content

Instantly share code, notes, and snippets.

@stathissideris
Last active November 26, 2020 22:26
Show Gist options
  • Save stathissideris/5e536c800923a3a6fa1181e37672a8e3 to your computer and use it in GitHub Desktop.
Save stathissideris/5e536c800923a3a6fa1181e37672a8e3 to your computer and use it in GitHub Desktop.
Basic Clojure example for Skija
(ns skija.core
(:import [org.jetbrains.skija Canvas Surface Paint Color4f
EncodedImageFormat]
[java.nio.file Path Files OpenOption]))
(defn write-bytes [#^bytes b path]
(Files/write (Path/of "output.png" (make-array String 0)) b (make-array OpenOption 0)))
(defn show []
(let [surface (Surface/makeRasterN32Premul 100 100)
canvas (.getCanvas surface)
paint (doto (Paint.) (.setColor4f (Color4f. (float 1) (float 0) (float 0))))]
(.drawCircle canvas 50 50 30 paint)
(write-bytes
(-> surface
.makeImageSnapshot
(.encodeToData EncodedImageFormat/PNG)
.getBytes)
"output.png")))
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
org.jetbrains.skija/skija-macos {:mvn/version "0.6.10"}}
:mvn/repos {"space-maven" {:url "https://packages.jetbrains.team/maven/p/skija/maven"}}}
@stathissideris
Copy link
Author

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