3dCustomizer.net
Search:
Browse
|
Create
|
Register
|
Login
3dCustomizer.net: Design custom 3D Models for 3D printing
OpenSCAD - Examples - Functions - List Comprehensions
Controls:
seconds
OpenSCAD Code
Input Params
Imported Files
Imported files:
Add file(s):
Select
HTML Form
Output Params
CLI Args
fast-csg
fast-csg-trust-corefinement
fast-csg-debug
fast-csg-remesh
fast-csg-remesh-predictibly
roof
input-driver-dbus
lazy-union
vertex-object-renderers
vertex-object-renderers-indexing
vertex-object-renderers-direct
vertex-object-renderers-prealloc
textmetrics
import-function
sort-stl
manifold
debug=all
STL Viewer
Viewer Settings
Buy 3D Print
Save:
|
| Draw:
flat
smooth
wireframe
|
| Opacity:
|
Lock Camera/Position
Rotate Model
Edge Lines
Show X,Y,Z axises
Center Model on X,Y,Z axes
Part Printing Services
Affiliates
3D Part Price
TreatStock
JLC PCB - 3D Printing
Non-affiliates
iMaterialise
Craftcloud
Sculpteo
Printelize
JawsTec
Shapeways
MakeXYZ
// list_comprehensions.scad - Examples of list comprehension usage // Basic list comprehension: // Returns a 2D vertex per iteration of the for loop // Note: subsequent assignments inside the for loop is allowed module ngon(num, r) { polygon([for (i=[0:num-1], a=i*360/num) [ r*cos(a), r*sin(a) ]]); } linear_extrude(1){ ngon(3, 10); translate([20,0]) ngon(6, 8); translate([36,0]) ngon(10, 6); } // More complex list comprehension: // Similar to ngon(), but uses an inner function to calculate // the vertices. the let() keyword allows assignment of temporary variables. module rounded_ngon(num, r, rounding = 0) { function v(a) = let (d = 360/num, v = floor((a+d/2)/d)*d) (r-rounding) * [cos(v), sin(v)]; polygon([for (a=[0:360-1]) v(a) + rounding*[cos(a),sin(a)]]); } linear_extrude(1){ translate([0,22]) rounded_ngon(3, 10, 5); translate([20,22]) rounded_ngon(6, 8, 4); translate([36,22]) rounded_ngon(10, 6, 3); } // Gear/star generator // Uses a list comprehension taking a list of radii to generate a star shape module star(num, radii) { function r(a) = (floor(a / 10) % 2) ? 10 : 8; polygon([for (i=[0:num-1], a=i*360/num, r=radii[i%len(radii)]) [ r*cos(a), r*sin(a) ]]); } linear_extrude(1){ translate([0,44]) star(20, [6,10]); translate([20,44]) star(40, [6,8,8,6]); translate([36,44]) star(30, [3,4,5,6,5,4]); } echo(version=version()); // Written by Marius Kintel <marius@kintel.net> // // To the extent possible under law, the author(s) have dedicated all // copyright and related and neighboring rights to this software to the // public domain worldwide. This software is distributed without any // warranty. // // You should have received a copy of the CC0 Public Domain // Dedication along with this software. // If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
Console
Debugger
3dCustomizer.net © 2025 |
Help
|
About
|
Contact
|
Links
|
Credits
Loaded in: 0.0043 seconds