Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Draw-a-sphere/11l/draw-a-sphere.11l
Normal file
26
Task/Draw-a-sphere/11l/draw-a-sphere.11l
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
V shades = [‘.’, ‘:’, ‘!’, ‘*’, ‘o’, ‘e’, ‘&’, ‘#’, ‘%’, ‘@’]
|
||||
|
||||
F dotp(v1, v2)
|
||||
V d = dot(v1, v2)
|
||||
R I d < 0 {-d} E 0.0
|
||||
|
||||
F draw_sphere(r, k, ambient, light)
|
||||
L(i) Int(floor(-r)) .< Int(ceil(r) + 1)
|
||||
V x = i + 0.5
|
||||
V line = ‘’
|
||||
|
||||
L(j) Int(floor(-2 * r)) .< Int(ceil(2 * r) + 1)
|
||||
V y = j / 2 + 0.5
|
||||
I x * x + y * y <= r * r
|
||||
V vec = normalize((x, y, sqrt(r * r - x * x - y * y)))
|
||||
V b = dotp(light, vec) ^ k + ambient
|
||||
V intensity = Int((1 - b) * (:shades.len - 1))
|
||||
line ‘’= I intensity C 0 .< :shades.len {:shades[intensity]} E :shades[0]
|
||||
E
|
||||
line ‘’= ‘ ’
|
||||
|
||||
print(line)
|
||||
|
||||
V light = normalize((30.0, 30.0, -50.0))
|
||||
draw_sphere(20, 4, 0.1, light)
|
||||
draw_sphere(10, 2, 0.4, light)
|
||||
Loading…
Add table
Add a link
Reference in a new issue