Skip to content

Commit

Permalink
[#15] line, save-current-[fill|stroke], current-[fill|stroke]
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Nov 24, 2018
1 parent ff4ad2b commit 24d81f8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
40 changes: 33 additions & 7 deletions src/doodler/core.clje
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@
([r g b alpha]
#erl[r g b alpha]))

(defn- save-current-stroke
"Save current stroke color vector in the internal state. It can be accessed using (current-stroke) function."
[color]
(set! *internal-state* (assoc *internal-state* :current-stroke color)))

(defn current-stroke
[]
(:current-stroke *internal-state*))

(defn stroke
[& args]
(let [pen (wxDC/getPen *canvas*)]
(wxPen/setColour pen (apply color args))
(wxDC/setPen *canvas* pen)))
(let [pen (wxDC/getPen *canvas*)
color (apply color args)]
(wxPen/setColour pen color)
(wxDC/setPen *canvas* pen)
(save-current-stroke color)))

(defn stroke-weight
[weight]
Expand All @@ -56,11 +67,22 @@
(wxDC/setBackground *canvas* brush)
(clear)))

(defn- save-current-fill
"Save current fill color vector in the internal state. It can be accessed using (current-fill) function."
[color]
(set! *internal-state* (assoc *internal-state* :current-fill color)))

(defn fill
[& args]
(let [brush (wxDC/getBrush *canvas*)]
(wxBrush/setColour brush (apply color args))
(wxDC/setBrush *canvas* brush)))
(let [brush (wxDC/getBrush *canvas*)
color (apply color args)]
(wxBrush/setColour brush color)
(wxDC/setBrush *canvas* brush)
(save-current-fill color)))

(defn current-fill
[]
(:current-fill *internal-state*))

(defn arc
[x y w h start end]
Expand All @@ -75,9 +97,13 @@
#erl[(- x (erlang/div w 2)) (- y (erlang/div h 2))]
#erl[w h]))

(defn line
([p1 p2] (apply line (concat p1 p2)))
([x1 y1 x2 y2] (wxDC/drawLine *canvas* #erl[x1 y1] #erl[x2 y2])))

(defn point
[x y]
(wxDC/drawPoint *canvas* (tuple x y)))
(wxDC/drawPoint *canvas* #erl[x y]))

(defn random
([max]
Expand Down
8 changes: 8 additions & 0 deletions src/doodler/examples/shapes.clje
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
(d/frame-rate 10))

(defn draw []
(d/background 200)

(d/stroke (rand-int 255))
(d/stroke-weight (rand-int 3))
(d/fill (rand-int 255))

(d/ellipse 20 20 20 20)
(d/arc 10 55 50 50 0.0 45.0)
(d/rect 10 60 20 20)
(d/rect 10 85 20 20 5)
(d/line 10 130 80 140)

(d/text "Hello world!" 10 110)
(d/text (str "Fill: " (d/current-fill)) 100 10)
(d/text (str "Stroke: " (d/current-stroke)) 100 30)

)

(d/defsketch sketch
Expand Down

0 comments on commit 24d81f8

Please sign in to comment.