The butterfly curve

October 7, 2015
By

(This article was first published on » R, and kindly contributed to R-bloggers)

I came across the butterfly curve, which was discovered by Temple Fay. The butterfly curve is produced by a parametric equation where:
x = sin(t) * (e^cos(t)-2cos(λt)-sin(t/12)^5) and
y = cos(t) * (e^cos(t)-2cos(λt)-sin(t/12)^5).
Where t stands for time and λ for a user input variable.

I used ggplot to create a plot of the butterfly curve with a background of the same color pattern. After sourcing the function, the user can vary the number of background points, as well as the butterfly curves.

butterfly

library(ggplot2)
source("https://raw.githubusercontent.com/danielmarcelino/SciencesPo/master/R/butterfly.R")

> p1 = butterfly(10, 100, title="10 x 100")

Date of Analysis: Wed Oct 07 2015
Computation time: 0.009749889
-----------------------------------
> p2 = butterfly(10, 200, title="10 x 200")

Date of Analysis: Wed Oct 07 2015
Computation time: 0.01240611
-----------------------------------
> p3 = butterfly(10, 500, title="100 x 500")

Date of Analysis: Wed Oct 07 2015
Computation time: 0.02488399
-----------------------------------
> p4 = butterfly(100, 1000, title="100 x 1000")

Date of Analysis: Wed Oct 07 2015
Computation time: 0.01444697
-----------------------------------
 multiplot(p1,p2,p3,p4, ncols = 2)

To leave a comment for the author, please follow the link and comment on their blog: » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)