Participation assignment 2023-02-01

This commit is contained in:
Michael Zhang 2023-02-04 22:55:07 -06:00
parent 6267dce475
commit cf1a540808
2 changed files with 31 additions and 0 deletions

View file

@ -21,6 +21,8 @@
unzip
texlive.combined.scheme-full
imagemagick
(python310.withPackages (p: with p; [ numpy ]))
]) ++ (with toolchain; [
cargo
rustc

View file

@ -0,0 +1,29 @@
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]