Francois
Francois

Reputation: 2066

Clojure2d: drawing on the canvas silently fails if it has been resized

The following code successfully displays a blank canvas with a small red square:

(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)

However if I uncomment the call to resize, the red square is not drawn any more.

Upvotes: 1

Views: 68

Answers (1)

Eugene Pakhomov
Eugene Pakhomov

Reputation: 10727

resize creates a new canvas that has to be passed into its own with-canvas.

For example:

(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))

Upvotes: 3

Related Questions