Little useless-useful R function – Psychedelic Square root with x11()
This article is originally published at https://tomaztsql.wordpress.com
Yes, the name of today’s function is wacky, because it gives you the flickering feeling when running it with x11() function. In addition is uses simple square root and cosine function to calculate the points in graph to give it psychedelic feeling.
With the following code you can generate the function to draw the “carpet” patterns.
Psychedelics <- function(number_iterations) { for (i in 1:number_iterations){ x <- seq(-5*pi, 5*pi, length.out = runif(1, i*2, i*2+1)) y <- seq(-5*pi, 5*pi, length.out = i) # print(x) print(y) r <- sqrt(outer(x^2, y^2, "+")) # print(r) image(z = exp(-r/8)*cos(r^4), col = brewer.pal(12,"Set3"), xaxt='n', yaxt='n', ann=FALSE) Sys.sleep(0.1) } }
And after function is registered in environment, you can run:
## Run all together - when running on Unix / Windows ## screen size can be altered x11(width = 7,height = 7) Psychedelics(25) graphics.off()
The end result is shown below
As always, the code is available at Github.
Happy R-ing!
Thanks for visiting r-craft.org
This article is originally published at https://tomaztsql.wordpress.com
Please visit source website for post related comments.