Skip to content

Commit

Permalink
centre cubes
Browse files Browse the repository at this point in the history
  • Loading branch information
pishty1 committed Dec 9, 2023
1 parent e031364 commit 14cf248
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
55 changes: 29 additions & 26 deletions src/sketches/menu.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
(:require [quil.core :as q]))

(defn draw-menu-item [x y h w c1 c2 c3]
;; (q/stroke-weight 20)
(q/fill c1 c2 c3)
(q/rect x y w h))

; get total height of page - totoal height of menu items divide by 2 = starting y
(defn generate-origin [number-of-menu-items height width page-height page-width]
(let [height 100
width 100
offset-x (* 0 0)
offset-y (* 0 0)
diff-y (- page-height (* number-of-menu-items height))
origin-y (/ diff-y 2)
diff-x (- page-width (* 1 width))
origin-x (/ diff-x 2)
]
{:ox origin-x
:oy origin-y}))

(defn gen-menu-items []
(let [myrange (range 7)
height 100

(defn gen-menu-items [page-height page-width]
(let [height 100
width 100
ox 100
oy 100]
number-of-menu-items 4
origin (generate-origin number-of-menu-items height width page-height page-width)
padding-top 0]
(loop [index 0
mrange myrange
mrange (range number-of-menu-items)
menu-list []]
(if (seq mrange)
(recur (inc index)
Expand All @@ -24,16 +39,16 @@
:color3 (rand-int (rand-int 255))
:height height
:width width
:px ox; lets start here and stack them down
:py (+ oy (* index height))}))
:px (:ox origin); lets start here and stack them down
:py (+ padding-top (+ (:oy origin) (* index height)))}))
menu-list))))

(def menu-item-list
(defn menu-item-list [page-height page-width]
{:padding 10
:menu-list (gen-menu-items)})
:menu-list (gen-menu-items page-height page-width)})

(defn draw-menu [is-mobile?]
(doseq [{:keys [px py height width color1 color2 color3]} (:menu-list menu-item-list)]
(defn draw-menu [is-mobile? menu-list]
(doseq [{:keys [px py height width color1 color2 color3]} (:menu-list menu-list)]
(draw-menu-item
px
py
Expand All @@ -45,17 +60,5 @@


(comment
;; (def mycoll [1 2 3 4 5])
(def mycoll
{:toto "hello"
:mycoll [1 2 3 4 5]})
(defn myloop []
(loop [index 0
coll (:mycoll mycoll)
;; {coll :mycoll} mycoll
]
(when (seq coll)
(println (first coll) " with index " index)
(recur (inc index) (rest coll)))))

(myloop))

)
15 changes: 9 additions & 6 deletions src/sketches/tut1.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@
bottom (- canvas-y-center cross-size)
is-mobile (is-mobile-browser?)]
(println "is mobile :" is-mobile)
{:is-mobile is-mobile :circ-size circ-size

{:menu (menu/menu-item-list h w)
:is-mobile is-mobile :circ-size circ-size
:canvas-x-center canvas-x-center :canvas-y-center canvas-y-center
:left left :right right :top top :bottom bottom}))

(defn draw-state [{:keys [is-mobile left right top bottom
canvas-x-center canvas-y-center circ-size]} ]
(defn draw-state [{:keys [menu is-mobile left right top bottom
canvas-x-center canvas-y-center circ-size]}]


(q/background 230 230 230)
(q/stroke 130, 0 0)
(q/stroke-weight 4)

(when (q/mouse-pressed?)
(menu/draw-menu is-mobile))
(menu/draw-menu is-mobile menu))
(q/stroke 130, 0 0)
(q/stroke-weight 4)

(q/line left bottom right top)
(q/line right bottom left top)
Expand Down

0 comments on commit 14cf248

Please sign in to comment.