diff --git a/scripts/__pycache__/script_multiprocessing.cpython-33.pyc b/scripts/__pycache__/script_multiprocessing.cpython-33.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0572f37f57fa0db1bd1b3c82f359b0e5e6079d24 Binary files /dev/null and b/scripts/__pycache__/script_multiprocessing.cpython-33.pyc differ diff --git a/scripts/__pycache__/script_triangle.cpython-33.pyc b/scripts/__pycache__/script_triangle.cpython-33.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5d355fb6dde386cf4534f32971d760e6020948b4 Binary files /dev/null and b/scripts/__pycache__/script_triangle.cpython-33.pyc differ diff --git a/scripts/img.png b/scripts/img.png new file mode 100644 index 0000000000000000000000000000000000000000..1d0febe6ddad6a74460909cde821a038dfcdb585 Binary files /dev/null and b/scripts/img.png differ diff --git a/scripts/script.py b/scripts/script.py index 032a962ad357c08aa0242232f5aa4f20057c7833..4337069032f23fb76812b80db529464204229c2d 100644 --- a/scripts/script.py +++ b/scripts/script.py @@ -1,7 +1,8 @@ # Show to python where to find the modules import sys +sys.path.append('..') -sys.path.append('..')from scene import * +from scene import * from light import Spotlight from camera import Camera from raytracer import raytracer_render diff --git a/scripts/script_multiprocessing.py b/scripts/script_multiprocessing.py index 2e7fb230bc98cb80cf895f8a1ac51e9014dfd5ac..c6667feb2cda3f86df9c7c16991a03719b3ec86d 100644 --- a/scripts/script_multiprocessing.py +++ b/scripts/script_multiprocessing.py @@ -15,12 +15,12 @@ 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) +(nx, ny, nb_reflexion) = (400, 400, 20) 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) -materiau_sphere_blanche = Material(Vector([1,0,0]), .5, .5, .5, 1000, .7) +materiau_sphere_blanche = Material(Vector([1,1,1]), .5, .5, .5, 1000, .7) sphere_verte = Sphere(Vector([3,-3,4]), 2.5, materiau_sphere_verte) sphere_bleue = Sphere(Vector([0,0,3]), .8, materiau_sphere_bleue) sphere_rouge = Sphere(Vector([.5,.5,2]), .5, materiau_sphere_rouge) @@ -38,9 +38,9 @@ columns = list(range(ny)) carte = list(itertools.product(rows, columns, [camera], [scene], [nb_reflexion])) if __name__ == '__main__': - pool = multiprocessing.Pool(8) + 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('test.png', affiche) + imsave('img.png', affiche) diff --git a/scripts/script_one_sphere.py b/scripts/script_one_sphere.py index 80402df3840c94ab7ac4e18fc2f58bd14041e461..1bb86c97fd806cca3233100779dbc86543b21103 100644 --- a/scripts/script_one_sphere.py +++ b/scripts/script_one_sphere.py @@ -1,5 +1,6 @@ # Show to python where to find the modules import sys +sys.path.append('..') from scene import * from light import Spotlight diff --git a/scripts/script_reflection.py b/scripts/script_reflection.py index 67cbff512c19b34433760c8f99d80e8c1308ff94..f76da921240f264e470a85257667baa4e4db36ad 100644 --- a/scripts/script_reflection.py +++ b/scripts/script_reflection.py @@ -1,5 +1,6 @@ # Show to python where to find the modules import sys +sys.path.append('..') from scene import * from light import Spotlight diff --git a/scripts/script_shadow.py b/scripts/script_shadow.py index a25a314f33a3145ece8aa92cc11cabf71b955101..019467b6f611ae798283e8a508830206afd8ac74 100644 --- a/scripts/script_shadow.py +++ b/scripts/script_shadow.py @@ -1,5 +1,6 @@ # Show to python where to find the modules import sys +sys.path.append('..') from scene import * from light import Spotlight diff --git a/scripts/script_triangle.py b/scripts/script_triangle.py new file mode 100644 index 0000000000000000000000000000000000000000..4dac2c860f2845db1b13184a2a6370b2df2c8b3a --- /dev/null +++ b/scripts/script_triangle.py @@ -0,0 +1,35 @@ +# Show to python where to find the modules +import sys +sys.path.append('..') + +from scene import * +from light import Spotlight +from camera import Camera +from raytracer import raytracer_render +from matplotlib.image import imsave + +camera = Camera(100,100,1) +materiau_sphere_bleue = Material(Vector((0,0,1)), .5, .3, .3, 100, .5) +materiau_sphere_rouge = Material(Vector((1,0,0)), .5, .3, .3, 100, .3) +materiau_sphere_blanche = Material(Vector((1,1,1)), .5, .3, .3, 100, 0) +materiau_sphere_verte= Material(Vector((0,1,0)), .5, .3, .3, 100, .3) +c = (8+2*(3**.5))**.5 +l = 0+0*((c**2 - 4)**.5) +v0 = Vector([0,0,2+l]) +v1 = Vector([0,2,2+l]) +v2 = Vector([2,0,2+l]) +v3 = Vector([0,0,2]) +#triangle_rouge = Triangle(v0,v1,v3,materiau_sphere_rouge) +#triangle_vert = Triangle(v1,v2,v3,materiau_sphere_verte) +#triangle_bleu = Triangle(v0,v2,v3,materiau_sphere_bleue) +triangle_blanc = Triangle(v0,v1,v2,materiau_sphere_blanche) +lumiere = Spotlight(Vector((1,1,0)), Vector((1,1,1))) +scene = Scene() +#scene.add_object(sphere_blanche) +#scene.add_object(triangle_bleu) +#scene.add_object(triangle_rouge) +scene.add_object(triangle_blanc) +scene.add_light(lumiere) +affiche = raytracer_render(camera, scene) +imsave('try.png',affiche) +print('Done') diff --git a/scripts/script_triangle_multi.py b/scripts/script_triangle_multi.py new file mode 100644 index 0000000000000000000000000000000000000000..f3fabc5cf6e728d109c3efa645b51a24eb949371 --- /dev/null +++ b/scripts/script_triangle_multi.py @@ -0,0 +1,52 @@ +# 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_bleue = Material(Vector([0,0,1]), .5, .5, .5, 1000,0) +materiau_sphere_verte = Material(Vector([0,1,0]), .5, .5, .5, 1000, 0) +materiau_sphere_rouge = Material(Vector([1,0,0]), .5, .5, .5, 1000, 0) +materiau_sphere_blanche = Material(Vector([1,1,1]), 1, 1, 1, 20, 0) +c = (8+2*(3**.5))**.5 +l = (c**2 - 4)**.5 +v0 = Vector([0,2,2+l]) +v1 = Vector([3**.5,-1,2+l]) +v2 = Vector([3**.5,-1,2+l]) +v3 = Vector([0,0,2]) +#triangle_rouge = Triangle(v0,v1,v3,materiau_sphere_rouge) +#triangle_vert = Triangle(v1,v2,v3,materiau_sphere_verte) +#triangle_bleu = Triangle(v0,v2,v3,materiau_sphere_bleue) +triangle_blanc = Triangle(v0,v2,v3,materiau_sphere_blanche) +scene = Scene() +lumiere = Spotlight(Vector([0,0,0]), Vector([1,1,1])) +#scene.add_object(sphere_blanche) +#scene.add_object(triangle_bleu) +#scene.add_object(triangle_rouge) +scene.add_object(triangle_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('triangle.png', affiche) diff --git a/scripts/test.png b/scripts/test.png new file mode 100644 index 0000000000000000000000000000000000000000..645c9fc7d4cc256f2928cacf73fe6a051e035a02 Binary files /dev/null and b/scripts/test.png differ diff --git a/scripts/try.png b/scripts/try.png new file mode 100644 index 0000000000000000000000000000000000000000..09abf45b713453cc820b6eca100672c98914e8f3 Binary files /dev/null and b/scripts/try.png differ