<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/playing-with-julia-set/"></div></div><div><a data-url="http://www.r-bloggers.com/playing-with-julia-set/" data-counturl="http://www.r-bloggers.com/playing-with-julia-set/" data-count="horizontal" data-text="Playing With Julia (Set)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://aschinchon.wordpress.com/2016/05/17/playing-with-julia-set/"> Ripples</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<blockquote><p>Viento, me pongo en movimiento y hago crecer las olas del mar que tienes dentro (Tercer Movimiento: Lo de Dentro, Extremoduro)</p>
</blockquote>
<p>I really enjoy drawing complex numbers: it is a huge source of entertainment for me. In this experiment I play with the <a target="_blank" href="https://en.wikipedia.org/wiki/Julia_set">Julia Set</a>, another beautiful fractal like <a target="_blank" href="https://aschinchon.wordpress.com/2014/04/04/the-collatz-fractal/">this one</a>. This is what I have done:</p>
<ul>
<li>Choosing the function <code>f(z)=exp(z<sup>3</sup>)-0.621</code></li>
<li>Generating a grid of complex numbers with both real and imaginary parts in [-2, 2]</li>
<li>Iterating <code>f(z)</code> over the grid a number of times so <code>z<sub>n+1 </sub>= f(z<sub>n</sub>)</code></li>
<li>Drawing the resulting grid as I did <a target="_blank" href="https://aschinchon.wordpress.com/2014/03/27/blurry-fractals/">here</a></li>
<li>Gathering all plots into a GIF with ImageMagick as I did in my <a target="_blank" href="https://aschinchon.wordpress.com/2016/05/02/zooming/">previous post</a>: each frame corresponds to a different number of iterations</li>
</ul>
<p>This is the result:</p>
<p><img alt="julia" class="wp-image-2724" src="https://aschinchon.files.wordpress.com/2016/05/julia.gif?w=604"></p>
<p>I love how easy is doing <em>difficult</em> things in R. You can <em>play</em> with the code changing <code>f(z)</code> as well as color palettes. Be ready to get surprised:</p>
<pre>
library(ggplot2)
library(dplyr)
library(RColorBrewer)
setwd(&quot;YOUR WORKING DIRECTORY HERE&quot;)
dir.create(&quot;output&quot;)
setwd(&quot;output&quot;)
f = function(z,c) exp(z^3)+c
# Grid of complex
z0 &lt;- outer(seq(-2, 2, length.out = 1200),1i*seq(-2, 2, length.out = 1200),'+') %>% c()
opt &lt;-  theme(legend.position=&quot;none&quot;,
              panel.background = element_rect(fill=&quot;white&quot;),
              plot.margin=grid::unit(c(1,1,0,0), &quot;mm&quot;),
              panel.grid=element_blank(),
              axis.ticks=element_blank(),
              axis.title=element_blank(),
              axis.text=element_blank())
for (i in 1:35)
{
  z=z0
  # i iterations of f(z)
  for (k in 1:i) z &lt;- f(z, c=-0.621)
  df=data.frame(x=Re(z0),
                y=Im(z0), 
                z=as.vector(exp(-Mod(z)))) %>% na.omit() 
  p=ggplot(df, aes(x=x, y=y, color=z)) + 
    geom_tile() + 
    scale_x_continuous(expand=c(0,0))+
    scale_y_continuous(expand=c(0,0))+
    scale_colour_gradientn(colours=brewer.pal(8, &quot;Paired&quot;)) + opt
  ggsave(plot=p, file=paste0(&quot;plot&quot;, stringr::str_pad(i, 4, pad = &quot;0&quot;),&quot;.png&quot;), width = 1.2, height = 1.2)
}
# Place the exact path where ImageMagick is installed
system('&quot;C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe&quot; -delay 20 -loop 0 *.png julia.gif')
# cleaning up
file.remove(list.files(pattern=&quot;.png&quot;))
</pre>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aschinchon.wordpress.com/2718/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/aschinchon.wordpress.com/2718/" border="0"></a> <img height="1" alt="" width="1" src="https://pixel.wp.com/b.gif?host=aschinchon.wordpress.com&blog=62377824&%23038;post=2718&%23038;subd=aschinchon&%23038;ref=&%23038;feed=1" border="0"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/playing-with-julia-set/"></div></div><div><a data-url="http://www.r-bloggers.com/playing-with-julia-set/" data-counturl="http://www.r-bloggers.com/playing-with-julia-set/" data-count="vertical" data-text="Playing With Julia (Set)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://aschinchon.wordpress.com/2016/05/17/playing-with-julia-set/"> Ripples</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/cEE0A6kVtt8"></a></div>