diff --git a/scenes/test.py b/scenes/test.py new file mode 100644 index 0000000000000000000000000000000000000000..9ad8273958509924b90a0acd88d98f9b1936a4ab --- /dev/null +++ b/scenes/test.py @@ -0,0 +1,43 @@ +# 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 imsave +import numpy as np +import matplotlib.image +import itertools +import multiprocessing + +def trace_ray_mutliprocess(t): + (i, j, camera, scene, nb_reflexion) = t + return trace_ray(camera.ray_at(i, j), scene, camera, nb_reflexion) + +(nx, ny, nb_reflexion) = (1000, 1000, 10) +camera = Camera(nx, ny, 1) +materiau_sphere_bleue = Material(Vector([0,0,1.]), .5, .5, .5, 1000,.1) +materiau_sphere_verte = Material(Vector([0,1,0]), .5, .5, .5, 1000, .6) +materiau_sphere_rouge = Material(Vector([1,0,0]), .5, .5, .5, 1000, .3) +sphere_verte = Sphere(Vector([3,-3,4]), 2.5, materiau_sphere_verte) +sphere_bleue = Sphere(Vector([0,0,3]), 0.8, materiau_sphere_bleue) +sphere_rouge = Sphere(Vector([0.5,0.5,2]), 0.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_object(sphere_verte) +scene.add_light(lumiere) +img = np.zeros((nx, ny, 3)) +Rows = list(range(nx)) +Colons = list(range(ny)) +carte = list(itertools.product(Rows, Colons, [camera], [scene], [nb_reflexion])) + +if __name__ == '__main__': + pool = multiprocessing.Pool(8) + affiche = pool.map(trace_ray_mutliprocess, carte) + p.close() + p.join() + img = np.array(img).reshape(nx, ny, 3) + imsave('test.png', affiche)