forked from ldnclj/Coloured-Balls
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Rees
committed
Apr 17, 2011
1 parent
4bb2017
commit d0fd077
Showing
4 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
(defproject coloured-balls "0.0.1-SNAPSHOT" | ||
:description "A visual game challenge for the Clojure dojo" | ||
:main coloured-balls.core | ||
:dependencies [[org.clojure/clojure "1.2.0"] | ||
:dependencies [[org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"] | ||
[midje "1.1-alpha-3"] | ||
[org.clojars.automata/rosado.processing "1.1.0"]]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
(ns coloured-balls.motion) | ||
(ns coloured-balls.motion | ||
(:use [clojure.contrib.generic.math-functions :only (floor, cos, sin)])) | ||
|
||
(defn degrees-to-radians [degrees] | ||
(* (/ Math/PI 180) degrees)) | ||
|
||
(defn move [item] | ||
{:x 3}) | ||
(let [heading (degrees-to-radians (:heading item)) | ||
velocity (:velocity item) | ||
old-x (:x item) | ||
old-y (:y item) | ||
new-x (floor (* velocity (cos heading))) | ||
new-y (floor (* velocity (sin heading)))] | ||
(conj {:x (+ old-x new-x) :y (+ old-y new-y)} (dissoc item :x :y)))) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns coloured-balls.core-test | ||
(:use coloured-balls.motion | ||
midje.sweet)) | ||
|
||
(fact (direction {:heading 45}) => [1 1]) | ||
|
||
(fact (direction {:heading 225}) => [-1 -1]) |