-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (32 loc) · 1.14 KB
/
main.py
File metadata and controls
47 lines (32 loc) · 1.14 KB
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
import numpy as np
import multiprocessing
from PIL import Image
from ray import Ray
import cProfile
import pstats
from pstats import SortKey
def main():
image_width = 400
image_height = 225
# size of output image in pixels; one ray per pixel
fov = 90
# degrees
data = np.zeros((image_height,image_width,3), dtype=np.uint8)
for x in range(image_width):
for y in range(image_height):
ray_x = ((2*x)/image_width - 1) * (image_width/image_height)
ray_y = 1 - ((2*y) / image_height)
ray_z = -1
# this assumes you're always looking straight towards z
direction_full = np.array([ray_x, ray_y, ray_z])
direction = direction_full/np.linalg.norm(direction_full)
ray = Ray(np.array([0., 0., 0.]), direction)
while not ray.step():
continue
data[y][x] = ray.get_color()
print(f"{x}/{image_width} complete")
img = Image.fromarray(data)
img.save("test.png")
cProfile.run("main()", 'restats')
p = pstats.Stats('restats')
p.sort_stats(SortKey.CUMULATIVE).print_stats(10)