def torus(name=None, **kwargs): """ Make a torus in the x-y plane torus('mytorus', u=6, v=32, r=1, t=0.3) u = number of subdivisions in a saggital section (small circle) v = number of subdivisions in the horizontal section (big circle) r = radius of the doughnut t = thickness (radius) th = degrees to rotate the small circle """ names, kwargs = utils.clean_names(name, kwargs, {'msh_name':'torus', 'obj_name':'torus', 'priority_msh':'current', 'priority_obj':'new'}) kwargs_def = {'n_u':16, 'r_u':0.3, 'n_v':32, 'r_v':1, 'theta_offset_deg':'auto'} kwargs_alias = {'n_u':['n_u', 'u'], 'r_u':['r_u', 't', 'thickness'], 'n_v':['n_v', 'v'], 'r_v':['r_v', 'r'], 'theta_offset_deg':['theta_offset_deg', 'th', 'offset', 'th_off_deg', 'th_u']} kwargs, _ = pn.clean_kwargs(kwargs, kwargs_def, kwargs_alias) a = turtle.Draw(**names) start = a.ngon(n=kwargs['n_u'], r=kwargs['r_u'], th_off_deg=kwargs['theta_offset_deg']) bmesh.ops.rotate(a.bm, verts=start.v, cent=(0, 0, 0), matrix=mathutils.Matrix.Rotation(np.radians(90.0), 3, 'Y')) for vert in start.v: vert.co += mathutils.Vector((0., -kwargs['r_v'], 0.)) end = a.spin(angle=2*np.pi-2*np.pi/kwargs['n_v'], steps=kwargs['n_v']-1, axis='z', cent=(0., 0., 0.)) a.join(start.e + end.e) tor = +a return tor
def draw_spring(): """Illustrates how to skin a curve using the Draw class.""" θ = np.radians(np.arange(0, 360 * 6 + 40, 40)) z1 = np.sin(θ) y1 = np.cos(θ) x1 = θ / 2 spine = np.array( [np.array((tx, ty, tz)) for tx, ty, tz in zip(x1, y1, z1)]) a = turtle.Draw('testskin') a.skin(spine, n=4, r=0.3) return +a
def draw_basic(): """Draw a loopy thing.""" a = turtle.Draw('link') bmesh.ops.create_circle(a.bm, radius=0.2, segments=6) for vert in a.bm.verts[:]: vert.co += mathutils.Vector((0., -1., 0)) a.spin(angle=np.pi, steps=3, axis='x', cent=(0., 0., 0.)) for i in range(5): a.spin(angle=np.pi, steps=3, axis=(1., 1.0 - 2.0 * (i % 2), 0), cent=(2 * i + 1.0, 0., 0)) return +a
def __init__(self, name=None, x=0, y=0, z=0, **kwargs): names, kwargs = utils.clean_names(name, kwargs, {'msh_name':'tube_msh', 'obj_name':'tube_obj', 'priority_obj':'new', 'priority_msh':'new'}) kwargs_ngon, _ = pn.clean_kwargs(kwargs, {'n':6, 'r':0.3, 'theta_offset_deg':-1}, {'n':['segments', 'seg', 'u', 'n'], 'r':['radius', 'r'], 'theta_offset_deg':['theta_offset_deg', 'th', 'offset', 'th_off_deg']}) spine = np.array([np.array((tx, ty, tz)) for tx, ty, tz in zip(x, y, z)]) normals = np.vstack((spine[1, :] - spine[0, :], spine[2:, :] - spine[:-2, :], spine[-1, :] - spine[-2, :])) a = turtle.Draw(**names) a.skin(spine, **kwargs_ngon) a_exp = a.export() this_obj = +a super().__init__(this_obj.name, this_obj.data) self.xsec = self.XSec(self, normals, a_exp)
def draw_link(n_u=6, n_v=16, l=1, r_v=1, r_u=0.2): """Draw one link of the chain. Same as the example in bmesh.ops page""" a = turtle.Draw('link') u_start = a.ngon(n=n_u, r=r_u) for vert in u_start.v: vert.co += mathutils.Vector((0., -r_v, 0)) u_end = a.spin(angle=np.pi, steps=n_v, axis='x', cent=(0., 0., 0.)) n_start = a.extrude(u_end.e) for vert in n_start.v: vert.co += mathutils.Vector((0, 0, l)) n_end = a.spin(angle=np.pi, steps=n_v, axis='x', cent=(0., 0., l)) a.join(u_start.e + n_end.e) return +a
def draw_atom(): """Electron clouds-like structure.""" a = turtle.Draw('cloud', coll_name='atom') a.ngon(n=2, r=0.1) for vert in a.bm.verts[:]: vert.co += mathutils.Vector((0., -1., 0)) a.spin(angle=np.pi, steps=24, axis='x', cent=(0., 0., 0.)) a.spin(angle=2 * np.pi, steps=6, axis='y', cent=(0., 0., 0.), geom=turtle.Geom(a.bm).all, use_duplicate=True) cloud = +a cloud.scale((1, 0.6, 1)) nucleus = new.sphere('nucleus', r=0.2, coll_name='atom') return (nucleus, cloud)