Skip to content

Commit

Permalink
move stroke-path into canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Feb 15, 2024
1 parent e98d7bb commit 60a587f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/shimmers/common/ui/canvas.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@
([ctx] (.stroke ctx) ctx)
([ctx path] (.stroke ctx path) ctx))

(defn stroke-path [ctx points]
(.beginPath ctx)
(move-to ctx (first points))
(doseq [p (rest points)]
(line-to ctx p))
(stroke ctx)
ctx)

(defn fill
([ctx] (.fill ctx) ctx)
([ctx fill-rule] (.fill ctx fill-rule) ctx)
Expand Down
13 changes: 3 additions & 10 deletions src/shimmers/sketches/carrier_wave.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@
(tm/* radius)
(tm/+ center))))

(defn draw-path [ctx points]
(.beginPath ctx)
(canvas/move-to ctx (first points))
(doseq [p (rest points)]
(canvas/line-to ctx p))
(canvas/stroke ctx)
ctx)

(defn draw
[ui-state _fs ctx [width height] ms]
(let [t (* 0.001 ms)
center (gv/vec2 (* 0.5 width) (* 0.5 height))
{:keys [params k]} @ui-state
[a b c d] params]
[a b c d] params
points (generate-points [a b c d (* 1 k)] center (* 0.133 height) (* 0.5 t))]
(canvas/line-width ctx 1.0)
(draw-path ctx (generate-points [a b c d (* 1 k)] center (* 0.133 height) (* 0.5 t)))
(canvas/stroke-path ctx points)
ctx))

;; TODO: use fraction controls
Expand Down

0 comments on commit 60a587f

Please sign in to comment.