Skip to content
Browse files

Use relationship functions to display vals on the graph

  • Loading branch information...
1 parent 87cc18d commit 4a8f6f718a891bca69d0076908f213c4a632f19d @Bost committed
Showing with 74 additions and 51 deletions.
  1. +4 −0 public/style.css
  2. +3 −7 src/turing_instability/core.clj
  3. +67 −44 src/turing_instability/svg.clj
View
4 public/style.css
@@ -7,3 +7,7 @@ p.ex {color:rgb(0,0,255);}
stroke-width:2
}
+.small
+{
+ font-size:small;
+}
View
10 src/turing_instability/core.clj
@@ -112,10 +112,6 @@
; (webserver)
; (println (str "Webserver started on http://localhost:" port webroute)))
-(defn first-n-vals [n f]
- "TODO first-n-vals evaluates to lazy sequence - is it ok?"
- (for [i (range 1 n)]
- ;(dorun
- (int (* 100 (f i)))
- ; )
- ))
+(defn first-n-vals [f n]
+ "Return a lazy seq of first n values for a given function f"
+ (map (fn [v] (f v)) (range 1 n)))
View
111 src/turing_instability/svg.clj
@@ -1,26 +1,33 @@
(ns turing-instability.svg
(:use
- [hiccup.core]
- [hiccup.page :only (include-css
- ;include-js
- )]
- [ring.adapter.jetty]
- [compojure.core]
- [turing-instability.init]
- )
+ [clojure.math.numeric-tower]
+ [hiccup.core]
+ [hiccup.page :only (include-css
+ ;include-js
+ )]
+ [ring.adapter.jetty]
+ [compojure.core]
+ [turing-instability.init]
+ [turing-instability.relfuncs]
+ )
(:require
[compojure.route :as route]
- )
+ )
)
(comment
-(load "../turing_instability/svg")
-)
+ (load "../turing_instability/svg")
+ )
+
+(defn scale [v]
+ ;(map (fn [i] (floor (* 100 i))) v)
+ (floor (* 100 v))
+ )
(defn circle [x y]
"usage: (tag-circle 20 30)"
"<circle cx="20" cy="30" r="4" fill=\"blue\"></circle>"
- [:circle {:cx (str x) :cy (str y) :r "2" :fill "red"}]
+ [:circle {:cx (str x) :cy (str y) :r "6" :fill "red"}]
)
(defn webpage []
@@ -34,47 +41,63 @@
(def scale-line-width 2)
- (html
- [:html
- [:head
- [:title "Turing instability"]
- (include-css stylesheet)
- ]
- [:body {:id "browser"}
- [:p {:class "ex" } "user.dir: " (System/getProperty "user.dir")]
- [:svg {:xmlns "http://www.w3.org/2000/svg" :version "1.1" }
-; (circle 20 40)
-; (circle 40 40)
+ (html
+ [:html
+ [:head
+ [:title "Turing instability"]
+ (include-css stylesheet)
+ ]
+ [:body {:id "browser"}
+ [:p {:class "ex" } "user.dir: " (System/getProperty "user.dir")]
+ (for [i (range 0 (+ 1 n))]
+ [:div {:class "small"} (str "val i: " (scale (j-n1 (+ 1 i))))]
+ )
+ [:svg {:xmlns "http://www.w3.org/2000/svg" :version "1.1"
+ :style "border: 1px; border-color: black; border-style: solid;"
+ }
+ ; (circle 20 40)
+ ; (circle 40 40)
- ; line with x-axis
- [:line {:x1 x-offset
- :y1 y-offset
- :x2 (+ x-offset (* x-width n))
- :y2 y-offset
- :style "stroke:rgb(0,0,0);stroke-width:2"} ]
+ ; line with x-axis
+ [:line {:x1 x-offset
+ :y1 y-offset
+ :x2 (+ x-offset (* x-width n))
+ :y2 y-offset
+ :style "stroke:rgb(0,0,0);stroke-width:2"} ]
- ; short lines to see the scale of the x-axis
- (for [i (range 0 (+ 1 n))]
- [:line {:x1 (+ x-offset (* i x-width))
- :y1 y-offset
- :x2 (+ x-offset (* i x-width))
- :y2 (+ y-offset y-length)
- :class "cls"
- }
- ]
- )
- ]]]; svg, body, html
- ))
+ ; short lines to see the scale of the x-axis
+ (for [i (range 0 (+ 1 n))]
+ [:line {:x1 (+ x-offset (* i x-width))
+ :y1 y-offset
+ :x2 (+ x-offset (* i x-width))
+ :y2 (+ y-offset y-length)
+ :class "cls"
+ }]
+ )
+ (for [i (range 0 (+ 1 n))]
+ (let [
+ yi (scale (j-n1 (+ 1 i)))
+ ]
+ (circle (+ x-offset (* i x-width))
+ (+ y-offset (abs yi))
+ ;(+ y-offset 0)
+ )
+ )
+ )
+ ]; svg
+ ]]; body, html
+ ))
(defroutes webroutes
(GET webroute [] (webpage))
(route/files "/"))
-(defn webserver []
+(defn websrv []
+ "Starts the web server"
(run-jetty (var webroutes) {:port port
:join? false ; :join? - Block the caller: defaults to true
}))
-;(webserver)
-;(println (str "Webserver started on http://localhost:" port webroute))
+;(websrv)
+;(println (str "Web server started on http://localhost:" port webroute))

0 comments on commit 4a8f6f7

Please sign in to comment.
Something went wrong with that request. Please try again.