示例#1
0
    def build_flat_plane(self):
        scene = Scene(self.screen, self.camera_position, COLOUR_WHITE, self.scale)

        count = 1
        for x in range(count):
            for y in range(count):
                s = int(self.screen.width / count)
                cube_material = Material(
                    (0 + int(random.random() * 100), 150 + int(random.random() * 100), int(1 * random.random())),
                    # (0,0,255),
                    (0.5, 0.5, 0.5),
                    (0.8, 0.8, 0.8),
                    (0.5, 0.5, 0.5),
                    50
                )
                rectangle = Rectangle(
                    Point(x * s - self.screen.width/2, -self.screen.height / 2, self.screen.distance + y * s),
                    Point(x * s - self.screen.width/2, -self.screen.height / 2, self.screen.distance + (y+1) * s),
                    Point((x+1) * s - self.screen.width/2, -self.screen.height / 2, self.screen.distance + y * s),
                    cube_material
                )
                scene.add_object(rectangle)

        light_position = Point(-self.screen.width/4,-self.screen.height/2 + 50, self.screen.width * 4 + self.screen.distance)
        light = Light(light_position)
        scene.add_light(light)

        return scene
示例#2
0
def get_scene():
  scene = Scene((500, 500), Point(0, 0, 800), Vector(0, 0, -1), Vector(0, 1, 0), 45, (0.3, 0.3, 0.3))
  mat1 = Material((0.7, 1.0, 0.7), (0.5, 0.7, 0.5), 25, 0.25)
  mat2 = Material((0.5, 0.5, 0.5), (0.5, 0.7, 0.5), 25, 0.25)
  mat3 = Material((1.0, 0.6, 0.1), (0.5, 0.7, 0.5), 25, 0.25)
  mat4 = Material((0.7, 0.6, 1.0), (0.5, 0.4, 0.8), 25, 0.25)

  # s1
  scene.add_child(Sphere(Point(0, 0, -400), 100, mat1))
  # s2
  scene.add_child(Sphere(Point(200, 50, -100), 150, mat1))
  # s3
  scene.add_child(Sphere(Point(0, -1200, -500), 1000, mat2))
  # b1 (TODO)
  # s4
  scene.add_child(Sphere(Point(-100, 25, -300), 50, mat3))
  # s5
  scene.add_child(Sphere(Point(0, 100, -250), 25, mat1))

  # white light
  scene.add_light(Light(Point(-100, 150, 400), (0.9, 0.9, 0.9), (1, 0, 0)))
  # orange light
  scene.add_light(Light(Point(400, 100, 150), (0.7, 0.0, 0.7), (1, 0, 0)))
  return scene
示例#3
0
# cube.material = green_rubber
# scene.add_shape(cube)
# light = DirectionalLight(ambient=[0.2, 0.2, 0.2, 1],
#                   diffuse=[1, 1, 1, 1],
#                   specular=[1, 1, 1, 1],
#                   transform=Transform(position=Vec3d(0, 0, -5), rotation=Vec3d(0, 0, 0)))

light = SpotLight(ambient=[0.2, 0.2, 0.2, 1],
                  diffuse=[1, 1, 1, 1],
                  specular=[1, 1, 1, 1],
                  angle=30,
                  distance=20,
                  transform=Transform(position=Vec3d(0, 0, -5),
                                      rotation=Vec3d(0, 0, 0)))
scene.add_shape(light)
scene.add_light(light)

light2 = SpotLight(ambient=[0.2, 0.2, 0.2, 1],
                   diffuse=[1, 1, 1, 1],
                   specular=[1, 1, 1, 1],
                   angle=15,
                   distance=20,
                   transform=Transform(position=Vec3d(0, 10, 1),
                                       rotation=Vec3d(100, 0, 0)))
scene.add_shape(light2)
scene.add_light(light2)

# light2 = DirectionalLight(ambient=[0.2, 0.2, 0.2, 1],
#               diffuse=[1, 0, 0, 1],
#               specular=[1, 1, 1, 1],
#               transform=Transform(position=Vec3d(0, 0, 0), rotation=Vec3d(0, 0, 0)))
示例#4
0
#!/usr/bin/env python

from dispatcher import Dispatcher
from scene import Scene
from camera import Camera
from lights import *
from objects import *
from color import Color

width, height = 800, 600

scene = Scene(Camera((0, -80, 20), 60), (80, 60), (width, height))

scene.add_light(Ambiant(intensity=0.2))
scene.add_light(Diffuse(-20, -40, 20, intensity=0.8))
scene.add_light(Diffuse(40, 40, 5, intensity=0.4))
scene.add_light(Specular(-20, -40, 20, intensity=0.6))

scene.add_object(Sphere(10, x=50, y=30, scale_z=1.5, color=Color(r=255)))
scene.add_object(Sphere(3, z=20, scale_x=5, color=Color(g=255)))
scene.add_object(Sphere(5, color=Color(r=255, b=255)).stretch('x', angle_y=60))
scene.add_object(Plane(z=-10, color=Color(255, 255, 255)))
scene.add_object(Plane(z=80, color=Color(255, 255, 255)))
scene.add_object(Plane(x=-80, rot_y=90, color=Color(b=255)))
scene.add_object(Plane(x=80, rot_y=90, color=Color(b=255)))
scene.add_object(Plane(y=100, rot_x=90, color=Color(r=255, g=255)))
scene.add_object(Cylinder(5, x=-80, y=100, color=Color(b=255)))
scene.add_object(Cylinder(5, x=80, y=100, color=Color(b=255)))
scene.add_object(Cone(10, color=Color(r=128, g=128, b=128)))

