Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2d779bef18ead25e924ceaddf1747b14 to your computer and use it in GitHub Desktop.
Save anonymous/2d779bef18ead25e924ceaddf1747b14 to your computer and use it in GitHub Desktop.
Sphere := Object clone do(
shades ::= list(".", ":", "!", "*", "o", "e", "&", "%", "#", "@")
light := nil
lightFocus ::= 0
ambientLight ::= 0
radius ::= 0
init := method(
light = Vector clone set(0, 0, 0)
)
getIntensity := method(b,
if(b <= 0, shades size - 2, 0 max((1 - b) * (shades size - 1)))
)
drawPoint := method(x, y,
if(x ** 2 + y ** 2 <= radius ** 2,
v := Vector clone
v set(x, y, (radius ** 2 - x ** 2 - y ** 2) sqrt)
v normalize
b := light dotProduct(v) negate max(0)
shades at(getIntensity(b ** lightFocus + ambientLight))
,
" "
) print
)
drawLine := method(x,
for(i, -2 * radius floor, 2 * radius ceil,
drawPoint(x, i / 2 + 0.5)
)
)
draw := method(
for(i, -radius floor, radius ceil,
drawLine(i + 0.5)
writeln
)
)
)
#!/usr/bin/env io
Sphere clone do(
light set(30, 30, -60)
light normalize
setLightFocus(1)
setAmbientLight(0.0)
setRadius(15)
draw
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment