Last active
May 1, 2022 07:22
-
-
Save georgemsavva/3fc19373ecf8f9bd2e860aa27a6feede to your computer and use it in GitHub Desktop.
Create an image from a rosette function.
This file contains 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
library(ggplot2) | |
library(data.table) | |
## Implement ideas from creating symmetry | |
## chapter 7 | |
f <- function(z,a,m,n) a*(z^m*Conj(z)^n) | |
# Set resolution | |
N=2000 | |
# Set domain | |
lim=seq(-1,1,l=N)*.7 | |
# Create points as a dataset | |
d <- as.data.table(expand.grid(x=lim, y=lim)) | |
# Create z = x + iy | |
d[, z:=x+1i*y] | |
# Calculate fz to plot. | |
# Alter the 'a' parameters to get different pictures that maintain the symmetry. | |
d[, fz := f(z,a=2i+2,5,0)+ | |
f(z,a=1i+1,0,5)+ | |
f(z,a=1,6,1)+ | |
f(z,a=1,1,6)+ | |
f(z,a=1,4,-6)+ | |
f(z,a=1,-6,4) | |
] | |
# Map hue, saturation and value to fz however you want | |
d[, s:=((Arg(fz)+pi)%%(2*pi))/(2*pi)] | |
d[, h:=.7] | |
d[, v:=log(Mod(fz))%%1] | |
# Now plot and save | |
g<-ggplot(d[is.finite(v)==TRUE],aes(x,y)) + | |
geom_raster(aes(fill=hsv(h,.9*s,v))) + scale_fill_identity() + theme_void() + coord_fixed() | |
ggsave("test1.jpg",g,dpi="retina", width=2000,height=2000, units = "px") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment