以下代码成功显示带有红色小方块的空白画布:
(ns test-rect
(:require [clojure2d.core :as c2d])
(:require '[clojure2d.extra.utils :refer [show-image]]))
(c2d/with-canvas->
(c2d/canvas 100 100)
; (c2d/resize 100 100)
(c2d/set-color :red)
(c2d/rect 50 50 10 10)
show-image)
但是,如果我取消对 resize 的调用的注释,则不再绘制红色方块。
resize
创建一个新画布,必须将其传递到自己的 with-canvas
。
例如:
(let [canvas (c2d/canvas 100 100)]
(c2d/with-canvas-> (c2d/resize canvas 100 100)
(c2d/set-color :red)
(c2d/rect 50 50 10 10)
show-image))