Skip to content

Instantly share code, notes, and snippets.

@georgemsavva
Created October 12, 2021 21:15
Show Gist options
  • Save georgemsavva/540375dedbcc4384363ff21bd690cfd5 to your computer and use it in GitHub Desktop.
Save georgemsavva/540375dedbcc4384363ff21bd690cfd5 to your computer and use it in GitHub Desktop.
An R script that generates itself into a piece of art. Must be 'sourced' to work.
str<-strsplit(readChar(basename(sys.frame(1)$ofile),1e5),"")[[1]];
w=ceiling(sqrt(length(str)-2));N=300;
d<-data.frame(x=floor(runif(N,0,w)),y=floor(runif(N,0,w)),h=runif(N,0,1)^4,s=.5,v=sqrt(runif(N,0.8,1)));
## refugees welcome ##;
d2<-data.frame(labels=str,x=(seq_along(str)-1)%%w,y=(seq_along(str)-1)%/%(w));
blanks<-d2[d2$labels%in%c(" ","\n"),]
library(ggplot2)
### THE CODE IS THE ART ###
ggplot(d,aes(x,y,fill=hsv(h,s,v)))+
geom_raster()+theme_void()+
scale_fill_identity()+
scale_y_reverse()+
theme(plot.background=element_rect(fill="#ffffee",color=NA))+
coord_fixed() +
geom_text(aes(label=labels,fill=NULL),data=d2,family="mono",fontface="bold",col="#111111")+
geom_tile(data=blanks,fill="black",height=1,width=1);
ggsave("img.jpg",width=7,height=7,dpi="retina")
#rtistry#generative#cleanNFT by @georgemsavva;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment