Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save anotherjesse/b8ec7a7147effa7053b2 to your computer and use it in GitHub Desktop.

Select an option

Save anotherjesse/b8ec7a7147effa7053b2 to your computer and use it in GitHub Desktop.
blocks scad

The block.clj file can generate various size blocks. block.scad is an example output of a 1x4 block

(ns threed.core
(:use [scad-clj.scad])
(:use [scad-clj.model]))
(centering! false)
(defn lego-single
[]
(difference
(union
(cube 8 8 9.6)
(->> (with-fn 36 (cylinder 2.4 1.6))
(translate [4 4 9.6])))
(->> (cube 4.8 4.8 8)
(translate [1.6 1.6 0]))
(->> (with-fn 36 (cylinder 0.8 9.6))
(translate [4 4 0]))))
(defn lego
[n]
(union
(difference
(apply union
(map #(translate [(* 8 %) 0 0] (lego-single)) (range n)))
(->> (cube (* 8 (- n 1)) 4.8 8)
(translate [1.6 1.6 0])))
(apply union (map #(union
(->> (cube 0.2 8 7)
(translate [(- (* % 8) 0.1) 0 2]))
(->> (with-fn 36 (cylinder 1.6 8))
(translate [(* % 8) 4 0])))
(range 1 n)))
))
(spit "block.scad"
(write-scad (lego 4)))
union () {
difference () {
union () {
translate ([0, 0, 0]) {
difference () {
union () {
cube ([8, 8, 9.6]);
translate ([4, 4, 9.6]) {
cylinder ($fn=36, h=1.6, r=2.4);
}
}
translate ([1.6, 1.6, 0]) {
cube ([4.8, 4.8, 8]);
}
translate ([4, 4, 0]) {
cylinder ($fn=36, h=9.6, r=0.8);
}
}
}
translate ([8, 0, 0]) {
difference () {
union () {
cube ([8, 8, 9.6]);
translate ([4, 4, 9.6]) {
cylinder ($fn=36, h=1.6, r=2.4);
}
}
translate ([1.6, 1.6, 0]) {
cube ([4.8, 4.8, 8]);
}
translate ([4, 4, 0]) {
cylinder ($fn=36, h=9.6, r=0.8);
}
}
}
translate ([16, 0, 0]) {
difference () {
union () {
cube ([8, 8, 9.6]);
translate ([4, 4, 9.6]) {
cylinder ($fn=36, h=1.6, r=2.4);
}
}
translate ([1.6, 1.6, 0]) {
cube ([4.8, 4.8, 8]);
}
translate ([4, 4, 0]) {
cylinder ($fn=36, h=9.6, r=0.8);
}
}
}
translate ([24, 0, 0]) {
difference () {
union () {
cube ([8, 8, 9.6]);
translate ([4, 4, 9.6]) {
cylinder ($fn=36, h=1.6, r=2.4);
}
}
translate ([1.6, 1.6, 0]) {
cube ([4.8, 4.8, 8]);
}
translate ([4, 4, 0]) {
cylinder ($fn=36, h=9.6, r=0.8);
}
}
}
}
translate ([1.6, 1.6, 0]) {
cube ([24, 4.8, 8]);
}
}
union () {
union () {
translate ([7.9, 0, 2]) {
cube ([0.2, 8, 7]);
}
translate ([8, 4, 0]) {
cylinder ($fn=36, h=8, r=1.6);
}
}
union () {
translate ([15.9, 0, 2]) {
cube ([0.2, 8, 7]);
}
translate ([16, 4, 0]) {
cylinder ($fn=36, h=8, r=1.6);
}
}
union () {
translate ([23.9, 0, 2]) {
cube ([0.2, 8, 7]);
}
translate ([24, 4, 0]) {
cylinder ($fn=36, h=8, r=1.6);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment