Created
July 19, 2023 23:44
-
-
Save georgemsavva/4e89a4b777570967dd85fb9a5de58c7d to your computer and use it in GitHub Desktop.
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(magick) | |
# This is the function for the basic shape | |
flower <- function(a){ | |
# make an index | |
t <- seq(0,202,l=499) | |
# make a curve | |
z1 <- (1i*(1i^a)*cos(2*t*pi)*(1) + 1*(1i^a)*(sin(2*t*pi))*(1) ) | |
# modulate the curve | |
z1*(3+(sin(a*Arg(z1))*cos(a*Arg(z1))*cos((10-a)*Arg(z1)))) | |
} | |
# Rotate the end point to the front for segments. | |
rot <- function(x) c(x[-1],x[1]) | |
# Function to make each image | |
makeFlower <- function(h=0,filename,N=9){ | |
png(filename, type="cairo",width=1000,height=1000) | |
par(mfrow=c(sqrt(N),sqrt(N)), | |
oma=10*rep(1,4), | |
mar=0*rep(1,4),bg="#f0f0f0") | |
for(i in 1:N) { | |
h = h | |
s = 0.9 | |
v = .5 | |
alpha = 0.3 | |
col = hsv(h,s,v,alpha) | |
z = flower(a=i/2) | |
plot(z, type="o", asp=1, pch=20, | |
axes=F, ann=F, col=col, lwd=0.1) | |
# We use segments not lines in case | |
# we want to vary the col throughout. | |
segments(Re(z),Im(z),rot(Re(z)),rot(Im(z)), col=col) | |
points(z, col=hsv(h,0,1,.4)) | |
} | |
dev.off() | |
} | |
# Make four layers | |
makeFlower( 1,"fl4.png",16) | |
makeFlower(.8,"fl3.png",9) | |
makeFlower(.6,"fl2.png",4) | |
makeFlower(.5,"fl1.png",1) | |
# Compose final image using imagemagick | |
fl1 <- image_read("fl1.png") | |
fl2 <- image_read("fl2.png")|> | |
image_transparent("#f0f0f0") | |
fl3 <- image_read("fl3.png")|> | |
image_transparent("#f0f0f0") | |
fl4 <- image_read("fl4.png") |> | |
image_transparent("#f0f0f0") | |
fl1 |> | |
image_composite(fl2) |> | |
image_composite(fl3) |> | |
image_composite(fl4) |> | |
image_write("fl0.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment