-
Notifications
You must be signed in to change notification settings - Fork 2
Add launchpad renderer #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dpiatek
wants to merge
1
commit into
master
Choose a base branch
from
launchpad-renderer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,26 +1,17 @@ | ||
| (ns game-of-life.core | ||
| (:require [game-of-life.game :refer :all])) | ||
| (:require [game-of-life.game :refer :all] | ||
| [game-of-life.renderer :as r] | ||
| [clj-launchpad :as launchpad])) | ||
|
|
||
| (def initial-grid | ||
| (random-grid 80 60 0.4)) | ||
|
|
||
| (defn clear | ||
| [] | ||
| (print (str (char 27) "[2J"))) ; clear screen | ||
| (def lpad (launchpad/open)) | ||
|
|
||
| (defn render | ||
| [grid cell empty] | ||
| (print (str (char 27) "[;H")) ; move cursor to the top left corner of the screen | ||
| (println (to-string grid cell empty))) | ||
| (def initial-grid | ||
| (random-grid 9 8 0.35)) | ||
|
|
||
| (defn -main | ||
| "Run some thing!" | ||
| [] | ||
| (let [emoji "◻️"] | ||
| (clear) | ||
| (render initial-grid emoji " ") | ||
| (Thread/sleep 1000) | ||
| (loop [grid initial-grid] | ||
| (render grid emoji " ") | ||
| (Thread/sleep 100) | ||
| (recur (game-step grid))))) | ||
| (loop [grid initial-grid] | ||
| (r/draw-grid lpad grid) | ||
| (Thread/sleep 100) | ||
| (recur (game-step grid)))) | ||
This file contains hidden or 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,13 @@ | ||
| (ns game-of-life.renderer | ||
| (:require [clj-launchpad :as launchpad] | ||
| [game-of-life.game :as game])) | ||
|
|
||
| (defn draw-grid | ||
| "Draws a grid on the launchpad" | ||
| [device grid] | ||
| (game/grid-map | ||
| (fn [x y v] | ||
| (if (true? v) | ||
| (launchpad/draw-grid device x y :green) | ||
| (launchpad/draw-grid device x y :off))) | ||
| grid)) |
This file contains hidden or 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,38 @@ | ||
| (ns game-of-life.renderer-test | ||
| (:require [clojure.test :refer :all] | ||
| [bond.james :as bond :refer [with-stub]] | ||
| [game-of-life.renderer :as renderer] | ||
| [clj-launchpad :as launchpad])) | ||
|
|
||
| (def lpad :lpad) | ||
|
|
||
| (deftest renderer-test | ||
| (testing "lights up top left corner light" | ||
| (with-stub [[launchpad/draw-grid (fn [& args] args)]] | ||
| (let [initial-grid [[true false] | ||
| [false false]]] | ||
| (renderer/draw-grid lpad initial-grid) | ||
| (is (= '(:lpad 0 0 :green) (-> launchpad/draw-grid bond/calls (nth 0) :args))) | ||
| (is (= '(:lpad 1 0 :off) (-> launchpad/draw-grid bond/calls (nth 1) :args))) | ||
| (is (= '(:lpad 0 1 :off) (-> launchpad/draw-grid bond/calls (nth 2) :args))) | ||
| (is (= '(:lpad 1 1 :off) (-> launchpad/draw-grid bond/calls (nth 3) :args)))))) | ||
|
|
||
| (testing "lights up bottom right corner" | ||
| (with-stub [[launchpad/draw-grid (fn [& args] args)]] | ||
| (let [initial-grid [[false false] | ||
| [false true]]] | ||
| (renderer/draw-grid lpad initial-grid) | ||
| (is (= '(:lpad 0 0 :off) (-> launchpad/draw-grid bond/calls (nth 0) :args))) | ||
| (is (= '(:lpad 1 0 :off) (-> launchpad/draw-grid bond/calls (nth 1) :args))) | ||
| (is (= '(:lpad 0 1 :off) (-> launchpad/draw-grid bond/calls (nth 2) :args))) | ||
| (is (= '(:lpad 1 1 :green) (-> launchpad/draw-grid bond/calls (nth 3) :args)))))) | ||
|
|
||
| (testing "lights up bottom right and top left" | ||
| (with-stub [[launchpad/draw-grid (fn [& args] args)]] | ||
| (let [initial-grid [[true false] | ||
| [false true]]] | ||
| (renderer/draw-grid lpad initial-grid) | ||
| (is (= '(:lpad 0 0 :green) (-> launchpad/draw-grid bond/calls (nth 0) :args))) | ||
| (is (= '(:lpad 1 0 :off) (-> launchpad/draw-grid bond/calls (nth 1) :args))) | ||
| (is (= '(:lpad 0 1 :off) (-> launchpad/draw-grid bond/calls (nth 2) :args))) | ||
| (is (= '(:lpad 1 1 :green) (-> launchpad/draw-grid bond/calls (nth 3) :args))))))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep both drawing methods and have an easy way to switch between them in the
-main?