Created
February 10, 2022 00:57
-
-
Save natesheehan/b1a0eaa38cd74e69a1e196313c0f4b1a to your computer and use it in GitHub Desktop.
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
Archimedian_Spiral = function(seq_start, seq_end, seq_space, bg, color) { | |
t = seq(seq_start, seq_end, by = seq_space) # set | |
# create points | |
x = t * cos(t) # moves the centrepoiunt of the spiral outward from the origin | |
y = t * sin(t) # controls the distance between loops | |
#bg color | |
par(bg = bg) | |
# Plot spiral | |
plot( | |
x, | |
y, | |
col = color, | |
axes = FALSE, | |
pch = 8, | |
ann = FALSE | |
) | |
# return x and y as a dateframe | |
a = rbind(x, y) | |
} | |
Archimedian_Spiral(seq_start = 0,seq_end = 10000, seq_space = 0.75, bg = "royalblue", color = "seashell") | |
# Vectorized version | |
mandelbrot_vectorized <- function(xmin=-2, xmax=2, nx=500, | |
ymin=-1.5, ymax=1.5, ny=500, | |
n=10000, showplot=TRUE, | |
cols=colorRampPalette(c("blue","yellow","red","black"))(11)) | |
{ | |
# variables | |
x <- seq(xmin, xmax, length.out=nx) | |
y <- seq(ymin, ymax, length.out=ny) | |
c <- outer(x,y*1i,FUN="+") | |
z <- matrix(0.0, nrow=length(x), ncol=length(y)) | |
k <- matrix(0.0, nrow=length(x), ncol=length(y)) | |
for (rep in 1:n) { | |
index <- which(Mod(z) < 2) | |
z[index] <- z[index]^2 + c[index] | |
k[index] <- k[index] + 1 | |
} | |
if (showplot==TRUE) { image(x,y,k,col=cols, xlab="Re(c)", ylab="Im(c)")} | |
return(k) | |
} | |
mandelbrot_vectorized() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment