install NPM modules
npm install nbb canvas
create draw.cljs file with the code below
(ns draw.core
(:require
["fs" :as fs]
["canvas" :refer (createCanvas)]))
(def width 400)
(def height 400)
(def canvas (createCanvas width height))
(def ctx (.getContext canvas "2d"))
(set! (.-fillStyle ctx) "#764abc")
(.fillRect ctx 0 0 width height)
(set! (.-fillStyle ctx) "#fff")
(set! (.-textAlign ctx) "center")
(set! (.-font ctx) "bold 50pt 'PT Sans'")
(.fillText ctx "Hello World" (/ width 2) (/ height 2))
(set! (.-strokeStyle ctx) "#fff")
(.beginPath ctx)
(.arc ctx 75 75 50 0 (* 2 js/Math.PI) true)
(.moveTo ctx 110, 75)
(.arc ctx 75 75 35 0 js/Math.PI false)
(.moveTo ctx 65 65)
(.arc ctx 60 65 5 0 (* 2 js/Math.PI) true)
(.moveTo ctx 95 65)
(.arc ctx 90 65 5 0 (* 2 js/Math.PI) true)
(.closePath ctx)
(.stroke ctx)
(.writeFileSync fs "./hello.png" (.toBuffer canvas "image/png"))
and run
npx nbb draw.cljs
You must log in or register to comment.