From 56c80785dfb6e26ec211c17d52315a93c7da5775 Mon Sep 17 00:00:00 2001 From: Thomas Preston Date: Wed, 4 Aug 2021 12:00:11 +0100 Subject: [openscad/en] Add OpenSCAD learnxinyminutes --- openscad.html.markdown | 120 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 openscad.html.markdown (limited to 'openscad.html.markdown') diff --git a/openscad.html.markdown b/openscad.html.markdown new file mode 100644 index 00000000..b2f46562 --- /dev/null +++ b/openscad.html.markdown @@ -0,0 +1,120 @@ +--- +language: openscad +filename: leanopenscad.scad +contributors: + - ["Thomas Preston", "https://github.com/tompreston/"] +--- + +Draw 3D models with code using [OpenSCAD](https://openscad.org/). + +```openscad +// Single-line comments start with // + +/* +Multi-line comments look like this. +*/ + +/* 3D Primitives */ +cube(10); +cube([5, 10, 20]); +sphere(10); + +/* Transformations */ +translate([20, 0, 0]) cube(10); +rotate([0, 20, 30]) cube(10); + +translate([20, 0, 0]) rotate([0, 20, 30]) cube(10); +rotate([0, 20, 30]) translate([20, 0, 0]) cube(10); + +/* Modifiers + * * disable + * ! show only + * # highlight / debug + * % transparent / background + */ +/* For example, show only the rotated cube at the origin, before we translate it. */ +translate([20, 0, 0]) !rotate([0, 20, 30]) cube(10); + +/* Formatting + * The following models are the same. The official docs prefer the second. + */ +rotate([0, 20, 30]) translate([20, 0, 0]) cube(10); + +rotate([0, 20, 30]) + translate([20, 0, 0]) + cube(10); + +rotate([0, 20, 30]) { + translate([20, 0, 0]) { + cube(10); + } +} + +/* Loops */ +num_cubes = 5; +r = 20; +cube_len = 5; + +for (i = [0:num_cubes]) { + echo(str("Plot cube ", i)); + rotate([0, i * 360 / num_cubes, 0]) + translate([r, 0, 0]) + cube(cube_len, center=true); +} + +/* Boolean operations. + * union() - the sum of both shapes + * difference() - the first shape, minus the second shape + * intersection() - only parts of both shapes which intersect + */ +cube_l = 20; +cube_w = 10; +cube_h = 10; + +hole_pos_l = 10; +hole_pos_h = 5; +hole_r = 3; + +difference() { + cube([cube_l, cube_w, cube_h]); + translate([hole_pos_l, 0, hole_pos_h]) + rotate([-90, 0, 0]) + cylinder(cube_w, r=hole_r); +} + +/* Functions calculate values. */ +function inch2mm(i) = i * 25.4; + +cube(inch2mm(2)); + +/* Modules create objects you want to use later. */ +module house(roof="flat", paint=[1,0,0]) { + color(paint) + if (roof=="flat") { + translate([0,-1,0]) cube(); + } else if (roof=="pitched") { + rotate([90,0,0]) + linear_extrude(height=1) + polygon(points=[[0,0],[0,1],[0.5,1.5],[1,1],[1,0]]); + } + else if (roof=="domical") { + translate([0,-1,0]) { + translate([0.5,0.5,1]) + sphere(r=0.5,$fn=20); + cube(); + } + } +} + +house("pitched"); +translate([2, 0, 0]) house("domical"); + +/* Import modules and function from other files. */ +include /* Import the content of the file as if they were written in this file. */ +use /* Import modules and functions, but do not execute any commands. */ +``` + +## Further Reading +* Official docs https://openscad.org/documentation.html +* Cheat sheet https://openscad.org/cheatsheet/index.html +* Vim bindings https://github.com/sirtaj/vim-openscad -- cgit v1.2.3 From 7654e1c6b6ebb11c3b14c3d51a06e08e099a7537 Mon Sep 17 00:00:00 2001 From: Tom Preston Date: Sat, 23 Jul 2022 22:53:11 +0100 Subject: Fixup typo in openscad.html.markdown Co-authored-by: Marcel Ribeiro Dantas, Ph.D. --- openscad.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openscad.html.markdown') diff --git a/openscad.html.markdown b/openscad.html.markdown index b2f46562..4e0fc696 100644 --- a/openscad.html.markdown +++ b/openscad.html.markdown @@ -1,6 +1,6 @@ --- language: openscad -filename: leanopenscad.scad +filename: learnopenscad.scad contributors: - ["Thomas Preston", "https://github.com/tompreston/"] --- -- cgit v1.2.3 From 68e71d00ff6cf2f65c164a865872738498267cbf Mon Sep 17 00:00:00 2001 From: Tom Preston Date: Sat, 23 Jul 2022 23:05:01 +0100 Subject: openscad: Remove multi-line comments to simplify --- openscad.html.markdown | 57 ++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 'openscad.html.markdown') diff --git a/openscad.html.markdown b/openscad.html.markdown index 4e0fc696..e09b5109 100644 --- a/openscad.html.markdown +++ b/openscad.html.markdown @@ -2,42 +2,38 @@ language: openscad filename: learnopenscad.scad contributors: - - ["Thomas Preston", "https://github.com/tompreston/"] + - ["Tom Preston", "https://github.com/tompreston/"] --- Draw 3D models with code using [OpenSCAD](https://openscad.org/). ```openscad -// Single-line comments start with // +// Comments look like this -/* -Multi-line comments look like this. -*/ - -/* 3D Primitives */ +// 3D Primitives cube(10); cube([5, 10, 20]); sphere(10); -/* Transformations */ +// Transformations translate([20, 0, 0]) cube(10); rotate([0, 20, 30]) cube(10); translate([20, 0, 0]) rotate([0, 20, 30]) cube(10); rotate([0, 20, 30]) translate([20, 0, 0]) cube(10); -/* Modifiers - * * disable - * ! show only - * # highlight / debug - * % transparent / background - */ -/* For example, show only the rotated cube at the origin, before we translate it. */ +// Modifiers +// +// * disable +// ! show only +// # highlight / debug +// % transparent / background +// +// For example, show only the rotated cube at the origin, before we translate it. translate([20, 0, 0]) !rotate([0, 20, 30]) cube(10); -/* Formatting - * The following models are the same. The official docs prefer the second. - */ +// Formatting +// The following models are the same. The official docs prefer the second. rotate([0, 20, 30]) translate([20, 0, 0]) cube(10); rotate([0, 20, 30]) @@ -50,7 +46,7 @@ rotate([0, 20, 30]) { } } -/* Loops */ +// Loops num_cubes = 5; r = 20; cube_len = 5; @@ -62,11 +58,12 @@ for (i = [0:num_cubes]) { cube(cube_len, center=true); } -/* Boolean operations. - * union() - the sum of both shapes - * difference() - the first shape, minus the second shape - * intersection() - only parts of both shapes which intersect - */ +// Boolean operations +// +// union() - the sum of both shapes +// difference() - the first shape, minus the second shape +// intersection() - only parts of both shapes which intersect +// cube_l = 20; cube_w = 10; cube_h = 10; @@ -82,12 +79,12 @@ difference() { cylinder(cube_w, r=hole_r); } -/* Functions calculate values. */ +// Functions calculate values function inch2mm(i) = i * 25.4; cube(inch2mm(2)); -/* Modules create objects you want to use later. */ +// Modules create objects you want to use later module house(roof="flat", paint=[1,0,0]) { color(paint) if (roof=="flat") { @@ -101,7 +98,7 @@ module house(roof="flat", paint=[1,0,0]) { translate([0,-1,0]) { translate([0.5,0.5,1]) sphere(r=0.5,$fn=20); - cube(); + cube(); } } } @@ -109,9 +106,9 @@ module house(roof="flat", paint=[1,0,0]) { house("pitched"); translate([2, 0, 0]) house("domical"); -/* Import modules and function from other files. */ -include /* Import the content of the file as if they were written in this file. */ -use /* Import modules and functions, but do not execute any commands. */ +// Import modules and function from other files +include // Import the content of the file as if they were written in this file +use // Import modules and functions, but do not execute any commands ``` ## Further Reading -- cgit v1.2.3