Skip to content

Commit

Permalink
add a grid helper for coordinate system and enable layer to process n…
Browse files Browse the repository at this point in the history
…ested lists of shapes
  • Loading branch information
carlos committed Nov 9, 2023
1 parent 8ca06d5 commit 250e62f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion editor/src/maria/user.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
timeout
fetch
geo-location]]
[shapes.core :as shapes :refer [listen
[shapes.core :as shapes :refer [listen grid
circle ellipse square rectangle triangle polygon polyline text image
position opacity rotate scale
colorize stroke stroke-width no-stroke fill no-fill
Expand Down
21 changes: 20 additions & 1 deletion shapes/src/shapes/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
(defn layer
"Returns a new shape with these `shapes` layered over each other."
[& shapes]
(let [kids (remove nil? shapes)
(let [kids (->> shapes flatten (remove nil?))
bbox (max-bbox (mapv bbox kids))]
(map->Shape {:kind :svg
:x 0
Expand Down Expand Up @@ -635,6 +635,25 @@
#(assoc-in % cell-path v)
#(identity v))))))

(defn grid
"Draws a grid to help with coordinates, you can specify height width and grid spacing"
[x y space]
(layer
(polyline [0 0 x 0])
(polyline [0 0 0 y])
(for [x (range 0 x space)]
[(polyline [x 0 x 5])
(position x 16 (text (str x)))])

(for [y (range 0 y space)]
[(polyline [0 y 5 y])
(position 5 (+ 5 y) (text (str y)))])

(for
[x (range 0 x space)
y (range 0 y space)]
(position x y (circle 1)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pre-cooked SVG shapes

Expand Down

0 comments on commit 250e62f

Please sign in to comment.