summaryrefslogtreecommitdiff
path: root/science/py-fresnel/files/example.py
blob: 71d7325011b0d46e342f7f9fe71582c820852b38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# the example is taken from https://fresnel.readthedocs.io/en/stable/examples/00-Basic-tutorials/00-Introduction.html
# image display is altered to use PIL

## generate image

import fresnel

scene = fresnel.Scene()

geometry = fresnel.geometry.Sphere(scene, N=8, radius=1.0)

geometry.position[:] = [[1,1,1],
                        [1,1,-1],
                        [1,-1,1],
                        [1,-1,-1],
                        [-1,1,1],
                        [-1,1,-1],
                        [-1,-1,1],
                        [-1,-1,-1]]


geometry.material = fresnel.material.Material(color=fresnel.color.linear([0.25,0.5,0.9]),
                                              roughness=0.8)
scene.camera = fresnel.camera.Orthographic.fit(scene)

fresnel.preview(scene)

fresnel.preview(scene, anti_alias=False)

fresnel.pathtrace(scene)

fresnel.pathtrace(scene, light_samples=40)

out = fresnel.preview(scene)
print(out[:].shape)
print(out[:].dtype)

import PIL

image = PIL.Image.fromarray(out[:], mode='RGBA')
image.save('output.png')

image = PIL.Image.fromarray(out[:,:,0:3], mode='RGB')
image.save('output.jpeg')


## display image

from PIL import Image

im = Image.open('output.png')
im.show()

im = Image.open('output.jpeg')
im.show()