making the shapes in shapes.scl purely mathematical, no strings attached, only returning a set of the positions to iterate over.

This commit is contained in:
Ghoulboy78 committed 2021-02-24 10:14:28 +01:00
1 parent 8eba0b9b8a
commit ac031090ef
2 files changed
+63 -86

No files matched your search

@@ -1,8 +1,14 @@
//a library app, mostly for the draw command, which allows to import these shape-drawing functions into your own app.
//Arguments for each are to be given as a singleton list, for ease of use. This is with the exception of fill_flat, with
//the assumption that it is unlikely to be used outside of internal calls, but it is still available to be called if necessary.
//Make sure you read the arguments and input them in the correct order, or it will mess up.
//these functions return a set of all the positions in the shape, given the parameters, without repeating a position.
//This way, you can efficiently iterate over the positions once having generated them. See draw_beta.sc for an example.
draw_sphere(args)->(
[centre, radius, block, replacement, hollow] = args;
[centre, radius, hollow] = args;
positions = {};
[cx,cy,cz]=centre;
for(range(-90, 90, 45/radius),
cpitch = cos(_);
@@ -11,85 +17,75 @@ draw_sphere(args)->(
cyaw = cos(_)*cpitch*radius;
syaw = sin(_)*cpitch*radius;
if(hollow,
set_block(cx+cyaw,cy+spitch*radius,cz+syaw,block,replacement);
set_block(cx+cos(_+180)*cpitch*radius,cy+spitch*radius,cz+sin(_+180)*cpitch*radius,block,replacement),
positions += [cx+cyaw,cy+spitch*radius,cz+syaw];
positions += [cx+cos(_+180)*cpitch*radius,cy+spitch*radius,cz+sin(_+180)*cpitch*radius],
for(range(-syaw,syaw+1),
set_block(cx+cyaw*cpitch,cy+spitch*radius,cz+_,block,replacement)
positions += [cx+cyaw*cpitch,cy+spitch*radius,cz+_]
)
)
)
);
return(global_positions)
return(positions)
);
draw_diamond(args)->(
[pos, radius, block, replacement] = args;
[pos, radius] = args;
positions = {};
c_for(r=0, r<radius, r+=1,
y = r-radius+1;
c_for(x=-r,x<=r,x+=1,
z=r-abs(x);
set_block(pos:0+x, pos:1 +y, pos:2+z, block, replacement);
set_block(pos:0+x, pos:1 +y, pos:2-z, block, replacement);
set_block(pos:0+x, pos:1 -y, pos:2+z, block, replacement);
set_block(pos:0+x, pos:1 -y, pos:2-z, block, replacement);
positions += [pos:0+x, pos:1 +y, pos:2+z];
positions += [pos:0+x, pos:1 +y, pos:2-z];
positions += [pos:0+x, pos:1 -y, pos:2+z];
positions += [pos:0+x, pos:1 -y, pos:2-z];
)
);
return(global_positions)
return(positions)
);
draw_filled_diamond(args)->(
[pos, radius, block, replacement] = args;
[pos, radius] = args;
positions = {};
for(diamond(pos,radius,radius),
set_block(_x,_y,_z,block,replacement)
positions += pos(_)
);
return(global_positions)
return(positions)
);
draw_pyramid(args)->(
[pos, radius, height, pointing, orientation, block, fill_type, replacement, is_square] = args;
[pos, radius, height, pointing, orientation, fill_type, is_square] = args;//todo change to hollow boolean arg
positions = {};
hollow = fill_type=='hollow';
pointup = pointing=='up';
for(range(height),
r = if(pointup, radius * ( 1- _ / height) -1, radius * _ / height);
fill_flat(pos, _, r, is_square, orientation, block, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow),replacement)//Always close bottom off
positions += fill_flat(pos, _, r, is_square, orientation, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow))//Always close bottom off
);
return(global_positions)
return(positions)
);
draw_prism(args)->(
[pos, rad, height, orientation, block, fill_type, replacement, is_square]=args;
[pos, rad, height, orientation, fill_type, is_square]=args;//todo change to hollow boolean arg
positions = {};
hollow = fill_type =='hollow';
radius = rad+0.5;
for(range(height),
fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off
positions += fill_flat(pos, _, radius, is_square, orientation, if(_==0 || _==height-1,false,hollow))//Always close ends off
);
return(global_positions)
return(positions)
);
fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)->(
fill_flat(pos, offset, dr, rectangle, orientation, hollow)->(
r = floor(dr);
drsq = dr^2;
positions = {};
if(orientation=='x',
scan(pos,0,-r,-r,
if((!hollow && (rectangle || _y^2 + _z^2 <= drsq))||//if not hollow, vry simple
(hollow && ((rectangle && (abs(_y) == r || abs(_z) ==r)) || //If hollow and it's a rectangle
(!rectangle && (_y^2 + _z^2 <= drsq && (abs(_y)+1)^ 2 + (abs(_z)+1)^2 >= drsq)))),//If hollow and not rectangle
set_block(_x+offset,_y,_z,block, replacement)
positions += [_x+offset,_y,_z]
)
),
orientation == 'y',
@@ -97,7 +93,7 @@ fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)->
if((!hollow && (rectangle || _x^2 + _z^2 <= drsq))||//if not hollow, vry simple
(hollow && ((rectangle && (abs(_x) == r || abs(_z) ==r)) || //If hollow and it's a rectangle
(!rectangle && (_x^2 + _z^2 <= drsq && (abs(_x)+1)^ 2 + (abs(_z)+1)^2 >= drsq)))),//If hollow and not rectangle
set_block(_x,_y+offset,_z,block, replacement)
positions += [_x,_y+offset,_z]
)
),
orientation == 'z',
@@ -105,8 +101,9 @@ fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)->
if((!hollow && (rectangle || _y^2 + _x^2 <= drsq))||//if not hollow, vry simple
(hollow && ((rectangle && (abs(_y) == r || abs(_x) ==r)) || //If hollow and it's a rectangle
(!rectangle && (_y^2 + _x^2 <= drsq && (abs(_y)+1)^ 2 + (abs(_x)+1)^2 >= drsq)))),//If hollow and not rectangle
set_block(_x,_y,_z+offset,block, replacement)
positions += [_x,_y,_z+offset]
)
)
)
);
return(positions)
);