Initial Drop of Scaddy.

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2017-12-01 13:55:57 +01:00
commit 85ceeaee95
11 changed files with 228 additions and 0 deletions

13
2d.scad Normal file
View file

@ -0,0 +1,13 @@
include <utils.scad>
module fillet(r) {
offset(r = -r,$fn=circle_details(r)) {
offset(delta = r,$fn=32,$fn=circle_details(r)) {
children();
}
}
}
module dcircle(r) {
circle(r,$fn=circle_details(r));
}

23
aliases.scad Normal file
View file

@ -0,0 +1,23 @@
module move(vec) {
translate(vec) children();
}
module extrude(height = 100, center = true, convexity = 10, twist = 0, slices = 20, scale = 1.0) {
linear_extrude(height = height, center = center, convexity = convexity, twist = twist, slices = slices, scale = scale) children();
}
module revolve(angle = 360, convexity = 2) {
rotate_extrude(angle = angle, convexity = convexity) children();
}
module 2d_front() {
rotate(x(90)) children();
}
module 2d_left() {
rotate(z(-90)) 2d_front() children();
}
module 2d_right() {
rotate(z(90)) 2d_front() children();
}

13
component.scad Normal file
View file

@ -0,0 +1,13 @@
module component_get(name) {
component_display(name) children();
}
module component_display(name) {
$scaddy_component = name;
children();
}
module component(name) {
if($scaddy_component == undef || $scaddy_component == name) children();
}

7
config.scad Normal file
View file

@ -0,0 +1,7 @@
/* [makereal SCAD Common Configuration] */
// Minimum polygon count for curve
CURVE_POLYGON_MINIMUM=16;
// Maximum length of curve polygons.
CURVE_POLYGON_LENGTH=1; // [0:100]

44
debug.scad Normal file
View file

@ -0,0 +1,44 @@
module debug(force=false) {
if($scaddy_debug || force ) {
$scaddy_debug=true;
%children();
}
}
module _debug_mesh() {
%color([255,0,0,0.4]) children();
}
module debug_points(vector) {
_debug_mesh()
for(i = [0:1:len(vector)-1])
translate(vector[i]) {
sphere(1);
text(str(i),size=4);
}
}
module xy_axis(length=20,width=0.5) {
_debug_mesh()
move((-width/2)*[1,1,0])
extrude(width) {
square([width,length]);
square([length,width]);
move(x(length)-y(1))
text("x",halign="right",valign="top",size=5);
move(y(length)-x(1))
text("y",valign="top",halign="right",size=5);
}
}
module xyz_axis(length=20,width=0.5) {
xy_axis(length,width);
_debug_mesh()
move((-width/2)*[1,1,0]) rotate(x(90))
extrude(width) {
square([width,length]);
move(y(length)-x(1))
text("z",valign="top",halign="right",size=5);
}
}

6
functions.scad Normal file
View file

@ -0,0 +1,6 @@
function circle_y(x,r,cx=0,cy=0) = (2*cy + sqrt(8*cx*x-4*cx*cx-4*(x)*(x)+4*r*r))/2;
function curve_r(curve_h,curve_w)=(pow(curve_h,2)+pow(curve_w,2))/(2*abs(curve_w));
function pow2(x)=x*x;
function pow3(x)=x*x*x;

31
polyhedron.scad Normal file
View file

@ -0,0 +1,31 @@
use <scaddy/vector.scad>
function fill_layer(vec,o=0)=let(n=len(vec)) concat([
[o+0,o+1,o+n-1]],[ for (i=[1:1:n/2-2]) [i, i+1, n-i-1, n-i ] + [o,o,o,o] ],[[o+n/2-1,o+n/2,o+n/2+1]]);
function wall(vec,o=0)=let(n=len(vec))
[ for (i=[0:1:n-1]) [i, n+i, n+(i+1)%n, (i+1)%n] + [o,o,o,o] ];
module polyhedron_layers(layers) {
lc = len(layers);
bottom=layers[0];
top=layers[lc-1];
points_per_layer=len(bottom);
points = flatten_vec(layers);
walls=[for(i = [0:1:lc-2]) wall(bottom,i*points_per_layer) ];
bottom_f=fill_layer(bottom);
walls_f=flatten_vec(walls);
top_f = [for( i = fill_layer(top,(lc-1)*points_per_layer))
reverse_vector(i)];
//echo(bottom_f = bottom_f);
//echo(top_f = top_f);
//echo(walls_f=walls_f);
//print_points(points);
polyhedron(points,faces=concat(
bottom_f,
top_f,
walls_f
));
}

14
preconditions.scad Normal file
View file

@ -0,0 +1,14 @@
module precondition(test,error) {
if(!test) {
echo(str("<font color='red'>",error,"<font>"));
assert(false);
} else children();
}
module check_defined(val,error) {
precondition(val != undef,error) children();
}
module check_parent(parent,statement,error) {
precondition(parent_module(3) == parent,str(statement,"(): ",error)) children();
}

8
scaddy.scad Normal file
View file

@ -0,0 +1,8 @@
include <./debug.scad>;
include <./config.scad>;
include <./preconditions.scad>;
include <./utils.scad>;
include <./2d.scad>;
include <./vector.scad>;
include <./aliases.scad>;
include <./component.scad>;

33
utils.scad Normal file
View file

@ -0,0 +1,33 @@
include <config.scad>;
function circle_details(r) = max(CURVE_POLYGON_MINIMUM,round(3.1415*r*2/CURVE_POLYGON_LENGTH));
function select(sel,vec) = [ for (i=sel) vec[i]];
function default(val,comp) = val != undef ? val : comp;
module construct() {
module construct_get(name) {
$construct_get=name;
children();
}
difference() {
construct_get("add") children();
construct_get("remove") children();
}
}
module add() {
//check_parent("construct_get", "add", "could be used only as child of construct()");
if($construct_get=="add")
children();
}
module remove() {
echo("remove",parent_module(1));
if($construct_get=="remove")
children();
}

36
vector.scad Normal file
View file

@ -0,0 +1,36 @@
/**
* Returns [n,0,0] vector.
*
* @param n Size of vector in specified direction
*/
function x(n)=[n,0,0];
function y(n)=[0,n,0];
function z(n)=[0,0,n];
/**
* Checks if vector (list) contains specified value.
*
* @param vec Vector to be checked
* @param vec Value to be checked
*/
function contains(vec, val)=len([for (i = list) if (i==val) i]) > 0;
/**
* Reverses supplied vector
*/
function reverse_vector(vec) = let(n=len(vec)) [for (i= [1:1:n]) vec[n-i]];
function scale_vec(sv,vec2)= let(l=len(sv))
[ for(v = vec2)
[for(i = [0:1:l-1]) v[i]*sv[i] ]];
/**
* Moves each vector by given offset
*
* @param vec2 set of vectors
* @param mov Movement vector
*
*/
function move_vectors(vec2,mov)=[ for(v = vec2) v+mov];
function flatten_vec(list) = [ for (i = list, v = i) v ];