In [1]:
# raytracing tutorial
# 07- experiment with recursive rays function

In [4]:
# max depth for scene
max_depth = 3

# recursive ray function

def ray(depth):
    print("depth = ", depth, "max_depth = ", max_depth)
    
    # colour contribution
    colour_contribution = 0.1/depth
    
    # fire off new ray
    if (depth < max_depth):
        colour_contribution += ray(depth+1)
        pass
    
    return colour_contribution

In [5]:
ray(1)


depth =  1 max_depth =  3
depth =  2 max_depth =  3
depth =  3 max_depth =  3
Out[5]:
0.18333333333333335

In [ ]: