Last active
October 31, 2021 12:23
-
-
Save georgemsavva/6afc3bbc22c6577967335acb18317cf4 to your computer and use it in GitHub Desktop.
R script for code/art 2. You need to have ffmpeg installed for this to work
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
str=strsplit(readChar(sys.frame(1)$ofile,1e5),"")[[1]]; | |
r=ceiling(sqrt(length(str)-1));for(i in 1:320){print(i); | |
##THE.CODE.IS.THE.ART## | |
inc=i/320; | |
p1 = 2.5*1i^(4*inc); | |
p2 = -1.5*1i^(8*inc); | |
cx = Re(p1/4+p2/4); | |
cy = Im(p1/4+p2/4); | |
x = seq(cx-3,cx+3,l=r); | |
y = seq(cy+3,cy-3,l=r); | |
d = expand.grid(x=x,y=y); | |
d$z=d$x+1i*d$y; | |
hoffset=2*pi*inc;voffset=-inc; | |
d <- within(d,{ | |
c=atan(z^3*(z-p1)/(z-p2)/(z+p2)) | |
}); | |
d$value = (2*(1-inv.logit(Mod(d$c)))+voffset)%%1; | |
d$hue = ((hoffset+Arg(d$c)) / (2*pi))%%1; | |
d$hue[!is.finite(d$hue)] <- 0 ; | |
d$value[!is.finite(d$value)] <- 0; | |
lb = which(str=="\n"); | |
for(j in c(3)) d$value[lb[j-1]:lb[j]] <- pmax(d$value[lb[j-1]:lb[j]],sin(2*pi*inc)^2); | |
d$saturation = d$hue; | |
d$label = rep(str, 100)[1:dim(d)[1]]; | |
d$change = rbinom(dim(d)[1], size = 1, prob=0.5*(1-((d$hue)))^8); | |
d$ls = sample(d$label); | |
d$lab2 = ifelse(d$change, d$ls, d$label); | |
png(filename=sprintf("tmp%05d.png",i), width=1000, height=1000); | |
par(bg="#111111", mar=rep(1,4)); | |
plot(NA, xlim=c(cx-3, cx+3), ylim=c(cy-3, cy+3), axes=F, ann=F); | |
text(d$x, d$y, d$lab2, col=hsv(d$hue, d$saturation, d$value), family="mono", font = 2, cex=2.8); | |
dev.off();} | |
shell("ffmpeg -r 40 -y -i tmp%05d.png -c:v libx264 -r 40 -pix_fmt yuv420p out.mp4"); | |
#rtistry #mathart @georgemsavva 31.10.21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment