 (defn resize!
   [state ctx]
   (let [w (- (.-innerWidth js/window) 40)
-        h (- (int (/ (* w 9) 16)) 40)]
-    (-> (by-id "canvas")
-        (attr! "width" w)
-        (attr! "height" h))
+        h (- (int (/ (* w 9) 16)) 40)
+        canvas (by-id "canvas")]
+    (aset canvas "width" w)
+    (aset canvas "height" h)
     (.scale ctx (/ w SCALE-W) (/ h SCALE-H))
     (draw-phase! state ctx)))
 

(defn by-id
  [id]
  (.getElementById js/document id))

(defn attr!
  [el attr val]
  (aset el attr val)
  el)

(defn listen!
  [el type fn]

  (if (or (hit? ball paddle-1 :right)
          (hit? ball paddle-2 :left))
    (let [{:keys [vx vy]} ball
          delta (rand-nth [0.3 0.5 0.7])
          vxf (if (< vx 0) dec inc)
          vyf (if (< vy 0) #(- % delta) #(+ % delta))]
      (assoc state :ball (assoc ball :vx (* -1 (vxf vx)) :vy (vyf vy))))
    state))

