Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Draw-a-sphere/Julia/draw-a-sphere-1.julia
Normal file
27
Task/Draw-a-sphere/Julia/draw-a-sphere-1.julia
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
function draw_sphere(r, k, ambient, light)
|
||||
shades = ('.', ':', '!', '*', 'o', 'e', '&', '#', '%', '@')
|
||||
for i in floor(Int, -r):ceil(Int, r)
|
||||
x = i + 0.5
|
||||
line = IOBuffer()
|
||||
for j in floor(Int, -2r):ceil(2r)
|
||||
y = j / 2 + 0.5
|
||||
if x ^ 2 + y ^ 2 ≤ r ^ 2
|
||||
v = normalize([x, y, sqrt(r ^ 2 - x ^ 2 - y ^ 2)])
|
||||
b = dot(light, v) ^ k + ambient
|
||||
intensity = ceil(Int, (1 - b) * (length(shades) - 1))
|
||||
if intensity < 1
|
||||
intensity = 1 end
|
||||
if intensity > length(shades)
|
||||
intensity = length(shades) end
|
||||
print(shades[intensity])
|
||||
else
|
||||
print(' ')
|
||||
end
|
||||
end
|
||||
println()
|
||||
end
|
||||
end
|
||||
|
||||
light = normalize([30, 30, -50])
|
||||
draw_sphere(20, 4, 0.1, light)
|
||||
draw_sphere(10, 2, 0.4, light)
|
||||
13
Task/Draw-a-sphere/Julia/draw-a-sphere-2.julia
Normal file
13
Task/Draw-a-sphere/Julia/draw-a-sphere-2.julia
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# run from REPL
|
||||
|
||||
using Makie
|
||||
|
||||
φ = 0:π/100:2π
|
||||
|
||||
θ = 0:π/200:π
|
||||
|
||||
x = [cos(θ) * sin(φ) for θ in θ, φ in φ]
|
||||
y = [sin(θ)*sin(φ) for θ in θ, φ in φ]
|
||||
z = [cos(φ) for θ in θ, φ in φ]
|
||||
|
||||
surface(x, y, z, backgroundcolor = :black, show_axis = false)
|
||||
Loading…
Add table
Add a link
Reference in a new issue