Created
June 9, 2017 17:50
-
-
Save anonymous/2d779bef18ead25e924ceaddf1747b14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
, | |
" " | |
) | |
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 | |
) | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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