def make_frame(t):
    # Specify width/height as in example 5
    width = 320
    height = 240

    # now create a camera and a view like in example 5:
    camera = PerspectiveCamera(width, height, 45)
    camera.setView(Vec3(0.,-10.,10.), Vec3(0.,0.,0.), Vec3(0.,0.,1.))

    # Create a scene
    scene = Scene()

    # Add a light to the scene
    radius = 3.0
    p = 2*pi/4
    x = radius * cos(t*p)
    y = radius * sin(t*p)

    scene.addLight(PointLight(Vec3(x, y, 10)))


    # create some materials:
    floormaterial = PhongMaterial(color=Vec3(0.5,0.5,0.5))
    sphere0material = PhongMaterial(color=Vec3(1.,0.,0.))
    sphere1material = PhongMaterial(color=Vec3(0.,1.,0.))
    sphere2material = PhongMaterial(color=Vec3(0.,0.,1.))
    sphere3material = PhongMaterial(color=Vec3(1.,1.,0.))

    # Add "floor"

    A = Vertex(position=(-5.0, -5.0, 0.0))
    B = Vertex(position=( 5.0, -5.0, 0.0))
    C = Vertex(position=( 5.0,  5.0, 0.0))
    D = Vertex(position=(-5.0,  5.0, 0.0))

    scene.add(Triangle(A,B,C, material=floormaterial))
    scene.add(Triangle(A,C,D, material=floormaterial))

    # Add some spheres

    scene.add(Sphere(center=Vec3(-2.5,-2.5,1.75), radius=1.75, material=sphere0material))
    scene.add(Sphere(center=Vec3( 2.5,-2.5,1.75), radius=1.75, material=sphere1material))
    scene.add(Sphere(center=Vec3( 2.5, 2.5,1.75), radius=1.75, material=sphere2material))
    scene.add(Sphere(center=Vec3(-2.5, 2.5,1.75), radius=1.75, material=sphere3material))

    # Now tell the scene which camera we use
    scene.setCamera(camera)

    # Create a raytracer using "SimpleRT"
    engine = SimpleRT(shadow=True)

    # Render the scene:
    image = engine.render(scene)
    return image.data
Example #2
0
def render(ents):
    """entities is dictionary built in obj_parser.parse() representing objects in scene"""
    #create scene and add objects to scene
    scene=Scene()
    for obj in ents['objects']:
        if isinstance(obj,list):
            for o in obj:
                scene.add(o)
        else:
            scene.add(obj)
    if ents['light'] is None:
        ents['light']=PointLight(Vec3(-1,-8,1))
    scene.addLight(ents['light'])
    scene.setCamera(ents['camera'])
    engine=SimpleRT(shadow=True,iterations=3)
    image=engine.render(scene)
 
    return image
Example #3
0
from PIL import Image

# Specify width/height as in example 5
width = 320
height = 240

# now create a camera and a view like in example 5:
camera = PerspectiveCamera(width, height, 60)
camera.setView(Vec3(0,-10,0), Vec3(0,0,0), Vec3(0,0,1))

# Create a scene
scene = Scene()

# Add a light to the scene
scene.addLight(PointLight(Vec3(-1,-8,1)))

# Add a sphere to the scene:
scene.add(Sphere(center=Vec3(0.,0.,0.), radius=3., material=PhongMaterial(color=Vec3(1.,0.,0.))))

# Now tell the scene which camera we use
scene.setCamera(camera)

# Create a raytracer using "SimpleRT"
engine = SimpleRT()

# Render the scene:
image = engine.render(scene)

# Save the resulting image using pillow
image.save("11.png")
Example #4
0
width = 320
height = 240

# now create a camera and a view like in example 5:
camera = PerspectiveCamera(width, height, 60)
camera.setView(Vec3(0, -10, 0), Vec3(0, 0, 0), Vec3(0, 0, 1))

# Create a scene
scene = Scene()

# Add a light to the scene
scene.addLight(PointLight(Vec3(-1, -8, 1)))

# Add a sphere to the scene:
scene.add(
    Sphere(center=Vec3(0., 0., 0.),
           radius=3.,
           material=PhongMaterial(color=Vec3(1., 0., 0.))))

# Now tell the scene which camera we use
scene.setCamera(camera)

# Create a raytracer using "SimpleRT"
engine = SimpleRT()

# Render the scene:
image = engine.render(scene)

# Save the resulting image using pillow
image.save("11.png")
Example #5
0
def make_frame(t):
    # Specify width/height as in example 5
    width = 320
    height = 240

    # now create a camera and a view like in example 5:
    camera = PerspectiveCamera(width, height, 45)
    camera.setView(Vec3(0., -10., 10.), Vec3(0., 0., 0.), Vec3(0., 0., 1.))

    # Create a scene
    scene = Scene()

    # Add a light to the scene
    radius = 3.0
    p = 2 * pi / 4
    x = radius * cos(t * p)
    y = radius * sin(t * p)

    scene.addLight(PointLight(Vec3(x, y, 10)))

    # create some materials:
    floormaterial = PhongMaterial(color=Vec3(0.5, 0.5, 0.5))
    sphere0material = PhongMaterial(color=Vec3(1., 0., 0.))
    sphere1material = PhongMaterial(color=Vec3(0., 1., 0.))
    sphere2material = PhongMaterial(color=Vec3(0., 0., 1.))
    sphere3material = PhongMaterial(color=Vec3(1., 1., 0.))

    # Add "floor"

    A = Vertex(position=(-5.0, -5.0, 0.0))
    B = Vertex(position=(5.0, -5.0, 0.0))
    C = Vertex(position=(5.0, 5.0, 0.0))
    D = Vertex(position=(-5.0, 5.0, 0.0))

    scene.add(Triangle(A, B, C, material=floormaterial))
    scene.add(Triangle(A, C, D, material=floormaterial))

    # Add some spheres

    scene.add(
        Sphere(center=Vec3(-2.5, -2.5, 1.75),
               radius=1.75,
               material=sphere0material))
    scene.add(
        Sphere(center=Vec3(2.5, -2.5, 1.75),
               radius=1.75,
               material=sphere1material))
    scene.add(
        Sphere(center=Vec3(2.5, 2.5, 1.75),
               radius=1.75,
               material=sphere2material))
    scene.add(
        Sphere(center=Vec3(-2.5, 2.5, 1.75),
               radius=1.75,
               material=sphere3material))

    # Now tell the scene which camera we use
    scene.setCamera(camera)

    # Create a raytracer using "SimpleRT"
    engine = SimpleRT(shadow=True)

    # Render the scene:
    image = engine.render(scene)
    return image.data