def makeHandActor(self, f=1): a1, a2, a3, c = (10 * f, 0, 0), (0, 7 * f, 0), (0, 0, 3 * f), (.7, 0.3, 0.3) palm = Ellipsoid(pos=(0, -3, 0), axis1=a1, axis2=a2, axis3=a3, alpha=0.6, c=c) wrist = Box(pos=(0, -9, 0), length=6 * f, width=5, height=2, alpha=0.4, c=c) arm = Assembly([palm, wrist]) f1 = Cylinder((-2, 1.5, 0), axis=(0, 1, 0), height=5, r=.8 * f, c=c) f2 = Cylinder((-1, 3, 0), axis=(0, 1, 0), height=6, r=.7 * f, c=c) f3 = Cylinder((0, 4, 0), axis=(0, 1, 0), height=6.2, r=.75 * f, c=c) f4 = Cylinder((1, 3.5, 0), axis=(0, 1, 0), height=6.1, r=.7 * f, c=c) f5 = Cylinder((2, 2, 0), axis=(0, 1, 0), height=5, r=.6 * f, c=c) self.vp += [arm, f1, f2, f3, f4, f5] # add actors to internal list return [arm, f1, f2, f3, f4, f5]
def demo3d_hanoi(**kwargs): nr_disks = kwargs.get("nr_disks", 5) interactive = kwargs.get("interactive", 1) hanoi = Hanoi(nr_disks) tower_states = list([hanoi.towers]) for _ in hanoi.moves(): tower_states.append(hanoi.towers) vp = Plotter(axes=0, interactive=0, bg="w", size=(800, 600)) vp.camera.SetPosition([18.5, -20.7, 7.93]) vp.camera.SetFocalPoint([3.0, 0.0, 2.5]) vp.camera.SetViewUp([-0.1, +0.17, 0.977]) cols = makePalette("red", "blue", hanoi.nr_disks + 1, hsv=True) disks = { hanoi.nr_disks - i: Cylinder(pos=[0, 0, 0], r=0.2 * (hanoi.nr_disks - i + 1), c=cols[i]) for i in range(hanoi.nr_disks) } for k in disks: vp += disks[k] vp += Box(pos=(3.0, 0, -.5), length=12.0, width=4.0, height=0.1) vp.show(zoom=1.2) printc("\n Press q to continue, Esc to exit. ", c="y", invert=1) pb = ProgressBar(0, len(tower_states), 1, c="b", ETA=False) for t in pb.range(): pb.print() state = tower_states[t] for tower_nr in range(3): for i, disk in enumerate(state[tower_nr]): disks[disk].pos([3 * tower_nr, 0, i + 0.5]) vp.show(resetcam=0, interactive=interactive, rate=10) vp.show(resetcam=0, interactive=1)
def root_box(scene): """ Creates a transparent box around the root mesh of a brainrender region. This forces the camera to stay in place even if ther root mesh is changed (e.g. sliced) """ pos = scene.root.centerOfMass() bounds = scene.root.bounds() bds = [ bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4], ] scene.add( Box( pos=[pos[0] - 1300, pos[1] - 500, pos[2]], length=bds[0], width=bds[1], height=bds[2], ).alpha(0), names="box", br_classes="box", )
Dt = 0.03 # time step # Create the initial positions and velocitites (0,0) of the bobs bob_x = [0] bob_y = [0] x_dot = np.zeros(N + 1) # velocities y_dot = np.zeros(N + 1) for k in range(1, N + 1): alpha = np.pi / 5 * k / 10 bob_x.append(bob_x[k - 1] + np.cos(alpha) + np.random.normal(0, 0.1)) bob_y.append(bob_y[k - 1] + np.sin(alpha) + np.random.normal(0, 0.1)) # Create the bobs plt = Plotter(title="Multiple Pendulum", axes=0, interactive=0, bg2='ly') plt += Box(pos=(0, -5, 0), length=12, width=12, height=0.7, c="k").wireframe(1) sph = Sphere(pos=(bob_x[0], bob_y[0], 0), r=R / 2, c="gray") plt += sph bob = [sph] for k in range(1, N + 1): c = Cylinder(pos=(bob_x[k], bob_y[k], 0), r=R, height=0.3, c=k) plt += c bob.append(c) # Create the springs out of N links link = [None] * N for k in range(N): p0 = bob[k].pos() p1 = bob[k + 1].pos() link[k] = Spring(p0, p1, thickness=0.015, r=R / 3, c="gray") plt += link[k]
for t_interval in range(int(T / output_int)): for it in range(output_int): t = t_interval * output_int + it #print('\r', "t=", t, end='') #print("t=", t) take_step(d_X, N) print('\r', "t=", t, end='') out_X = d_X.copy_to_host() pol = arr_pol_to_float3(out_X[:, 3:5]) coords_t.append(out_X[:, :3]) pol_t.append(pol) #print('\r', "DONE", t, end='') ####################################################################### from vedo import Box, Spheres, Arrows, show, interactive world = Box(pos=(1, 1, 0), size=(10, 10, 4), alpha=1).wireframe() for t in range(len(coords_t)): cells = Spheres(coords_t[t], c='b', r=0.4) polarities = Arrows(startPoints=coords_t[t], endPoints=coords_t[t] + pol_t[t], c='tomato') show(world, cells, polarities, interactive=0, viewup='z') interactive()
nr_disks = 5 hanoi = Hanoi(nr_disks) tower_states = list([hanoi.towers]) for _ in hanoi.moves(): tower_states.append(hanoi.towers) disks = { hanoi.nr_disks - i: Cylinder(r=0.2 * (hanoi.nr_disks - i + 1), c=i) for i in range(hanoi.nr_disks) } plt = Plotter(interactive=False, size=(800, 600), bg='wheat', bg2='lb') plt += disks.values() plt += Box(pos=(3, 0, -0.5), size=(12, 4, 0.1)) cam = dict( pos=(14.60, -20.56, 7.680), focalPoint=(3.067, 0.5583, 1.910), viewup=(-0.1043, 0.2088, 0.9724), ) plt.show(camera=cam) pb = ProgressBar(0, len(tower_states), 1, c="y") for t in pb.range(): pb.print() state = tower_states[t] for tower_nr in range(3): for i, disk in enumerate(state[tower_nr]): disks[disk].pos([3 * tower_nr, 0, i + 0.5]) plt.render()
"""Customizing axes style (40+ control parameters!) Title font: """ from vedo import Box, Lines, Points, Spline, show, settings settings.defaultFont = 'Theemim' # an invisible box: world = Box(pos=(2.7, 0, 0), size=(12, 10, 8), alpha=0) # a dummy spline with its shadow on the xy plane pts = Points([(-2, -3.2, -1.5), (3, -1.2, -2), (7, 3, 4)], r=12) spl = Spline(pts, res=50).addShadow(z=-4) # make spline and add its shadow at z=-4 lns = Lines(spl, spl.shadow) # join spline points with its own shadow # make a dictionary of axes options axes_opts = dict( xtitle= 'My variable \Omega^\lowerxi_lm in units of \mum^3', # latex-style syntax ytitle='This is my highly\ncustomized y-axis', ztitle= 'z in units of Å', # many unicode chars are supported (type: vedo -r fonts) yValuesAndLabels=[(-3.2, 'Mark^a_-3.2'), (-1.2, 'Carmen^b_-1.2'), (3, 'John^c_3')], textScale=1.3, # make all text 30% bigger numberOfDivisions=5, # approximate number of divisions on longest axis axesLineWidth=2, gridLineWidth=1, zxGrid2=True, # show zx plane on opposite side of the bounding box yzGrid2=True, # show yz plane on opposite side of the bounding box
def build_keyboard(self): nts = ("C", "D", "E", "F", "G", "A", "B") tol = 0.12 keybsize = 16.5 # in cm, span of one octave wb = keybsize / 7 nr_octaves = 7 span = nr_octaves * wb * 7 self.vp = Plotter(title='PianoPlayer ' + __version__, axes=0, size=(1400, 700), bg='cornsilk', bg2='lb') #wooden top and base self.vp += Box(pos=(span / 2 + keybsize, 6, 1), length=span + 1, height=3, width=5).texture('wood1') self.vp += Box(pos=(span / 2 + keybsize, 0, -1), length=span + 1, height=1, width=17).texture('wood1') self.vp += Text('PianoPlayer ^' + __version__ + " ", pos=(18, 5., 2.3), depth=.5, c='silver', italic=0.8) leggio = Box(pos=(span / 1.55, 8, 10), length=span / 2, height=span / 8, width=0.08, c=(1, 1, 0.9)).rotateX(-20) self.vp += leggio.texture('paper1') self.vp += Text('Playing:\n' + self.songname[-30:].replace('_', "\\_"), font="Theemim", vspacing=3, depth=0.04, s=1.35, c='k', italic=0.5).rotateX(70).pos([55, 10, 6]) for ioct in range(nr_octaves): for ik in range(7): #white keys x = ik * wb + (ioct + 1) * keybsize + wb / 2 tb = Box(pos=(x, -2, 0), length=wb - tol, height=1, width=12, c='white') self.KB.update({nts[ik] + str(ioct + 1): tb}) self.vp += tb if not nts[ik] in ("E", "B"): #black keys tn = Box(pos=(x + wb / 2, 0, 1), length=wb * .6, height=1, width=8, c='black') self.KB.update({nts[ik] + "#" + str(ioct + 1): tn}) self.vp += tn cam = dict(pos=(110, -51.1, 89.1), focalPoint=(81.5, 0.531, 2.82), viewup=(-0.163, 0.822, 0.546), distance=105, clippingRange=(41.4, 179)) self.vp.show(interactive=0, camera=cam, resetcam=0)
def __init__(self, bb_center, length, width, height): self.bb_center = bb_center self.length = length self.width = width self.height = height self.world = Box(bb_center, length, width, height).wireframe()
"""Customizing axes style (30 control parameters)""" from vedo import Box, show #an invisible box: box = Box(pos=(2.4, 0, 0), length=12, width=10, height=8).alpha(0) # make a dictionary of axes options axes_opts = dict( xtitle='Some long variable description [a.u.]', ytitle='This is my \ncustomized y-axis', ztitle='z values go here!', yPositionsAndLabels=[(-3.2, 'Mark'), (-1.2, 'Antony'), (3, 'John')], numberOfDivisions=5, # approx number of divisions on longest axis axesLineWidth=2, gridLineWidth=1, reorientShortTitle=True, xOriginMarkerSize=0.02, yOriginMarkerSize=None, titleDepth=0, # extrusion fractional depth of title text xyGrid=True, # show a gridded wall on plane xy yzGrid=True, zxGrid=False, zxGrid2=True, # show zx plane on opposite side of the bounding box xyPlaneColor='green', xyGridColor='darkgreen', # line color xyAlpha=0.2, # plane opacity showTicks=True, # show major ticks xTitlePosition=0.5, # title fractional positions along axis xTitleOffset=0.02, # title fractional offset distance from axis line xTitleJustify="top-center", xTitleRotation=20,
"""Customizing axes style (40+ control parameters!) Axes font: """ from vedo import Box, show, settings settings.defaultFont = 'Theemim' #an invisible box: box = Box(pos=(2.7,0,0), length=12, width=10, height=8, alpha=0) # make a dictionary of axes options axes_opts = dict( xtitle='My variable \Sigma^\lowerxi_lm in units of \mum^3', ytitle='This is my \ncustomized y-axis', ztitle='z values go here!', yPositionsAndLabels= [(-3.2,'Mark'), (-1.2,'Carmen'), (3,'John')], textScale=1.2, # make text 20% bigger numberOfDivisions=5, # approx number of divisions on longest axis axesLineWidth= 2, gridLineWidth= 1, xOriginMarkerSize=0.02, yOriginMarkerSize=None, titleDepth=0.1, # extrusion fractional depth of title text xyGrid=True, # show a gridded wall on plane xy yzGrid=True, zxGrid=False, zxGrid2=True, # show zx plane on opposite side of the bounding box xyPlaneColor='green', xyGridColor='darkgreen', # line color xyAlpha=0.2, # plane opacity