-
-
Save kballenegger/6e554107a715d1c09c9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns js-utils) | |
; math helpers | |
(defn random [] | |
(.random js/Math)) | |
(defn floor [f] | |
(.floor js/Math f)) | |
(defn log [m] | |
(.log js/console m)) | |
(defn clj->js | |
"Recursively transforms ClojureScript maps into Javascript objects, | |
other ClojureScript colls into JavaScript arrays, and ClojureScript | |
keywords into JavaScript strings." | |
[x] | |
(cond | |
(string? x) x | |
(keyword? x) (name x) | |
(map? x) (.strobj (reduce (fn [m [k v]] | |
(assoc m (clj->js k) (clj->js v))) {} x)) | |
(coll? x) (apply array (map clj->js x)) | |
:else x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns continuous | |
(:use [js-utils :only (clj->js random floor log)])) | |
(def random-walk-value (atom 70)) | |
(def tick (atom 0)) | |
(defn next-tick [] | |
{:tick (swap! tick inc) | |
:value (swap! random-walk-value | |
(fn [v] (floor (max 10 (min 90 (+ v (* 10 (- (random) .5))))))))}) | |
(def data (clj->js (repeat 33 (next-tick)))) | |
(def w 20) | |
(def h 200) | |
(def x (-> (.-scale js/d3) | |
(.linear) | |
(.domain (array 0 1)) | |
(.range (array 0 w)))) | |
(def y (-> (.-scale js/d3) | |
(.domain (array 0 100)) | |
(.range (array 0 h)))) | |
(defn redraw-graph [] | |
nil) | |
(defn each-tick [] | |
(.shift data) | |
;(.push data (next-tick)) | |
(redraw-graph) | |
(log data) | |
nil) | |
(defn ^:export main [] | |
(js/setInterval #(each-tick) 1500)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject chartboost-cljs "0.0.1" | |
:description "clojurescript files for chartboost" | |
:dependencies [[org.clojure/clojure "1.3.0"]] | |
:plugins [[lein-cljsbuild "0.1.9"]] | |
:cljsbuild { | |
:builds [{ | |
:source-path "cljs" | |
:compiler { | |
:output-to "../public/js/cljs.js" | |
:optimizations :advanced | |
:pretty-print true}}]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment