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
(defn compute-dejong | |
"Computes a single DeJong 2d point vector for given params and XY pos" | |
[a b c d x y] | |
(v/vec2 | |
(+ (Math/sin (* a y)) (Math/cos (* (* b x) x))) | |
(+ (Math/sin (* (* c x) x)) (Math/cos (* d y))))) | |
(->> (range 1e6) | |
(reduce | |
(fn [[points [x y]] _] |
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
(require '[thi.ng.geom.core :as g]) | |
(require '[thi.ng.geom.circle :as c]) | |
(require '[thi.ng.geom.polygon :as poly]) | |
(-> (c/circle 100) | |
(g/as-polygon 6) | |
(g/sample-uniform 10 false)) | |
;; [[100.0 0.0] [95.0 8.660254037844387] [90.0 17.320508075688775] ...] |
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
(require '[thi.ng.geom.core :as g]) | |
(require '[thi.ng.geom.vector :as v]) | |
(defn make-agent | |
[pos theta speed rot-theta] | |
{:pos pos | |
:theta theta | |
:rot-theta rot-theta | |
:speed speed | |
:path [] |
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
(ns canvas | |
(:require | |
[thi.ng.geom.gl.webgl.animator :as anim] | |
[reagent.core :as reagent])) | |
(defn canvas-component | |
[props] | |
(reagent/create-class | |
{:component-did-mount | |
(fn [this] |
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
(defmacro get-in* | |
"Macro version of clojure.core/get-in without not-found fallback" | |
[root path] | |
(loop [root root, path path] | |
(if path | |
(recur `(get ~root ~(first path)) (next path)) | |
root))) | |
(macroexpand-1 '(get-in* [[1 2 3] [3 4 [5 6 7 8]]] [1 2 3])) | |
;; (clojure.core/get (clojure.core/get (clojure.core/get [[1 2 3] [3 4 [5 6 7 8]]] 1) 2) 3) |
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
(defn attrib-buffer-view | |
[ptr stride num] | |
(js/Float32Array. (.-buffer (aget js/Particles "HEAPU8")) ptr (* stride num))) | |
(defn update-attrib-buffer | |
[gl attrib ptr stride num] | |
(.bindBuffer gl glc/array-buffer | |
(get-in (:scene @app) [:particles :attribs attrib :buffer])) | |
(.bufferData gl glc/array-buffer | |
(attrib-buffer-view ptr stride num) |
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
;; initialize particle system and | |
;; create C function wrappers | |
(let [psys (.ccall js/Particles "initParticleSystem" "*" | |
#js ["number" "number" "number" "number"] | |
#js [10000 1000 0.0 -0.01 0.125]) | |
psys-update (.cwrap js/Particles "updateParticleSystem" "*" | |
#js ["number"]) | |
psys-count (.cwrap js/Particles "getNumParticles" "number" | |
#js ["number"]) | |
particle-ptr (.ccall js/Particles "getParticlesPointer" "*" |
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
// particle system structs | |
typedef struct { | |
float x,y,z; | |
} Vec3; | |
typedef struct { | |
Vec3 pos; // 12 bytes | |
Vec3 vel; // 12 bytes | |
Vec3 col; // 12 bytes |
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
static Screen *screen; | |
int main(void) { | |
HAL_Init(); | |
SystemClock_Config(); | |
screen = ct_screen_init(); | |
while (1) { | |
ct_screen_flip_buffers(screen); | |
// put normal drawing code here... |
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
(ns tjunctions | |
(:require | |
[thi.ng.geom.core :as g] | |
[thi.ng.geom.core.utils :as gu] | |
[thi.ng.geom.line :as l] | |
[thi.ng.geom.gmesh :as gm] | |
[thi.ng.math.core :as m])) | |
(defn- edges-without-v | |
"Takes gmesh and vertex, returns lazyseq of all edges NOT related to v." |