Last active
July 10, 2017 18:05
-
-
Save HenrikBengtsson/37c15ae357e20eede01924ad4bee242c to your computer and use it in GitHub Desktop.
ASCII Mandelbrot renderer (One-to-one R interpretation of C implementation)
This file contains hidden or 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
## A one-to-one R interpretation of the minimalist C implementation | |
## of the ASCII Mandelbrot renderer in http://codepad.org/nINhbWVy: | |
## | |
## main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x | |
## =0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0; | |
## j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);} | |
main <- function(k = 0) { | |
y <- -16 | |
while({ cat("\n"); y <- y + 1L } < 16) { | |
for (x in 0:83) { | |
cat(rawToChar(charToRaw(" .:-;!/>)|&IH%*#")[k %% 16 + 1])) | |
i <- k <- r <- 0 | |
while ({ | |
j <- r * r - i * i - 2 + x / 25 | |
i <- 2 * r * i + y / 10 | |
j * j + i * i < 11 && { k <- k + 1 } < 112 | |
}) r <- j | |
} | |
} | |
} | |
## Render | |
main() | |
# | |
# ..............::::::::::::::::::::::::::::::::::::::::::::::::..................... | |
# ...........::::::::::::::::::::::::::::::::::::::::::::::::::::::::................. | |
# .......::::::::::::::::::::::::::::::::::-----------:::::::::::::::::::............. | |
# .....:::::::::::::::::::::::::::::------------------------:::::::::::::::........... | |
# ..:::::::::::::::::::::::::::-------------;;;!:H!!;;;--------:::::::::::::::........ | |
# .:::::::::::::::::::::::::-------------;;;;!!/>&*|I !;;;--------::::::::::::::...... | |
# .:::::::::::::::::::::-------------;;;;;;!!/>)|.*#|>/!!;;;;-------::::::::::::::.... | |
# .:::::::::::::::::-------------;;;;;;!!!!//>|: !:|//!!!;;;;-----::::::::::::::... | |
# .:::::::::::::------------;;;;;;;!!/>)I>>)||I# H&))>////*!;;-----:::::::::::::.. | |
# .:::::::::----------;;;;;;;;;;!!!//)H: #| IH&*I#/;;-----:::::::::::::. | |
# .::::::---------;;;;!!!!!!!!!!!//>|.H: #I>/!;;-----::::::::::::: | |
# .::----------;;;;!/||>//>>>>//>>)|% %|&/!;;----::::::::::::: | |
# :---------;;;;;!!//)& :;I*-H#&||&/ *)/!;;-----:::::::::::: | |
# :------;;;;;!!!//>)IH:- ## #&!!;;-----:::::::::::: | |
# :-;;;;!!!!!///>)H%.** * )/!;;;------::::::::::: | |
# : &)/!!;;;------::::::::::: | |
# :-;;;;!!!!!///>)H%.** * )/!;;;------::::::::::: | |
# :------;;;;;!!!//>)IH:- ## #&!!;;-----:::::::::::: | |
# :---------;;;;;!!//)& :;I*-H#&||&/ *)/!;;-----:::::::::::: | |
# :::----------;;;;!/||>//>>>>//>>)|% %|&/!;;----::::::::::::: | |
# :::::::---------;;;;!!!!!!!!!!!//>|.H: #I>/!;;-----::::::::::::: | |
# .:::::::::----------;;;;;;;;;;!!!//)H: #| IH&*I#/;;-----:::::::::::::. | |
# .:::::::::::::------------;;;;;;;!!/>)I>>)||I# H&))>////*!;;-----:::::::::::::.. | |
# .:::::::::::::::::-------------;;;;;;!!!!//>|: !:|//!!!;;;;-----::::::::::::::... | |
# .:::::::::::::::::::::-------------;;;;;;!!/>)|.*#|>/!!;;;;-------::::::::::::::.... | |
# .:::::::::::::::::::::::::-------------;;;;!!/>&*|I !;;;--------::::::::::::::...... | |
# ..:::::::::::::::::::::::::::-------------;;;!:H!!;;;--------:::::::::::::::........ | |
# .....:::::::::::::::::::::::::::::------------------------:::::::::::::::........... | |
# .......::::::::::::::::::::::::::::::::::-----------:::::::::::::::::::............. | |
# ...........::::::::::::::::::::::::::::::::::::::::::::::::::::::::................. | |
# ...............::::::::::::::::::::::::::::::::::::::::::::::::..................... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment