csci5607/participation/2023-02-01.py

29 lines
693 B
Python

import numpy as np
I_lambda = np.array([1, 0, 0])
I_dc_lambda = np.array([0, 0, 0])
a_min = 0.0
a_max = 1.0
d_near = 1.0
d_far = 21.0
eye = np.array([0, 0, 0])
def dist(a, b):
return np.linalg.norm(b - a, 2)
def a_dc(d_obj):
if d_obj < d_near: return a_max
elif d_obj > d_far: return a_min
return a_min + (a_max - a_min) * (d_far - d_obj) / (d_far - d_near)
def get_color(point):
d_obj = dist(eye, point)
I_lambda_prime = a_dc(d_obj) * I_lambda + (1 - a_dc(d_obj)) * I_dc_lambda
return I_lambda_prime
print(get_color(np.array([1, 0, 0]))) # [1, 0, 0]
print(get_color(np.array([5, 0, 0]))) # [0.8, 0, 0]
print(get_color(np.array([20, 0, 0]))) # [0.05, 0, 0]