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:
1 parent
8eba0b9b8a
commit
ac031090ef
2 files changed
+63
-86
No files matched your search
@@ -1,23 +1,23 @@
|
||||
import('math','_euclidean_sq','_vec_length');
|
||||
import('shapes','draw_sphere', 'draw_diamond', 'draw_filled_diamond', 'draw_pyramid', 'draw_prism'); //importing all the shape funcs from the other app
|
||||
|
||||
__config() -> {
|
||||
'commands'->{
|
||||
'sphere <center> <radius> <block>'->_(c,r,b)->draw('draw_sphere',[c,r,b,null,true]),
|
||||
'sphere <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_sphere',[c,r,b,rp,true]),
|
||||
'ball <center> <radius> <block>'->_(c,r,b)->draw('draw_sphere',[c,r,b,null,false]),
|
||||
'ball <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_sphere',[c,r,b,rp,false]),
|
||||
'diamond <center> <radius> <block> hollow' -> _(c,r,b)->draw('draw_diamond',[c,r,b,null]),
|
||||
'diamond <center> <radius> <block> hollow replace <replacement>'->_(c,r,b,rp)->draw('draw_diamond',[c, r, b, rp]),
|
||||
'diamond <center> <radius> <block>' -> _(c,r,b)->draw('draw_filled_diamond',[c,r,b,null]),
|
||||
'diamond <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_filled_diamond',[c, r, b, rp]),
|
||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,b,ho,null, true]),
|
||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,b,ho,rp,true]),
|
||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,b,ho,null, false]),
|
||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,b,ho,rp,false]),
|
||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow>'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,b,ho,null, true]),
|
||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,b,ho,rp,true]),
|
||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow>'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,b,ho,null, false]),
|
||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,b,ho,rp,false]),
|
||||
'sphere <center> <radius> <block>'->_(c,r,b)->draw('draw_sphere',[c,r, true],b,null),
|
||||
'sphere <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_sphere',[c,r,true],b,rp),
|
||||
'ball <center> <radius> <block>'->_(c,r,b)->draw('draw_sphere',[c,r,false],b,null),
|
||||
'ball <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_sphere',[c,r,false],b,rp),
|
||||
'diamond <center> <radius> <block> hollow' -> _(c,r,b)->draw('draw_diamond',[c,r],b,null),
|
||||
'diamond <center> <radius> <block> hollow replace <replacement>'->_(c,r,b,rp)->draw('draw_diamond',[c, r], b, rp),
|
||||
'diamond <center> <radius> <block>' -> _(c,r,b)->draw('draw_filled_diamond',[c,r],b,null),
|
||||
'diamond <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_filled_diamond',[c, r], b, rp),
|
||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,ho, true],b,null),
|
||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,ho,true],b,rp),
|
||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,ho, false],b,null),
|
||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,ho,false],b,rp),
|
||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow>'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,ho, true],b,null),
|
||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,ho,true],b,rp),
|
||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow>'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,ho, false],b,null),
|
||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,ho,false],b,rp),
|
||||
},
|
||||
'arguments'->{
|
||||
'center'->{'type'->'pos', 'loaded'->'true'},
|
||||
@@ -32,10 +32,6 @@ __config() -> {
|
||||
'scope'->'global'
|
||||
};
|
||||
|
||||
|
||||
//"Boilerplate" code
|
||||
|
||||
|
||||
_block_matches(existing, block_predicate) ->
|
||||
(
|
||||
[name, block_tag, properties, nbt] = block_predicate;
|
||||
@@ -46,32 +42,16 @@ _block_matches(existing, block_predicate) ->
|
||||
(!tag || tag_matches(block_data(existing), tag))
|
||||
);
|
||||
|
||||
set_block(x, y, z, block, replacement)->//doing it like this so I can get list of blocks to place from functions
|
||||
global_positions:0+=[[x, y, z], block, replacement];//Cos optional args return list always
|
||||
draw(what, args, block, replacement)->(//custom setter cos it's easier
|
||||
positions = call(what,args); //returning blocks to be set
|
||||
|
||||
affected = 0
|
||||
|
||||
global_positions = [{}, 0];//using a set so I dont waste compute on duplicate positions
|
||||
|
||||
affected(player) -> (
|
||||
affected = global_positions;
|
||||
print(player,format('gi Filled ' + affected:1 + ' blocks'));
|
||||
global_positions = [{},0];
|
||||
affected
|
||||
);
|
||||
|
||||
|
||||
//Drawing commands
|
||||
|
||||
draw(what, args)->(//custom setter cos it's easier
|
||||
call(what,args);//putting blocks to be set into the first element of global_positions
|
||||
|
||||
for(global_positions:0,
|
||||
[pos, block, replacement]=_;
|
||||
existing = block(pos);
|
||||
for(positions,
|
||||
existing = block(_);
|
||||
if(block != existing && (!replacement || _block_matches(existing, replacement) ),
|
||||
global_positions:1 += bool(set(existing,block))
|
||||
affected += bool(set(existing,block))
|
||||
)
|
||||
);
|
||||
|
||||
affected(player());
|
||||
print(player,format('gi Filled ' + affected + ' blocks'));
|
||||
);
|
||||
@@ -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)
|
||||
);
|
||||
Reference in new issue
Block a user