From bc607852ef964f877504bd1b74e048e8ed7cadef Mon Sep 17 00:00:00 2001 From: Jonas Enlund Date: Sun, 9 Feb 2014 13:12:54 +0200 Subject: [PATCH] Added some circles --- examples/geometry/src/components.cljs | 12 +++++++++++- examples/geometry/src/core.cljs | 4 +++- examples/geometry/src/geometry.cljs | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/geometry/src/components.cljs b/examples/geometry/src/components.cljs index c54e0bd..f962811 100644 --- a/examples/geometry/src/components.cljs +++ b/examples/geometry/src/components.cljs @@ -1,6 +1,6 @@ (ns components (:require [reagent.core :as r] - [geometry :refer [x y] :as g])) + [geometry :refer [x y dist] :as g])) (def point-defaults {:stroke "black" @@ -46,3 +46,13 @@ [segment a b] [segment b c] [segment c a]]) + + +(defn circle [c r] + [:circle + {:cx (x c) + :cy (y c) + :r (dist c r) + :stroke-width 2 + :stroke "black" + :fill "rgba(0,0,0,0)"}]) diff --git a/examples/geometry/src/core.cljs b/examples/geometry/src/core.cljs index 3558e7a..9d173e4 100644 --- a/examples/geometry/src/core.cljs +++ b/examples/geometry/src/core.cljs @@ -28,6 +28,9 @@ (defn root [] [:g [c/triangle @p1 @p2 @p3] + [c/circle @p1 @p2] + [c/circle @p2 @p3] + [c/circle @p3 @p1] [c/draggable-point p1 mouse-info] [c/draggable-point p2 mouse-info] [c/draggable-point p3 mouse-info]]) @@ -48,4 +51,3 @@ "The corners are draggable"] [root]] (by-id "app"))) - diff --git a/examples/geometry/src/geometry.cljs b/examples/geometry/src/geometry.cljs index 2956ec5..b0e7f9d 100644 --- a/examples/geometry/src/geometry.cljs +++ b/examples/geometry/src/geometry.cljs @@ -24,5 +24,7 @@ (rand-point -1 2 -1 2)) - +(defn dist [p1 p2] + (js/Math.sqrt (+ (js/Math.pow (- (x p2) (x p1)) 2) + (js/Math.pow (- (y p2) (y p1)) 2))))