def legend(start_position, axis_length): """ Legend function for calling importable legend""" # Reduce the AXIS_LENGTH by the length of the Cone (1) so that # the total length is exactly the AXIS_LENGTH axis_length -= 1 # Initialize the Cylinder END-position to a COPY of the start position cylinder_coords_end = { 'x': list(start_position), 'y': list(start_position), 'z': list(start_position) } # Add the AXIS_LENGTHs to the corresponding coordinate cylinder_coords_end['x'][0] += axis_length cylinder_coords_end['y'][1] += axis_length cylinder_coords_end['z'][2] += axis_length # creation of the Cylinders style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) linex = Cylinder(start_position, cylinder_coords_end['x'], 0.1, style) liney = Cylinder(start_position, cylinder_coords_end['y'], 0.1, style) linez = Cylinder(start_position, cylinder_coords_end['z'], 0.1, style) cylinders = {'x': linex, 'y': liney, 'z': linez} # Cone START is the same as the Cylinder END, so we COPY these lists cones_coords_start = { 'x': list(cylinder_coords_end['x']), 'y': list(cylinder_coords_end['y']), 'z': list(cylinder_coords_end['z']) } # Copy the START as END coordinate cones_coords_end = { 'x': list(cones_coords_start['x']), 'y': list(cones_coords_start['y']), 'z': list(cones_coords_start['z']) } # Extend the tip of the cones with length 1 cones_coords_end['x'][0] += 1 cones_coords_end['y'][1] += 1 cones_coords_end['z'][2] += 1 # Creation of the Cones conex = Cone(cones_coords_start['x'], 0.5, cones_coords_end['x'], 0, style) coney = Cone(cones_coords_start['y'], 0.5, cones_coords_end['y'], 0, style) conez = Cone(cones_coords_start['z'], 0.5, cones_coords_end['z'], 0, style) cones = {'x': conex, 'y': coney, 'z': conez} # Add ALL objects to a LIST and return legend_objects = list(cylinders.values()) + list(cones.values()) return legend_objects
def legend(loc, length): """ Creates a legend in a given location. Usage: legend([x, y, z], length) """ # Defining textures for each axis x_model = Texture(Pigment( 'color', [1, 0, 0], ), Finish('reflection', 0)) z_model = Texture(Pigment( 'color', [0, 0, 1], ), Finish('reflection', 0)) y_model = Texture(Pigment( 'color', [0, 1, 0], ), Finish('reflection', 0)) # Create objects x_cyl = Cylinder(loc, [loc[0] + length, loc[1], loc[2]], 0.1, x_model) x_cone = Cone([loc[0] + length, loc[1], loc[2]], 0.3, [loc[0] + length + 1, loc[1], loc[2]], 0, x_model) z_cyl = Cylinder(loc, [loc[0], loc[1], loc[2] + length], 0.1, y_model) z_cone = Cone([loc[0], loc[1], loc[2] + length], 0.3, [loc[0], loc[1], loc[2] + length + 1], 0, y_model) y_cyl = Cylinder(loc, [loc[0], loc[1] + length, loc[2]], 0.1, z_model) y_cone = Cone([loc[0], loc[1] + length, loc[2]], 0.3, [loc[0], loc[1] + length + 1, loc[2]], 0, z_model) return [x_cyl, x_cone, y_cyl, y_cone, z_cyl, z_cone]
def frame(step): """ Creates the objects and places this in a scene """ # Creates the lines in each directions x_cylinder = Cylinder([-15, 0, 0], [-10, 0, 0], 0.1, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))) y_cylinder = Cylinder([-15, 0, 0], [-15, 5, 0], 0.1, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))) z_cylinder = Cylinder([-15, 0, 0], [-15, 0, 5], 0.1, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))) # Creates the arrows of each directions x_cone = Cone([-10, 0, 0], 0.3, [-9, 0, 0], 0, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))) y_cone = Cone([-15, 5, 0], 0.3, [-15, 6, 0], 0, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))) z_cone = Cone([-15, 0, 5], 0.3, [-15, 0, 6], 0, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))) # Return the Scene object for rendering return Scene(models.default_camera, objects=[LightSource([2, 8, -20], 2), x_cylinder, y_cylinder, z_cylinder, x_cone, y_cone, z_cone])
def frame(step): curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) nframes = eval(SETTINGS.NumberFrames) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, style) sphere = Sphere([6, 2, -2], 3, style) leg = legend([-15, 0, 0], 5) radius = 25 z_start = -25 x_start = 0 alpha = (-pi / 2) + (step * 2 * pi / nframes) x_coord = radius * cos(alpha) z_coord = radius * sin(alpha) x = x_start + x_coord z = z_start - z_coord camera_x = 0 camera_z = -25 # x gaat links en rechts en z verder de diepte in en terug -25? camera = Camera('location', [camera_x, 8, camera_z], 'look_at', [0, 0, 0]) return Scene( camera, objects=[ cylinder, sphere, models.default_light, models.checkered_ground ] + shapes, included=['colors.inc'])
def frame(step): """ Returns the scene at step number (1 step per frame) """ curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) nframes = eval(SETTINGS.NumberFrames) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, style) sphere = Sphere([6, 2, -2], 3, style) leg = legend([-15, 0, 0], 5) radius = 25 z_start = 0 x_start = 0 alpha = (-pi / 2) + (step * 2 * pi / nframes) # For each step, de difference in the x and z positions is equal to the radius time the sin and cos of alpha. x_coord = radius * cos(alpha) z_coord = radius * sin(alpha) # Adding or subtracting the difference of the position for each step from the original camera position. x = x_start + x_coord z = z_start - z_coord return Scene( Camera('location', [x, 8, z], 'look_at', [0, 0, 0]), objects=[ models.checkered_ground, models.default_light, cylinder, sphere ] + leg)
def scene(step): ''' Returns the scene at step number (1 step per frame) ''' A = np.array([-10, 8, 0]) B = np.array([5, 2, -20]) # Find a point with distance 3 from A BA = B-A # Vector B->A d = math.sqrt(sum(np.power(BA, 2))) # distance BA = BA / d # Normalize by its length; BA / ||BA|| scale = 4 N = A + scale * BA # Scale and add to A l = Cylinder(A, B, 0.05, Pigment('color', [0, 1, 0])) s1 = Sphere(N, 0.5, Texture(Pigment('color', [0.9, 0.05, 0.05]))) scale = 15 N = A + scale * BA # Scale and add to A s2 = Sphere(N, 0.5, Texture(Pigment('color', [0.9, 0.05, 0.05]))) scale = 24 N = A + scale * BA # Scale and add to A s3 = Sphere(N, 0.5, Texture(Pigment('color', [0.9, 0.05, 0.05]))) return Scene(povray.floor_camera, objects=[povray.default_light, povray.checkered_ground, l, s1, s2, s3], included=['colors.inc'])
def frame(step): """ Creates a frame of a given frame (step) number. """ # Show some information about how far we are with rendering curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) # Getting the total number of frames, see the configuration file nframes = eval(SETTINGS.NumberFrames) # Calculates rotation positions angle_per_frame = math.pi * 2 / nframes # Calculates how much the angle needs to move per frame angle = angle_per_frame * step # Calculates the angle of the frame # Gets locations x = math.cos(angle) * 20 z = math.sin(angle) * 20 # Create objects sphere = Sphere([6, 2, -2], 3, models.default_sphere_model) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, models.default_sphere_model) legend_1 = legend([-15, 0, 0], 5) camera = Camera('location', [x, 8, z], 'look_at', [0, 0, 0]) # Return the Scene object containing all objects for rendering return Scene(camera, objects=[sphere, models.default_light, models.checkered_ground, cylinder] + legend_1)
def frame(step): """ Returns the scene at step number (1 step per frame) """ # Show some information about how far we are with rendering curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) # Getting the total number of frames, see the configuration file nframes = eval(SETTINGS.NumberFrames) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, style) sphere = Sphere([6, 2, -2], 3, style) leg = legend([-15, 0, 0], 5) radius = 25 z_start = 0 x_start = 0 #werkt allbei # alpha = (-pi/2) + (step * 2 * pi / nframes) alpha = pi / (nframes / 2) * step + 1 x_coord = radius * cos(alpha) z_coord = radius * sin(alpha) x = x_start + x_coord z = z_start - z_coord return Scene( Camera('location', [x, 8, z], 'look_at', [0, 0, 0]), objects=[ models.checkered_ground, models.default_light, cylinder, sphere ] + leg)
def make_objects(): global SPHERE, CYLINDER, LEGEND SPHERE = Sphere([6, 2, -2], 3, models.default_sphere_model) CYLINDER = Cylinder([-6, -1, 4], [-6, 7, 4], 3, models.default_sphere_model) LEGEND = legend([-15, 0, 0], 5)
def make_receptor(loc, size=5): """ Creates the receptor and returns the object """ rec_model = Texture(Pigment('color', [0, 1, 1], ), Finish('reflection', 0)) x = loc[0] y = loc[1] z = loc[2] rec = list() rec.append(Cylinder([x - size * 1.2, y - size * 15, z], [x - size * 1.2, y + size*2, z], size, rec_model)) rec.append(Cylinder([x + size * 1.2, y - size * 15, z], [x + size * 1.2, y + size*2, z], size, rec_model)) rec.append(Cylinder([x - size * 1.2, y + size * 1.2, z], [x - size * 5, y + size * 4, z], size, rec_model)) rec.append(Cylinder([x - size * 7.2, y + size * 4, z - size/2], [x - size * 3.2, y + size * 4, z - size/2], size / 1.321, rec_model)) rec.append(Cylinder([x + size * 1.2, y + size * 1.2, z], [x + size * 5, y + size * 4, z], size, rec_model)) rec.append(Cylinder([x + size * 7.2, y + size * 4, z - size/2], [x + size * 3.2, y + size * 4, z - size/2], size / 1.321, rec_model)) rec.append(Sphere([x, y - size * 6, z], size * 3, rec_model)) return rec
def make_membrane(loc, amount, size=5): """ Create the membrane and returns the object """ sphere_model = Texture(Pigment('color', [1, 0, 0], ), Finish('reflection', 0)) cyl_model = Texture(Pigment('color', [0.7, 0.3, 0], ), Finish('reflection', 0)) x_position = loc[0] y_position = loc[0] - size * 6 objects = [] for index in range(1, amount + 1): # Create top spheres objects.append(Sphere([x_position, loc[1], loc[2]], size, sphere_model)) objects.append(Sphere([0 - x_position, loc[1], loc[2]], size, sphere_model)) # Create top cylinders location = [x_position - size/3, loc[1], loc[2]], [x_position - size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [x_position + size/3, loc[1], loc[2]], [x_position + size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position - size/3, loc[1], loc[2]], [0-x_position - size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position + size/3, loc[1], loc[2]], [0-x_position + size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) # Create bottom spheres objects.append(Sphere([x_position, y_position, loc[2]], size, sphere_model)) objects.append(Sphere([0 - x_position, y_position, loc[2]], size, sphere_model)) # Create bottom cylinders location = [x_position - size/3, y_position, loc[2]], [x_position - size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [x_position + size/3, y_position, loc[2]], [x_position + size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position - size/3, y_position, loc[2]], [0-x_position - size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position + size/3, y_position, loc[2]], [0-x_position + size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) x_position += size * 2 return objects
def frame(step): lichtje = LightSource([2, 8, -5], 5.0) default_camera = Camera('location', [-5, 8, -20], 'look_at', [-5, 0, -5]) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) linex = Cylinder([-15, 0, 0], [-10, 0, 0.5],0.1, style) liney = Cylinder([-15, 0, 0], [-15, 5, 0.2],0.1, style) linez = Cylinder([-15, 0, 0], [-15, 0.2, 5],0.1, style) conex = Cone([-10, 0, 0.5], 0.5, [-9, 0, 0.5], 0, style) coney = Cone([-15, 5, 0], 0.5, [-15, 6, 0], 0, style) conez = Cone([-15, 0, 5], 0.5, [-15, 0, 6], 0, style) # Return the Scene object for rendering return Scene(default_camera, objects=[lichtje,linex,liney,linez,conex,coney,conez])
def scene(step): # Storing the cylinders cylinders = [] n = 7 for i in range(n): cylinders.append( Cylinder([0, 0, 0], [1.2, 0, 0], 1.0, 1.0, 'scale', [1, 0.25, 1], 'rotate', [-30, 0, 0], 'translate', [1.25, 0, 0], 'rotate', [0, i * 360 / n, 0], Texture('Chrome_Texture'), Pigment('color', [0.1, 0.1, 0.1]), Finish('phong', 1, 'reflection', 1))) # Reset color for the center sphere degrees = (360 / (SETTINGS.Duration * SETTINGS.RenderFPS)) * step prop = Blob( 'threshold', 0.65, # Add a Sphere with radius and strength = 1 Sphere( [0, 0, 0], 1.00, 1.00, # Double the heigth of the Sphere 'scale', [1, 2, 1], # Make it shine Texture('Chrome_Texture', Pigment('color', [0.1, 0.1, 0.1]), Finish('phong', 0.5, 'reflection', 0.5))), # unpack cylinders *cylinders, # Scale the whole objects (enlarge) 'scale', 1.8, # rotate counter-clockwise 'rotate', [90, 0, degrees], # re-center 'translate', [0, 0.5, 0]) camera = Camera('location', [5, 10, -8], 'look_at', [0, 0, 0]) xyz_legend = legend([-10, 0, 0], 3) return Scene( camera, objects=[prop] + xyz_legend + povray.default_spots, # The 'Chrome_Texture comes from the 'textures.inc' file included=['textures.inc'])
def make_tyrine(loc, size): """ Creates the tyrine molecules """ text_model = Texture(Pigment('color', [1, 1, 0], ), Finish('reflection', 0)) cyl_model = Texture(Pigment('color', [0, 1, 0.5], ), Finish('reflection', 0)) tyr = [] y_always = [13, 13, 10, 10] x_text = [-3, 5, -3, 5] x_end = [-5, 5, -5, 5] x = loc[0] y = loc[1] z = loc[2] + 7 for _ in range(4): tyr.append(Cylinder([x, y-size * y_always[_], z], [x-size*x_end[_], y-size*y_always[_], z], size, cyl_model)) text = Text('ttf', '"timrom.ttf"', '"{}"'.format(str('Tyr')), 2, [0, 0, 0], text_model, 'scale', 5, 'translate', [x-size*x_text[_], y-size*y_always[_], z - 7]) tyr.append(text) return tyr
def frame(step): """ Returns the scene at the given step """ # Show some information about how far we are with rendering curr_time = step * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) ## Rotating sphere, placed in the center sphere_rad = 1.8 sphere = Sphere([0, 0, 0], sphere_rad, Pigment('color', [0.9, 0.05, 0.05], 'filter', 0.7), Interior('ior', 1), Finish('phong', 0.6, 'reflection', 0.4)) # Intersecting cylinder object rod = Cylinder([0, 0, 3], [0, 0, -3], 1.0, 'open', Pigment('color', [1, 0, 0], 'filter', 0.8), Interior('ior', 1), Finish('phong', 0, 'reflection', 0)) # 'Hollow out' the rotating sphere with the intersecting cylinder using the Difference, # move to a spot on the circle (top) and rotate on the x-axis traveller = Difference(sphere, rod, 'translate', [RADIUS, 0, 0], 'rotate', [0, 360/eval(SETTINGS.NumberFrames)*step*2, 0]) return Scene(CAMERA, objects=[GROUND, MAIN_LIGHT, BACK_LIGHT, traveller] + RING)
def frame(step): """ Returns the scene at step number (1 step per frame) """ cylinder = Cylinder([-6, -1, 4], [-6, 8, 4], 4, models.default_sphere_model) sphere = Sphere([6, 2, -2], 3, models.default_sphere_model) xyz_legend = legend([-15, 0, 0], 5) # Show some information about how far we are with rendering curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) # Getting the total number of frames, see the configuration file nframes = eval(SETTINGS.NumberFrames) distance_per_frame = 50 / nframes z_start = -25 z_end = 25 if step < (nframes / 2): z = z_start + step * distance_per_frame x = math.sqrt(25**2 - z**2) else: z = z_end - step * distance_per_frame x = -1 * math.sqrt(25**2 - z**2) camera = Camera('location', [x, 8, z], 'look_at', [0, 0, 0]) # Return the Scene object containing all objects for rendering return Scene(camera, objects=[ sphere, cylinder, models.checkered_ground, models.default_light ])
def frame(step): """ Returns a scene at a step number while camera is moving. """ # Feedback to user in terminal about render status curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) # Calculates the total frames n_frames = eval(SETTINGS.NumberFrames) # Calculates coordinates for the camera position radius = 25 degrees = pi / (n_frames / 2) * (step + 1) x_coord = radius * sin(degrees) z_coord = radius * cos(degrees) # Makes objects at given coordinates sphere = Sphere([6, 2, -2], 3, models.default_sphere_model) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, models.default_sphere_model) xyz_legend = legend([-15, 0, 0], 5) # Returns the objects of the scene using the default camera settings return Scene(Camera('location', [x_coord, 8, z_coord], 'look_at', [0, 0, 0]), objects=[LightSource([2, 8, -20], 2), models.checkered_ground, sphere, cylinder] + xyz_legend)
def _render_structure(self, change=None): """Render the structure with POVRAY.""" if not isinstance(self.structure, Atoms): return self.render_btn.disabled = True omat = np.array(self._viewer._camera_orientation).reshape( 4, 4).transpose() zfactor = norm(omat[0, 0:3]) omat[0:3, 0:3] = omat[0:3, 0:3] / zfactor bb = deepcopy(self.structure) bb.pbc = (False, False, False) for i in bb: ixyz = omat[0:3, 0:3].dot(np.array([i.x, i.y, i.z]) + omat[0:3, 3]) i.x, i.y, i.z = -ixyz[0], ixyz[1], ixyz[2] vertices = [] cell = bb.get_cell() vertices.append(np.array([0, 0, 0])) vertices.extend(cell) vertices.extend([ cell[0] + cell[1], cell[0] + cell[2], cell[1] + cell[2], cell[0] + cell[1] + cell[2], ]) for n, i in enumerate(vertices): ixyz = omat[0:3, 0:3].dot(i + omat[0:3, 3]) vertices[n] = np.array([-ixyz[0], ixyz[1], ixyz[2]]) bonds = [] cutOff = neighborlist.natural_cutoffs( bb) # Takes the cutoffs from the ASE database neighborList = neighborlist.NeighborList(cutOff, self_interaction=False, bothways=False) neighborList.update(bb) matrix = neighborList.get_connectivity_matrix() for k in matrix.keys(): i = bb[k[0]] j = bb[k[1]] v1 = np.array([i.x, i.y, i.z]) v2 = np.array([j.x, j.y, j.z]) midi = v1 + (v2 - v1) * Radius[i.symbol] / (Radius[i.symbol] + Radius[j.symbol]) bond = Cylinder( v1, midi, 0.2, Pigment("color", np.array(Colors[i.symbol])), Finish("phong", 0.8, "reflection", 0.05), ) bonds.append(bond) bond = Cylinder( v2, midi, 0.2, Pigment("color", np.array(Colors[j.symbol])), Finish("phong", 0.8, "reflection", 0.05), ) bonds.append(bond) edges = [] for x, i in enumerate(vertices): for j in vertices[x + 1:]: if (norm(np.cross(i - j, vertices[1] - vertices[0])) < 0.001 or norm(np.cross(i - j, vertices[2] - vertices[0])) < 0.001 or norm(np.cross(i - j, vertices[3] - vertices[0])) < 0.001): edge = Cylinder( i, j, 0.06, Texture( Pigment("color", [212 / 255.0, 175 / 255.0, 55 / 255.0])), Finish("phong", 0.9, "reflection", 0.01), ) edges.append(edge) camera = Camera( "perspective", "location", [0, 0, -zfactor / 1.5], "look_at", [0.0, 0.0, 0.0], ) light = LightSource([0, 0, -100.0], "color", [1.5, 1.5, 1.5]) spheres = [ Sphere( [i.x, i.y, i.z], Radius[i.symbol], Texture(Pigment("color", np.array(Colors[i.symbol]))), Finish("phong", 0.9, "reflection", 0.05), ) for i in bb ] objects = ( [light] + spheres + edges + bonds + [Background("color", np.array(to_rgb(self._viewer.background)))]) scene = Scene(camera, objects=objects) fname = bb.get_chemical_formula() + ".png" scene.render( fname, width=2560, height=1440, antialiasing=0.000, quality=11, remove_temp=False, ) with open(fname, "rb") as raw: payload = base64.b64encode(raw.read()).decode() self._download(payload=payload, filename=fname) self.render_btn.disabled = False
def legend(start_position, axis_length): """ Returns the objects of a legend :param start_position: the position where the legend is rendered :param axis_length: the length of each line+arrow in the x, y and z direction :return legend_objects: the objects of a legend """ # Reduce the AXIS_LENGTH by the length of the Cone (1) so that # the total length is exactly the AXIS_LENGTH axis_length -= 1 # Initialize the Cylinder END-position to a COPY of the start position cylinder_coords_end = { 'x': list(start_position), 'y': list(start_position), 'z': list(start_position) } # Add the AXIS_LENGTHs to the corresponding coordinate cylinder_coords_end['x'][0] += axis_length cylinder_coords_end['y'][1] += axis_length cylinder_coords_end['z'][2] += axis_length ''' CREATE THE CYLINDERS''' cylinders = { 'x': Cylinder(start_position, cylinder_coords_end['x'], 0.1, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))), 'y': Cylinder(start_position, cylinder_coords_end['y'], 0.1, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))), 'z': Cylinder(start_position, cylinder_coords_end['z'], 0.1, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))) } # Cone START is the same as the Cylinder END, so we COPY these lists cones_coords_start = { 'x': list(cylinder_coords_end['x']), 'y': list(cylinder_coords_end['y']), 'z': list(cylinder_coords_end['z']) } # Copy the START as END coordinate cones_coords_end = { 'x': list(cones_coords_start['x']), 'y': list(cones_coords_start['y']), 'z': list(cones_coords_start['z']) } # Extend the tip of the cones with length 1 cones_coords_end['x'][0] += 1 cones_coords_end['y'][1] += 1 cones_coords_end['z'][2] += 1 ''' CREATE THE CONES ''' cones = { 'x': Cone(cones_coords_start['x'], 0.3, cones_coords_end['x'], 0, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))), 'y': Cone(cones_coords_start['y'], 0.3, cones_coords_end['y'], 0, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))), 'z': Cone(cones_coords_start['z'], 0.3, cones_coords_end['z'], 0, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))), } # Add ALL objects to a LIST and return legend_objects = list(cylinders.values()) + list(cones.values()) return legend_objects
def single_virus_gen(): """ single_virus_gen() Generates a virus object. :return virus object """ object_texture = Texture(Pigment('color', [1, 1, 1], 'transmit', 0), Finish('phong', 0.5, 'reflection', 0.9)) helix_test = 'f_helix1(x, y, z, 1, 1 * 4 * pi, 0.07, 0.8, 1, 0.3, 0)' iso_spine = Isosurface(Function(helix_test), ContainedBy(Box(-5, 5)), 'translate', [0, 0, 0], models.default_sphere_model) # spine helix cyl = Cylinder([0, -5, 0], [0, 5, 0], 0.5, object_texture) # spine cylinder icosahedral = 'abs(x)+abs(y)+abs(z)-4.9' ico_head = Isosurface(Function(icosahedral), ContainedBy(Box(-3.5, 3.5)), 'max_gradient', 5, 'translate', [0, 7, 0], object_texture) # head object ring = Torus(1.2, 0.3, 'translate', [0, -5, 0], object_texture) # hip ring spine # berelem radian, bijv: 1.05 * math.cos(radian * 3) 3 = step, 1.05 = straal radian = (360 / 6) * (math.pi / 180) x_tail_list = [] for coordinate_offset in range(1, 7, 2): coordinate_offset += 0.05 x_tail_list.append(coordinate_offset) # [1.05, 3.05, 5.05] x_axis_tail_list = [] z_axis_tail_list = [] for tail_nr in range(1, 7): tail_steps = tail_nr for coordinate in x_tail_list: x_axis_tail_list.append(coordinate * math.cos(radian * tail_steps)) z_axis_tail_list.append(coordinate * math.sin(radian * tail_steps)) tails = [] for tail_coordinate in range(0, len(x_axis_tail_list), 3): tails.append( SphereSweep('linear_spline', 3, [ x_axis_tail_list[tail_coordinate], -5.00, z_axis_tail_list[tail_coordinate] ], 0.1, [ x_axis_tail_list[tail_coordinate + 1], -1.00, z_axis_tail_list[tail_coordinate + 1] ], 0.15, [ x_axis_tail_list[tail_coordinate + 2], -9.00, z_axis_tail_list[tail_coordinate + 2] ], 0.1, object_texture)) # 6 tails virus_object = Merge(iso_spine, ico_head, ring, cyl) for tail in tails: virus_object.args.append(tail) return virus_object