コード例 #1
0
ファイル: assignment2b.py プロジェクト: wouterzeevat/thema2
def frame(step):
    """ Creates a frame of 4 cones, 4 boxes, 1 sphere and a legend """

    # Define textures for different models
    sphere_model = Texture(Pigment('color', [1, 0, 1], ), Finish('reflection', 0.5))
    box_model = Texture(Pigment('color', [0, 1, 1], ), Finish('reflection', 0))
    cone_model = Texture(Pigment('color', [1, 0, 1], ), Finish('reflection', 0))

    # Create objects
    sphere = Sphere([0, 0, 0], 3, sphere_model)

    box_1 = Box([-5, -5, -4], [-3, 5, 4], box_model)
    box_2 = Box([3, -5, -4], [5, 5, 4], box_model)
    box_3 = Box([-5, 4, -4], [5, 6, 4], box_model)
    box_4 = Box([-5, -5, -4], [5, -3, 4], box_model)

    cone_1 = Cone([0, 6, 0], 3, [0, 10, 0], 0, cone_model)
    cone_2 = Cone([0, -6, 0], 3, [0, -10, 0], 0, cone_model)
    cone_3 = Cone([-5, 0, 0], 3, [-9, 0, 0], 0, cone_model)
    cone_4 = Cone([5, 0, 0], 3, [9, 0, 0], 0, cone_model)

    light_1 = LightSource([0, 10, -25], 'color', [1, 1, 1])
    light_2 = LightSource([0, 8, -7], 'color', [1, 1, 1])

    xyz_legend = legend([-15, 0, 0], 5)

    camera = Camera('location', [0, 7, -30], 'look_at', [0, 2, 1])

    # Return the Scene object for rendering
    return Scene(camera,
                 objects=[sphere, box_1, box_2, box_3, box_4,
                          cone_1, cone_2, cone_3, cone_4, light_1, light_2] + xyz_legend)
コード例 #2
0
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)
コード例 #3
0
def create_second_part_of_animation(frame_number,
                                    thirty_percent_of_total_frames,
                                    fifty_percent_of_total_frames):
    """
    In this function the whole RNA molecule is placed in the center of the scene and
    a sphere is moved over the molecule as a vesicle.
    """
    # Determine total frames of the second part of the animation
    total_frames_second_part = fifty_percent_of_total_frames - thirty_percent_of_total_frames

    # Determine in which step of the second part we are, starting with zero
    step_in_part = frame_number - (thirty_percent_of_total_frames + 1)

    # Place whole RNA molecule in the center of the scene
    RNA_1.move_to([0, 0, 0])

    # Determine the starting and ending x-coordinate of the vesicle
    x_start = 100
    x_end = 0

    # Calculating the distance per frame that the vesicle has to cover
    distance_x = x_end - x_start
    distance_per_frame_x = (distance_x / total_frames_second_part)

    # Calculating the x and y coordinates per frame according to the sine function
    x_coord = x_start + step_in_part * distance_per_frame_x
    y_coord = 2 * sin(x_coord / 5)

    # Making the vesicle with a sphere and placing it at the created x and y coordinates
    vesicle = Sphere([x_coord, y_coord, 0], 20, VESICLE_TEXTURE)

    return [vesicle]
コード例 #4
0
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)
コード例 #5
0
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)
コード例 #6
0
def frame(step):
    """ Returns a scene at a step number in which a sphere is visualised. """
    # 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)

    # Calculate the frames per wave
    repeats = 5
    n_frames_wave = n_frames / repeats  # amount of frames per wave

    # Calculates starting coordinates of the sphere
    increase = 4  # amount of increase per wave
    x_start = -10
    x_end = x_start + increase
    y_start = -4
    y_end = 4

    # Calculates total distance and distance per frame
    x_distance = x_end - x_start
    y_distance = y_end - y_start
    x_distance_per_frame = (x_distance / (n_frames_wave / 2))
    y_distance_per_frame = (y_distance / (n_frames_wave / 2))

    # Determine in which wave this step is
    if step // n_frames_wave == 0:
        wave = 0
    else:
        wave = step // n_frames_wave

    # Step has to reset for every wave, so subtract frames of previous wave(s)
    frame_in_wave = step - (wave * n_frames_wave)

    # If it is in the first part of the wave
    if frame_in_wave <= (n_frames_wave / 2):
        x_coord = x_start + (
            wave * increase
        ) + frame_in_wave * x_distance_per_frame  # Increases linear
        y_coord = y_start + frame_in_wave * y_distance_per_frame  # Increases linear
    # Second part of the wave
    else:
        x_coord = x_end + (wave * increase
                           )  # Stays constant and increases 4 for every wave
        y_coord = y_end - (
            frame_in_wave -
            (n_frames_wave / 2)) * y_distance_per_frame  # Decreases linear

    # Makes a sphere at given x- and Y-coordinates with the default style
    sphere = Sphere([x_coord, y_coord, 0], 0.5, models.default_sphere_model)

    # Returns the objects of the scene using the default camera settings
    return Scene(models.default_camera,
                 objects=[sphere, models.default_ground, models.default_light])
コード例 #7
0
def sphere_circle():
    """ Creates a circle made up of 20 small spheres.
        A list of Sphere objects is returnded ready for rendering. """
    spheres = 20  # number of spheres to create
    ring = []
    ring_node_size = 0.6
    smodel = Texture(Pigment('color', [1, 0, 0], 'filter', 0.5),
                     Finish('phong', 0.8, 'reflection', 0.5))
    for i in range(spheres):
        ring.append(Sphere([0, 0, 0], ring_node_size, smodel,
                           'translate', [RADIUS, 0, 0],
                           'rotate', [0, 360/spheres * i, 0]))
    return ring
コード例 #8
0
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'])