From 96c98b8fd8d1db68da2d5ebf32ae884d54f6fde7 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Fri, 17 Feb 2023 11:21:57 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + Lego.json | 10 ++++++++++ Lego.scad | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 8 ++++++++ 4 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 Lego.json create mode 100644 Lego.scad create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1567411 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.stl diff --git a/Lego.json b/Lego.json new file mode 100644 index 0000000..527d65e --- /dev/null +++ b/Lego.json @@ -0,0 +1,10 @@ +{ + "parameterSets": { + "Brick_4x2": { + "type": "1", + "studs_x": "4", + "studs_y": "2" + } + }, + "fileFormatVersion": "1" +} diff --git a/Lego.scad b/Lego.scad new file mode 100644 index 0000000..b90792d --- /dev/null +++ b/Lego.scad @@ -0,0 +1,55 @@ +/* [Lego Type] */ +type = 1; // [1:Standard] +studs_x = 4; +studs_y = 2; + +/* [Hidden] */ +block_height = 9.6; // The height of the block without studs +length_per_stud = 31.8 / 4; +stud_details = 4 * ($preview ? 5 : 10); +wall_width = 1.4; +ceiling_width = 1; + +module stud() { + cylinder(d = 4.8, h = 1.8, $fn = stud_details); +} + +module studs() { + for (x = [0:studs_x-1], y = [0:studs_y-1]) + translate([(x+0.5) * length_per_stud, (y+0.5) * length_per_stud, 0]) + stud(); +} + +module base() { + difference() { + cube([ studs_x*length_per_stud, studs_y*length_per_stud, block_height ]); + translate([wall_width, wall_width, -ceiling_width]) { + cube([ + studs_x*length_per_stud - wall_width * 2, + studs_y*length_per_stud - wall_width * 2, + block_height + ]); + } + } +} + +module pillar() { + cylinder(h = block_height, d = 6.51, $fn = stud_details); +} + +module pillars() { + if (studs_x >= 2 && studs_y >= 2) { + for (x = [0:studs_x-2], y = [0:studs_y-2]) + translate([(x+1) * length_per_stud, (y+1) * length_per_stud, 0]) + pillar(); + } +} + +module block() { + base(); + pillars(); + translate([0, 0, block_height]) + studs(); +} + +block(); diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bcac840 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +PARAMETERS := $(shell cat Lego.json | grep -v '"parameterSets": ""' | jq -r '.parameterSets | keys[]') +STL = $(PARAMETERS:%=%.stl) + +all: $(STL) + +$(STL): Lego.scad Lego.json + openscad -o $@ -P $@ $< +