-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chapter 1 Examples 3 and 4, plus Vector Math table reference
- Loading branch information
Showing
5 changed files
with
168 additions
and
3 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
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,30 @@ | ||
(ns noc.chapter-1-3 | ||
(:require | ||
|
||
[thi.ng.math.core :as tm] | ||
[thi.ng.geom.vector :as v] | ||
[quil.core :as q])) | ||
|
||
(def size [640 240]) | ||
|
||
(defn init-state [{:keys [width height] :as state}] | ||
{}) | ||
|
||
(defn setup! [{:keys [width height]}] | ||
(q/background 255)) | ||
|
||
(defn tick [state] | ||
state) | ||
|
||
(defn draw! [{:keys [width height mouse-x mouse-y]}] | ||
(let [mouse (v/vec2 mouse-x mouse-y) | ||
center (v/vec2 (quot width 2) (quot height 2)) | ||
subtracted (tm/- mouse center)] | ||
(q/background 255) | ||
(q/stroke-weight 4) | ||
(q/stroke 200) | ||
(q/line 0 0 mouse-x mouse-y) | ||
(q/line 0 0 (first center) (second center)) | ||
(q/stroke 0) | ||
(q/translate (quot width 2) (quot height 2)) | ||
(q/line 0 0 (first subtracted) (second subtracted)))) |
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,35 @@ | ||
(ns noc.chapter-1-4 | ||
(:require | ||
|
||
[thi.ng.math.core :as tm] | ||
[thi.ng.geom.vector :as v] | ||
[quil.core :as q])) | ||
|
||
(def size [640 240]) | ||
|
||
(defn init-state [{:keys [width height] :as state}] | ||
{}) | ||
|
||
(defn setup! [{:keys [width height]}] | ||
(q/background 255)) | ||
|
||
(defn tick [state] | ||
state) | ||
|
||
(defn line [[x1 y1] [x2 y2]] | ||
(q/line x1 y1 x2 y2)) | ||
|
||
(defn draw! [{:keys [width height mouse-x mouse-y]}] | ||
(let [zero (v/vec2 0 0) | ||
mouse (v/vec2 mouse-x mouse-y) | ||
center (v/vec2 (quot width 2) (quot height 2)) | ||
subtracted (tm/- mouse center) | ||
multed (tm/* subtracted 0.5)] | ||
(q/background 255) | ||
(q/translate (quot width 2) (quot height 2)) | ||
(q/stroke-weight 2) | ||
(q/stroke 200) | ||
(line zero subtracted) | ||
(q/stroke 0) | ||
(q/stroke-weight 4) | ||
(line zero multed))) |
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