Last active
December 31, 2017 00:37
-
-
Save robbintt/768747b31b8896feb1ac9b3eeafda97a to your computer and use it in GitHub Desktop.
Some simple transformations of a cube, generalizing this stuff to make an 'augur' or 'grid' of objects would be fun.
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
;; bring primitives into namespace or whatever | |
(ns scad-demo.core | |
(:require [scad-clj.scad :refer :all] | |
[scad-clj.model :refer :all])) | |
(def c 50) | |
(def d 100) | |
(defn translate-primitive [prim x y z] | |
(->> prim | |
(translate [x y z]))) | |
; render all 0->d translations between [0 0 0] and [d d d] | |
; generalize this concept a bit more before implementing fully | |
; would be nice to get all [-d, 0, d] values | |
; also would be nice to stretch in multiples of d | |
; also you can translate and offset this object | |
(defn all-translations [prim d results] | |
; use case and recursion to follow all branches? | |
; the "d d d" needs altered per branch... | |
(all-translations prim d (concat objects [(translate-primitive prim d d d)])) | |
) | |
(def primitives | |
(->> | |
(union | |
;(all-translations (cube c c c) d []) | |
(translate-primitive (cube c c c) 0 0 0) | |
(translate-primitive (cube c c c) d 0 0) | |
(translate-primitive (cube c c c) 0 d 0) | |
(translate-primitive (cube c c c) 0 0 d) | |
(translate-primitive (cube c c c) d d 0) | |
(translate-primitive (cube c c c) 0 d d) | |
(translate-primitive (cube c c c) d 0 d) | |
(translate-primitive (cube c c c) d d d) | |
) | |
(rotate (/ Math/PI 4) [1 1 1]) | |
)) | |
;; export to scad | |
(spit "scad/example.scad" (write-scad primitives)) |
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
rotate (a=45.0, v=[1, 1, 1]) { | |
union () { | |
translate ([0, 0, 0]) { | |
cube ([50, 50, 50], center=true); | |
} | |
translate ([100, 0, 0]) { | |
cube ([50, 50, 50], center=true); | |
} | |
translate ([0, 100, 0]) { | |
cube ([50, 50, 50], center=true); | |
} | |
translate ([0, 0, 100]) { | |
cube ([50, 50, 50], center=true); | |
} | |
translate ([100, 100, 0]) { | |
cube ([50, 50, 50], center=true); | |
} | |
translate ([0, 100, 100]) { | |
cube ([50, 50, 50], center=true); | |
} | |
translate ([100, 0, 100]) { | |
cube ([50, 50, 50], center=true); | |
} | |
translate ([100, 100, 100]) { | |
cube ([50, 50, 50], center=true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment