From 250e62f158f6588c4e675bcb06ccd893e1101116 Mon Sep 17 00:00:00 2001 From: carlos Date: Thu, 9 Nov 2023 12:17:37 +0100 Subject: [PATCH] add a grid helper for coordinate system and enable layer to process nested lists of shapes --- editor/src/maria/user.cljs | 2 +- shapes/src/shapes/core.cljs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/editor/src/maria/user.cljs b/editor/src/maria/user.cljs index b4648b70..ecc210eb 100644 --- a/editor/src/maria/user.cljs +++ b/editor/src/maria/user.cljs @@ -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 diff --git a/shapes/src/shapes/core.cljs b/shapes/src/shapes/core.cljs index 3443cb5e..1abfe0b7 100644 --- a/shapes/src/shapes/core.cljs +++ b/shapes/src/shapes/core.cljs @@ -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 @@ -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