From c94bdc7c5c3eb02b43ac3bcfe04541f899dac00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sala=C3=BCn?= Date: Sun, 4 Oct 2020 23:50:31 +0200 Subject: [PATCH 1/6] Add basics, export & tools --- src/diamant/basics.clj | 12 ++++++++++++ src/diamant/export.clj | 9 +++++++++ src/diamant/tools.clj | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/diamant/basics.clj create mode 100644 src/diamant/export.clj create mode 100644 src/diamant/tools.clj diff --git a/src/diamant/basics.clj b/src/diamant/basics.clj new file mode 100644 index 0000000..539d0a1 --- /dev/null +++ b/src/diamant/basics.clj @@ -0,0 +1,12 @@ +(ns diamant.basics + (:require [scad-clj.model :as model])) + +(defn inner-tube + [inner-radius thickness height] + (model/difference + (model/cylinder (+ inner-radius thickness) height) + (model/cylinder inner-radius (+ 1 height)))) + +(defn outer-tube + [outer-radius thickness height] + (inner-tube (- outer-radius thickness) thickness height)) \ No newline at end of file diff --git a/src/diamant/export.clj b/src/diamant/export.clj new file mode 100644 index 0000000..82dbab0 --- /dev/null +++ b/src/diamant/export.clj @@ -0,0 +1,9 @@ +(ns diamant.export + (:require [scad-clj.scad :as scad])) + +(defn write + ([block] (write "model.scad" block)) + ([name block] (->> + block + (scad/write-scad) + (spit name)))) \ No newline at end of file diff --git a/src/diamant/tools.clj b/src/diamant/tools.clj new file mode 100644 index 0000000..b4382a2 --- /dev/null +++ b/src/diamant/tools.clj @@ -0,0 +1,11 @@ +(ns diamant.tools + (:require [scad-clj.model :as model])) + +(defn slice + [block] + (model/difference + block + (let [s 500] + (->> + (model/cube s s s) + (model/translate [(/ s 2) 0 0]))))) \ No newline at end of file From 907b18d904326f875fa0f5466cc886813201ed58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sala=C3=BCn?= Date: Sun, 4 Oct 2020 23:50:43 +0200 Subject: [PATCH 2/6] Add calva to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d18f225..9a7bd4c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ pom.xml.asc /.nrepl-port .hgignore .hg/ +.calva \ No newline at end of file From d63f866241cc8b1795662714ab13711beee4f046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sala=C3=BCn?= Date: Sun, 4 Oct 2020 23:50:51 +0200 Subject: [PATCH 3/6] Add symmetry --- src/diamant/geometry.clj | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/diamant/geometry.clj b/src/diamant/geometry.clj index d8bcc6c..66d9a02 100644 --- a/src/diamant/geometry.clj +++ b/src/diamant/geometry.clj @@ -2,12 +2,22 @@ (:require [scad-clj.model :as model])) (defn circleify - "Copy object count times around a circle of the given radius" - [radius count object] - (let [angle (/ (* 2 Math/PI) count)] + "Copy object n times around a circle of the given radius" + [radius n object] + (let [angle (/ (* 2 Math/PI) n) + obj (if (vector? object) object [object])] (->> - (range count) + (range n) (map #(->> - object + (get obj (mod %1 (count obj))) (model/translate [radius 0 0]) - (model/rotate [0 0 (* angle %1)])))))) \ No newline at end of file + (model/rotate [0 0 (* angle %1)])))))) + +(defn symmetry + [block] + (->> + [-1 1] + (map #(->> + block + (model/scale [%1 1 1]))) + (apply model/union))) \ No newline at end of file From d9df849ec527dd905d51266e464721c4af33a03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sala=C3=BCn?= Date: Sun, 4 Oct 2020 23:51:08 +0200 Subject: [PATCH 4/6] Bump version --- project.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 23301fa..485313b 100644 --- a/project.clj +++ b/project.clj @@ -1,5 +1,5 @@ -(defproject diamant "0.1.0-SNAPSHOT" - :description "Commonly useful space modeling functions for scad-clj" +(defproject diamant "0.2.0-SNAPSHOT" + :description "Practical space-modeling commons & helpers for scad-clj" :url "https://github.com/altitude/diamant" :license {:name "MIT"} :dependencies [[org.clojure/clojure "1.10.0"] From ba659646bf62d058abd700260a09d032243d9ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sala=C3=BCn?= Date: Tue, 13 Oct 2020 23:42:27 +0200 Subject: [PATCH 5/6] Added parts registry --- src/diamant/registry.clj | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/diamant/registry.clj diff --git a/src/diamant/registry.clj b/src/diamant/registry.clj new file mode 100644 index 0000000..b46cddf --- /dev/null +++ b/src/diamant/registry.clj @@ -0,0 +1,25 @@ +(ns diamant.registry + (:require [diamant.export :as export])) + +(def parts (atom {})) + +(def live false) + +(defn set-live-mode + [v] + (def live v)) + +(defn defpart + [name part & {:keys [write] :or {write live}}] + (swap! parts assoc name part) + (if write + (export/write part) + nil)) + +(defn getparts + ([] + @parts) + ([& names] + (->> + (select-keys @parts names) + (vals)))) \ No newline at end of file From 60f96e16c068d79e06fdd284f23b789283c4cb2d Mon Sep 17 00:00:00 2001 From: altitude Date: Fri, 16 Oct 2020 14:27:37 +0200 Subject: [PATCH 6/6] add symmetry axis --- src/diamant/geometry.clj | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/diamant/geometry.clj b/src/diamant/geometry.clj index 66d9a02..b8074e0 100644 --- a/src/diamant/geometry.clj +++ b/src/diamant/geometry.clj @@ -14,10 +14,14 @@ (model/rotate [0 0 (* angle %1)])))))) (defn symmetry - [block] - (->> - [-1 1] - (map #(->> - block - (model/scale [%1 1 1]))) - (apply model/union))) \ No newline at end of file + ([axis object] + (let [scale (case axis + :x [-1 1 1] + :y [1 -1 1] + :z [1 1 -1] + [1 1 1])] + (model/union + object + (model/scale scale object)))) + ([object] + (symmetry :x object))) \ No newline at end of file