Permalink
Browse files

Got a basic coloured ball program working

  • Loading branch information...
0 parents commit f265bbd2e56a3a2e17895b35615c5de6548735b5 Robert Rees committed Apr 4, 2011
Showing with 786 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +674 −0 LICENSE
  3. +5 −0 project.clj
  4. +3 −0 readme.textile
  5. +36 −0 src/coloured_balls/core.clj
  6. +57 −0 tasks.clj
  7. +3 −0 test/coloured_balls/core_test.clj
@@ -0,0 +1,8 @@
+.cake
+pom.xml
+*.jar
+*.war
+lib
+classes
+build
+/Coloured-Balls
Oops, something went wrong.
@@ -0,0 +1,5 @@
+(defproject coloured-balls "0.0.1-SNAPSHOT"
+ :description "A visual game challenge for the Clojure dojo"
+ :dependencies [[org.clojure/clojure "1.2.0"]
+ [midje "1.1-alpha-3"]
+ [org.clojars.automata/rosado.processing "1.1.0"]])
@@ -0,0 +1,3 @@
+h1. Coloured Balls
+
+This is an example exercise in visual programming for the London Clojure dojo.
@@ -0,0 +1,36 @@
+(ns coloured-balls.core
+ (:use [rosado.processing]
+ [rosado.processing.applet]))
+
+;; here's a function which will be called by Processing's (PApplet)
+;; draw method every frame. Place your code here. If you eval it
+;; interactively, you can redefine it while the applet is running and
+;; see effects immediately
+
+(defn draw-ball [ball]
+ (fill (:red ball) (:green ball) (:blue ball))
+ (ellipse (:x ball) (:y ball) (:radius ball) (:radius ball)))
+
+(defn make-ball []
+ {:x (rand-int 400) :y (rand-int 400) :red (rand-int 256) :blue (rand-int 256) :green (rand-int 256) :radius (+ 1 (rand-int 70))})
+
+(defn draw
+ "Example usage of with-translation and with-rotation."
+ []
+ (draw-ball (make-ball))
+ )
+
+(defn setup []
+ "Runs once."
+ (smooth)
+ (no-stroke)
+ (fill 226)
+ (framerate 10))
+
+;; Now we just need to define an applet:
+
+(defapplet balls :title "Coloured balls"
+ :setup setup :draw draw :size [400 400])
+
+ (run balls)
+
@@ -0,0 +1,57 @@
+(use 'cake 'cake.core
+ '[cake.project :only [reload!]]
+ '[bake.find-namespaces :only [find-namespaces-in-dir]])
+(import '[java.io File])
+
+(deftask midje
+ "Run midje and clojure.test tests"
+ (bake (:use [bake.core :only [with-context]])
+ (:require [clojure test string])
+ [namespaces (concat (find-namespaces-in-dir (java.io.File. "test"))
+ (find-namespaces-in-dir (java.io.File. "src")))]
+ (with-context :test
+ ;; This turns off "Testing ...." lines, which I hate, especially
+ ;; when there's no failure output.
+ (defmethod clojure.test/report :begin-test-ns [m])
+
+ (alter-var-root (var clojure.test/*report-counters*)
+ (fn [_] (ref clojure.test/*initial-report-counters*)))
+ (doseq [n namespaces] (require n :reload))
+
+
+ (let [midje-passes (:pass @clojure.test/*report-counters*)
+ midje-fails (:fail @clojure.test/*report-counters*)
+ midje-failure-message
+ (condp = midje-fails
+ 0 (format "All claimed facts (%d) have been confirmed." midje-passes)
+ 1 (format "FAILURE: %d fact was not confirmed." midje-fails)
+ (format "FAILURE: %d facts were not confirmed." midje-fails))
+ potential-consolation
+ (condp = midje-passes
+ 0 ""
+ 1 "(But 1 was.)"
+ (format "(But %d were.)" midje-passes))
+ midje-consolation
+ (if (> midje-fails 0) potential-consolation "")
+
+ ; Stashed clojure.test output
+ clojure-test-output-catcher
+ (java.io.StringWriter.)
+ clojure-test-result
+ (binding [clojure.test/*test-out* clojure-test-output-catcher]
+ (apply clojure.test/run-tests namespaces))
+ clojure-test-output
+ (-> clojure-test-output-catcher .toString clojure.string/split-lines)]
+
+
+ (when (> (+ (:fail clojure-test-result) (:error clojure-test-result))
+ 0)
+ (println ">>> Output from clojure.test tests:")
+ (dorun (map println (drop-last 2 clojure-test-output))))
+
+ (when (> (:test clojure-test-result) 0)
+ (println ">>> clojure.test summary:")
+ (dorun (map println (take-last 2 clojure-test-output)))
+ (println ">>> Midje summary:"))
+
+ (println midje-failure-message midje-consolation)))))
@@ -0,0 +1,3 @@
+(ns coloured-balls.core-test
+ (:use coloured-balls.core)
+ (:use ))

0 comments on commit f265bbd

Please sign in to comment.