objects.py
1.4 kB · python · 61 lines
1import mrlypy.two as m22import mrlypy.three as m33import numpy as np4from config import DATA_DIR56def tree_mask(n: int) -> np.ndarray:7 t1 = m3.tree_3d(n).types8 t2 = m3.tree_3d(n).rotate(1).types9 mask = np.zeros_like(t1, dtype=np.uint8)10 mask[(t1 == 1) | (t2 == 1)] = 111 mask[(t1 == 1) & (t2 == 1)] = 212 return mask1314def sponge():15 cell = m3.carpet_3d(5, 2)16 fp = f"{DATA_DIR}/sponge.obj"17 cell.save_obj(fp)18 print(f"Saved: {fp}")1920def carpet():21 cell = m2.random_2d(3, 3)22 cell = m3.Cell3d.from_2d(cell)23 cell.extrude(1)24 fp = f"{DATA_DIR}/carpet.obj"25 cell.save_obj(fp)26 print(f"Saved: {fp}")2728def magic():29 cell_1 = m3.random_3d(3, 1)30 cell_2 = m3.random_3d(3, 1)31 cell = m3.magic_3d([cell_1, cell_2])32 fp = f"{DATA_DIR}/magic.obj"33 cell.save_obj(fp)34 print(f"Saved: {fp}")3536def special():37 mask = m3.random_3d(3, 1).types38 cell = m3.special_3d(mask, m3.tree_3d(3, 1))39 fp = f"{DATA_DIR}/special.obj"40 cell.save_obj(fp)41 print(f"Saved: {fp}")4243def mosaic():44 mask = tree_mask(3)45 cell_1 = m3.random_3d(3, 1)46 cell_2 = m3.random_3d(3, 1)47 cell_3 = m3.random_3d(3, 1)48 cell = m3.mosaic_3d(mask, [cell_1, cell_2, cell_3])49 fp = f"{DATA_DIR}/mosaic.obj"50 cell.save_obj(fp)51 print(f"Saved: {fp}")5253def main():54 sponge()55 carpet()56 magic()57 special()58 mosaic()5960if __name__ == "__main__":61 main()