Participation assignment 2023-02-01
This commit is contained in:
parent
0000029064
commit
0000030042
2 changed files with 31 additions and 0 deletions
|
@ -21,6 +21,8 @@
|
|||
unzip
|
||||
texlive.combined.scheme-full
|
||||
imagemagick
|
||||
|
||||
(python310.withPackages (p: with p; [ numpy ]))
|
||||
]) ++ (with toolchain; [
|
||||
cargo
|
||||
rustc
|
||||
|
|
29
participation/2023-02-01.py
Normal file
29
participation/2023-02-01.py
Normal 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]
|
Loading…
Reference in a new issue