Skip to content
Snippets Groups Projects
Commit b7788e64 authored by Benjamin Koltes's avatar Benjamin Koltes
Browse files

commentaires et carré

parent ae3db5f9
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
File added
File added
File added
scenes/carré.png

654 B

# -*- coding: utf-8 -*-
# Show to python where to find the modules # Show to python where to find the modules
import sys import sys
sys.path.append('..') sys.path.append('..')
......
# Show to python where to find the modules
import sys
sys.path.append('..')
from camera import Camera
from scene import *
from light import *
from raytracer import *
import numpy as np
from matplotlib.image import imsave
import itertools
import multiprocessing
def trace_ray_mutliprocess(t):
(i, j, camera, scene, nb_reflexion) = t
return np.array(trace_ray(camera.ray_at(i, j), scene, camera, nb_reflexion).coord())
(nx, ny, nb_reflexion) = (200, 200, 20)
camera = Camera(nx, ny, 1)
materiau_sphere_blanche = Material(Vector([1,1,1]), 0.2, 1, 1, 20, 0)
v0 = Vector([-1,-1,2])
v1 = Vector([1,-1,2])
v2 = Vector([-1,1,2])
v3 = Vector([1,1,2])
carre_blanc = Quad(v0,v1,v2,v3,materiau_sphere_blanche)
scene = Scene()
lumiere = Spotlight(Vector([0,0,0]), Vector([0,0,1]))
scene.add_object(carre_blanc)
scene.add_light(lumiere)
affiche = np.zeros((nx, ny, 3))
rows = list(range(nx))
columns = list(range(ny))
carte = list(itertools.product(rows, columns, [camera], [scene], [nb_reflexion]))
if __name__ == '__main__':
pool = multiprocessing.Pool(4)
affiche_map = pool.map(trace_ray_mutliprocess, carte)
pool.close()
pool.join()
affiche = np.array(affiche_map).reshape(nx, ny, 3)
imsave('carré.png', affiche)
scenes/triangle.png

1.5 KiB

scenes/two_spheres_processing.png

27.5 KiB

# Show to python where to find the modules
import sys
sys.path.append('..')
from camera import Camera
from scene import *
from light import *
from raytracer import *
import numpy as np
from matplotlib.image import imsave
import itertools
import multiprocessing
def trace_ray_mutliprocess(t):
(i, j, camera, scene, nb_reflexion) = t
return np.array(trace_ray(camera.ray_at(i, j), scene, camera, nb_reflexion).coord())
(nx, ny, nb_reflexion) = (1000, 1000, 20)
camera = Camera(nx, ny, 1)
materiau_sphere_bleue = Material(Vector([0,0,1.]), .5, .5, .5, 1000,.1)
materiau_sphere_rouge = Material(Vector([1,0,0]), .5, .5, .5, 1000, .3)
sphere_bleue = Sphere(Vector([0,0,3]), .8, materiau_sphere_bleue)
sphere_rouge = Sphere(Vector([.5,.5,2]), .5, materiau_sphere_rouge)
scene = Scene()
lumiere = Spotlight(Vector([1,1,0]), Vector([1,1,1]))
scene.add_object(sphere_bleue)
scene.add_object(sphere_rouge)
scene.add_light(lumiere)
affiche = np.zeros((nx, ny, 3))
rows = list(range(nx))
columns = list(range(ny))
carte = list(itertools.product(rows, columns, [camera], [scene], [nb_reflexion]))
if __name__ == '__main__':
pool = multiprocessing.Pool(4)
affiche_map = pool.map(trace_ray_mutliprocess, carte)
pool.close()
pool.join()
affiche = np.array(affiche_map).reshape(nx, ny, 3)
imsave('two_spheres_processing.png', affiche)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment