Skip to content

Commit

Permalink
FIX - Compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilreddy committed Nov 20, 2024
1 parent a4faf74 commit aedec83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions r_place_backend/src/r_place_backend/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[compojure.core :refer [defroutes GET POST DELETE ANY context]]))

(def sample-data {:column 4
:row 4
:color "green"})
:row 4
:color "green"})

(def colors ["#8967B3" "#4F75FF" "#8FD14F"
"#FF6500" "#73EC8B" "#243642"])
Expand Down
53 changes: 28 additions & 25 deletions r_place_ui/src/place/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@

(def canvas (dom/getElement "paintCanvas"))
(def ctx (.getContext canvas "2d"))
(def socket* (atom nil))

(def tools
{:brush (dom/getElement "brush")
:eraser (dom/getElement "eraser")
:color-picker (dom/getElement "colorPicker")
:demo (dom/getElement "demo")})

(defonce app-state (atom {}))
;; Set canvas size

(defn set-zoom [new-scale]
(swap! app-state assoc :scale new-scale)
(style/setStyle canvas "transform" (str "scale(" new-scale ")"))
(style/setStyle canvas "transformOrigin" "top left")
(draw-grid))
;; Grid settings
(def grid-size 20)
(def grid-color "#808080")

(defonce app-state (atom {:current-tool :brush
:current-color "#000000"
:scale 0.1}))
;; Set canvas size
(defn draw-grid []
(set! (.-strokeStyle ctx) grid-color)
(set! (.-lineWidth ctx) 0.5)
Expand All @@ -34,6 +35,14 @@
(.lineTo ctx (.-width canvas) y))
(.stroke ctx))

(defn set-zoom [new-scale]
(swap! app-state assoc :scale new-scale)
(style/setStyle canvas "transform" (str "scale(" new-scale ")"))
(style/setStyle canvas "transformOrigin" "top left")
(draw-grid))



(defn draw-grid-pixel [grid-idx-x grid-idx-y color]
(let [grid-x (* grid-idx-x grid-size)
grid-y (* grid-idx-y grid-size)]
Expand All @@ -54,9 +63,9 @@

(defn send-pixel!
[x y color]
(.send socket* (pr-str {:column x
:row y
:color color})))
(.send @socket* (pr-str {:column x
:row y
:color color})))

(defn handle-canvas-click [e]
(let [rect (.getBoundingClientRect canvas)
Expand All @@ -68,7 +77,7 @@
(:current-color @app-state))]
(draw-pixel x y color)
(send-pixel! (Math/floor (/ x grid-size))
Math/floor
(Math/floor (/ y grid-size))
color)))

(events/listen canvas "click" handle-canvas-click)
Expand All @@ -82,13 +91,6 @@
(set! (.-width canvas) 500)
(set! (.-height canvas) 500)

;; Grid settings
(def grid-size 20)
(def grid-color "#808080")

(def app-state (atom {:current-tool :brush
:current-color "#000000"
:scale 0.1}))

;; Set initial zoom
(set-zoom 1)
Expand Down Expand Up @@ -119,12 +121,13 @@
on-message-fn)
socket))

(do (def socket* (setup-ws "ws://localhost:8080/ws"
(fn []
(js/console.log "Socket connected"))
(fn [e]
(js/console.log e.data)
(websocket-message-handler e.data)))))
(reset! socket*
(setup-ws "ws://localhost:8080/ws"
(fn []
(js/console.log "Socket connected"))
(fn [e]
(js/console.log e.data)
(websocket-message-handler e.data))))


(def sample-data {:column 0
Expand Down

0 comments on commit aedec83

Please sign in to comment.