Results 1 to 10 of 72
Thread: OpenScad Help Centre
Threaded View
-
12-03-2014, 09:28 AM #13
A sphere and cylinder are always generated at (0,0). So when you translate them... what ever amount you translated them... Is where the center's are. I warmed over your code so you can see how to make your code easier to understand:
Code:singleduploblock(); module singleduploblock () {
$fn=100;cube (32,32,20); color("gray", 0.5) translate([16,16,20]) cylinder(36, d=30); difference() {color("red" ) translate([16,16,55]) sphere(d=30); color ("lime") translate ([ 8,8,68 ]) cube([16,16,8]);}}
singleduploblock() does not have any paremeters, and certainly does not need its name passed in as a parameter.
It is typical, and usually better to put modifiers like color() in the front of the line. And it is usually best to combine things that go together like color(), translate() and cube() so it is easy to pick out what everything is doing.
And of course, indenting really helps too. For example, having things indented makes it easier to see what the difference() is operating on. The code directive isn't working perfectly on this post... But you can see what I mean even though I'm restricted on how to indent 'properly'. You only have one module in this file so this won't be as clear. But a lot of people indent everything within a module so it is clear where a module starts and ends. The module declarations are part of the 'top level' so they are pushed as far to the left as possible. As you get nested deeper and deeper, you indent more and more to show that.
Even though what I posted is almost exactly what you had... most people would prefer to work with my version.Last edited by Roxy; 12-03-2014 at 09:47 AM.
Please explain to me how to...
05-17-2024, 12:15 PM in 3D Printer Parts, Filament & Materials