nb_lines_chunk = 50
示例#5
0
light4 = Spotlight(np.array([2., 0.6, 1.4]),
                   np.array([random(), random(), random()]))
#white_light2 = Spotlight(np.array([0.,1.5,0.3]),np.array([1.,1.,1.]))
#white_light3 = Spotlight(np.array([-1.,0.5,0.]),np.array([1.,1.,1.]))
#red_light = Spotlight(np.array([0.,-1.5,1.]), np.array([1.,0.,0.]))
#green_light = Spotlight(np.array([-1.74,0.75,1.]), np.array([0.,1.,0.]))
#blue_light = Spotlight(np.array([1.74,0.75,1.]), np.array([0.,0.,1.]))

this_scene.add_object(sphere1)
this_scene.add_object(sphere2)
this_scene.add_object(sphere3)
this_scene.add_object(small_sphere1)
this_scene.add_object(small_sphere2)
this_scene.add_object(small_sphere3)

this_scene.add_light(white_light)
this_scene.add_light(light1)
this_scene.add_light(light2)
this_scene.add_light(light3)
this_scene.add_light(light4)
#this_scene.add_light(white_light2)
#this_scene.add_light(white_light3)
#this_scene.add_light(red_light)
#this_scene.add_light(green_light)
#this_scene.add_light(blue_light)

this_camera = Camera(2000, 2000, 1.35)

plt.imsave('random8.png', raytracer_render(this_camera, this_scene))
print('colors of spheres :\n{}\n{}\n{}'.format(sphere1.material.color,
                                               sphere2.material.color,
示例#6
0
        Point(3, -5, -4),
        2,
        Phong(
            Color.BLACK,
            Color.BLACK,
            Color.BLACK,
            50,
            transmittance=0.8,
            ior=1.5,
            reflect_bg=True
        )
    ),
]


for o in objects:
    scene.add(o)
for l in lights:
    scene.add_light(l)

result = scene.render()

img = Image.new('RGB', (scene.width, scene.height), tuple(scene.background))
pixels = img.load()

for u in range(img.size[0]):
    for v in range(img.size[1]):
        pixels[u, v] = tuple(result[v][u])

img.save('output.png')
示例#7
0
from scene import Scene
from sphere import Sphere
from material import Material
from light import Spotlight
from rayon import raytracer_render
from camera import Camera
import numpy as np
import matplotlib.pyplot as plt

this_scene = Scene()
some_material = Material(
    np.array([106., 102., 163.]) / 255, 0.5, 0.7, 0.1, 0.3, 0.4)
red_material = Material(
    np.array([255., 151., 112.]) / 255, 0.8, 0.4, 0.2, 0.4, 0.7)

light1 = Spotlight(np.array([1., 1., 0.]), np.array([252., 236., 201.]) / 255)
#red_light = Spotlight(np.array([-1,2,1]),np.array([1,1,0]))
#other_light = Spotlight(np.array([0,-1,1.5]),np.array([1,0,1]))
blue_sphere = Sphere(np.array([0., 0., 3.]), 0.8, some_material)
red_sphere = Sphere(np.array([0.4, 0.4, 1.8]), 0.1, red_material)

this_scene.add_object(blue_sphere)
this_scene.add_object(red_sphere)
this_scene.add_light(light1)
#this_scene.add_light(red_light)
#this_scene.add_light(other_light)

this_camera = Camera(1500, 1500, 2.2)

plt.imsave('shadow exemple.png', raytracer_render(this_camera, this_scene))
示例#8
0
#!/usr/bin/env python

from dispatcher import Dispatcher
from scene import Scene
from camera import Camera
from lights import *
from objects import *
from color import Color

width, height = 800, 600

scene = Scene(Camera((0, -80, 20), 60), (80, 60), (width, height))

scene.add_light(Ambiant(intensity=0.2))
scene.add_light(Diffuse(-20, -40, 20, intensity=0.8))
scene.add_light(Diffuse(40, 40, 5, intensity=0.4))
scene.add_light(Specular(-20, -40, 20, intensity=0.6))

scene.add_object(Sphere(10, x=50, y=30, scale_z=1.5, color=Color(r=255)))
scene.add_object(Sphere(3, z=20, scale_x=5, color=Color(g=255)))
scene.add_object(Sphere(5, color=Color(r=255, b=255)).stretch('x', angle_y=60))
scene.add_object(Plane(z=-10, color=Color(255, 255, 255)))
scene.add_object(Plane(z=80, color=Color(255, 255, 255)))
scene.add_object(Plane(x=-80, rot_y=90, color=Color(b=255)))
scene.add_object(Plane(x=80, rot_y=90, color=Color(b=255)))
scene.add_object(Plane(y=100, rot_x=90, color=Color(r=255, g=255)))
scene.add_object(Cylinder(5, x=-80, y=100, color=Color(b=255)))
scene.add_object(Cylinder(5, x=80, y=100, color=Color(b=255)))
scene.add_object(Cone(10, color=Color(r=128, g=128, b=128)))

nb_lines_chunk = 50