From bb30f37fe6b764fdbf740f8676c92a57449acc33 Mon Sep 17 00:00:00 2001 From: Jess Robinson Date: Wed, 27 Mar 2013 23:07:33 +0000 Subject: [PATCH] Initial revision, March 27th, 2013 --- README.md | 7 +++ tutorial/#04-meeple.scad# | 91 ++++++++++++++++++++++++++++++++ tutorial/01-introduction.scad | 40 ++++++++++++++ tutorial/02-shapes.scad | 39 ++++++++++++++ tutorial/03-transformations.scad | 61 +++++++++++++++++++++ tutorial/04-meeple.scad | 91 ++++++++++++++++++++++++++++++++ 6 files changed, 329 insertions(+) create mode 100644 README.md create mode 100755 tutorial/#04-meeple.scad# create mode 100755 tutorial/01-introduction.scad create mode 100755 tutorial/02-shapes.scad create mode 100755 tutorial/03-transformations.scad create mode 100755 tutorial/04-meeple.scad diff --git a/README.md b/README.md new file mode 100644 index 0000000..fbc34c2 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +OpenSCAD files for snhack +========================= + +tutorial/ contains a set of files which Jess created for an OpenSCAD tutorial, held at the hackspace on March 27th, 2013. + +Feel free to add your own files, or make improvements to the tutorial! + diff --git a/tutorial/#04-meeple.scad# b/tutorial/#04-meeple.scad# new file mode 100755 index 0000000..9cf4723 --- /dev/null +++ b/tutorial/#04-meeple.scad# @@ -0,0 +1,91 @@ +// 04 - A meeple + +// A meeple is a person-shaped playing piece for board games + +module body() { + union() { + // First we need a head: + translate([0,0,15]) + sphere(r=5, $fn=50); + + // and a body: + cylinder(h=15, r1=10, r2=1, $fn=50); + } +} + +// Save it for later by making it a module. +// (we're not calling it yet so reloading makes it disappear) + +// Let's display it for reference: +translate([0,0,7]) + body(); + +// Create a leg, then attach a foot. + +module leg() { + // A leg: + cylinder(h=7,r=3, $fn=50); + + // Foot + difference() { + union() { + // First a cylinder along the X-axis + rotate(a=90,v=[0,1,0]) + cylinder(h=5,r=3,$fn=50); + // Then round the end with a sphere: + translate([5,0,0]) + sphere(r=3, $fn=50); + } + + // Level off the bottom by subtracting a larger cube: + # translate([-5,-7,-14]) + cube(size=14); + } +} +// Wrap it in a module so that we can create two easily +// Then duplicate either side of the Y axis: + +2translate([0,3,0]) + leg(); +translate([0,-3,0]) + leg(); + +// All we need now are arms, grey the legs for a moment using % (or just comment them out) +// The arms are more cylinders with spheres on each end: +/* +module arm() { + cylinder(h=6, r=2.5, $fn=50); + sphere(r=2.5,$fn=50); + translate([0,0,6]) + sphere(r=2.5,$fn=50); +} +*/ + +// I want the the arm alongside the body: +// Angle the arm outwards. + +// We want the top (end of arm) to be two thirds up the body cone +// height of body (7) + two thirds (10) - length of arm(6) +// For the distance along y (out alongside the cone), I just start guessing... +// Move this code into the arm module. +module arm() { + translate([0,8,11]) + rotate(a=45,v=[1,0,0]) + union() { + cylinder(h=6, r=2.5, $fn=50); + sphere(r=2.5,$fn=50); + translate([0,0,6]) + sphere(r=2.5,$fn=50); + } +} + +// Now we draw two, and just mirror the second one: +arm(); +mirror([0,1,0]) + arm(); + + +// Tada! + + + diff --git a/tutorial/01-introduction.scad b/tutorial/01-introduction.scad new file mode 100755 index 0000000..3d5b6c1 --- /dev/null +++ b/tutorial/01-introduction.scad @@ -0,0 +1,40 @@ + +// 01 - Introduction + +// This is a comment + +i = 0; // This is a variable assignment and a comment + +/* +This is a +multi-line +comment +*/ + +// Output a string and the value of i: +echo("The value of i is:"); +echo(i); + +// Hit F5 (or Design -> Compile) to run. +// If you prefer your own editor, you can Reload and Compile (F4) + +// Don't forget to end your statements with a semi-colon(;) + +i = 3; +// Re-running this will now output 3, as variables are set at compile time! + +// Let's draw something! +// Values are mm when converted to STL +cube(size=20); +// cube(20); // Same thing with less text + +// Hit F5 (or Design -> Compile) to + +// View -> Show axes to see the origin and which axis is which +// Middle mouse button to zoom in and out +// Left mouse button to rotate +// Right mouse button to move + + + + diff --git a/tutorial/02-shapes.scad b/tutorial/02-shapes.scad new file mode 100755 index 0000000..454979f --- /dev/null +++ b/tutorial/02-shapes.scad @@ -0,0 +1,39 @@ +// 02 - Shapes + +// Cubes are not just square, they have x,y,z sides +// [..,..] is a vector in openscad (similar to an array elsewhere) +cube(size=[10,20,30]); + +// Spheres are, well, round and have a radius size +sphere(r=10); + +// To see which item we just drew, we can use # to highlight it: +# sphere(r=15); + +// The resolution is fairly rough by default, to get a smoother one, change $fn, you can do this globally, or per object: +sphere(r=15, $fn=100); + +// We can colour the objects (only for the preview, not the STL) +// And also stack/scope functions + +color("blue") + cube(size=[10,20,30]); + +// A cylinder has height (h) and radius (r): +cylinder(h=35,r=10); + +// It can also be a cone by using two radii: r1 and r2: +cylinder(h=50,r1=5,r2=40); + +// Polyhedrons, now it gets complicated! +// Provide a list of points [x,y,z] and a list of triangles [n,m,o] connecting the points (0-based index) +// I borrowed this example from the manual! + +polyhedron( + points=[ [30,30,0],[30,-30,0],[-30,-30,0],[-30,30,0], // the four points at base + [0,0,30] ], // the apex point + triangles=[ [0,1,4],[1,2,4],[2,3,4],[3,0,4], // each triangle side + [1,0,3],[2,1,3] ] // two triangles for square base + ); + +// What a mess, lets look at how to move things around.. diff --git a/tutorial/03-transformations.scad b/tutorial/03-transformations.scad new file mode 100755 index 0000000..7642e41 --- /dev/null +++ b/tutorial/03-transformations.scad @@ -0,0 +1,61 @@ + +// 03 - Transformations + +// To move objects around in space, we can translate them +// translate takes a vector, of x,y,z + +// So this cube: +cube(size=[10,10,20]); + +// Can be moved along X: +translate(v=[20,0,0]) + cube(size=[10,10,20]); + +// Or Y: +translate(v=[0,20,0]) + cube(size=[10,10,20]); + +// Or even X and Z (we can skip ahead if you're bored): +translate(v=[20,0,40]) + cube(size=[10,10,20]); + +// We can also translate two objects together by using curlies: +// Look, a badmington shuttlecock! +translate(v=[0,0,50]) { + sphere(r=10); + cylinder(h=30,r1=5,r2=30); +} + +// Let's turn it sideways, rotate can take a number of degrees, and a vector to rotate around (default [0,0,0] which does nothing) +rotate(a=90,v=[0,1,0]) { + translate(v=[0,0,50]) { + sphere(r=10); + cylinder(h=30,r1=5,r2=30); + } +} + +// Rotation is always around the axis, so to rotate "in space" do a rotation, then translate: +translate(v=[0,0,50]) { + rotate(a=90,v=[0,1,0]) { + sphere(r=10); + cylinder(h=30,r1=5,r2=30); + } +} + +// Multiple items together are a union, we can also subtract intersecting parts using "difference" +// Subtract the rotated item from the original one: +# difference() { + union() { + sphere(r=10); + cylinder(h=30,r1=5,r2=30); + } + rotate(a=90,v=[0,1,0]) { + sphere(r=10); + cylinder(h=30,r1=5,r2=30); + } +} + +// Note that subtracting exact faces produces uncertain results, it would be better in this case to subtract the two cylinders without the sphere. + +// Let's build something now... + diff --git a/tutorial/04-meeple.scad b/tutorial/04-meeple.scad new file mode 100755 index 0000000..9d89a09 --- /dev/null +++ b/tutorial/04-meeple.scad @@ -0,0 +1,91 @@ +// 04 - A meeple +// A meeple is a person-shaped playing piece for board games + +// Adjust for more roundiness: +$fn=25; + +module body() { + union() { + // First we need a head: + translate([0,0,15]) + sphere(r=5); + + // and a body: + cylinder(h=15, r1=10, r2=1); + } +} + +// Save it for later by making it a module. +// (we're not calling it yet so reloading makes it disappear) + +// Let's display it for reference: +translate([0,0,7]) + body(); + +// Create a leg, then attach a foot. + +module leg() { + // A leg: + cylinder(h=7,r=3); + + // Foot + difference() { + union() { + // First a cylinder along the X-axis + rotate(a=90,v=[0,1,0]) + cylinder(h=5,r=3); + // Then round the end with a sphere: + translate([5,0,0]) + sphere(r=3); + } + + // Level off the bottom by subtracting a larger cube: + # translate([-5,-7,-14]) + cube(size=14); + } +} +// Wrap it in a module so that we can create two easily +// Then duplicate either side of the Y axis: + +translate([0,3,0]) + leg(); +translate([0,-3,0]) + leg(); + +// All we need now are arms, grey the legs for a moment using % (or just comment them out) +// The arms are more cylinders with spheres on each end: +/* +module arm() { + cylinder(h=6, r=2.5); + sphere(r=2.5); + translate([0,0,6]) + sphere(r=2.5); +} +*/ + +// I want the the arm alongside the body: +// Angle the arm outwards. + +// We want the top (end of arm) to be two thirds up the body cone +// height of body (7) + two thirds (10) - length of arm(6) +// For the distance along y (out alongside the cone), I just start guessing... +// Move this code into the arm module. +module arm() { + translate([0,8,11]) + rotate(a=45,v=[1,0,0]) + union() { + cylinder(h=6, r=2.5); + sphere(r=2.5,$fn=50); + translate([0,0,6]) + sphere(r=2.5,$fn=50); + } +} + +// Now we draw two, and just mirror the second one: +arm(); +mirror([0,1,0]) + arm(); + + +// Tada! +