Skip to content

Instantly share code, notes, and snippets.

@georgemsavva
Created January 3, 2025 20:52
Show Gist options
  • Save georgemsavva/e7d75dd30f13630d195a1ab7ca3582b7 to your computer and use it in GitHub Desktop.
Save georgemsavva/e7d75dd30f13630d195a1ab7ca3582b7 to your computer and use it in GitHub Desktop.
R code inspired by prompt 3 of genuary 2025 "Exactly 42 lines of code"
N=42
ratio=0.8
t = seq(1,N/2*pi,l=100000)
stepper = .5*(2*((t%%pi)/pi-0.5))^5 + (t%/%pi)
circle = function(a,p,f) {
exp(1i*(t*f + p + 0*t/N*.5))*a
}
w=1000
Nf=N/6
drawchar = function(x,y,width,height,a=1,p,f,...){
a1 = rep(sample(1:N)/N, each=length(t)/N)
a1 = zoo::rollmean(a1,w,fill=c(a1[1],NA, tail(a1)[1]))
a2 = rep(sample(1:N)/N, each=length(t)/N)
a2 = zoo::rollmean(a2,w,fill=c(a2[1],NA, tail(a2)[1]))
a3 = rep(sample(1:N)/N, each=length(t)/N)
a3 = zoo::rollmean(a3,w,fill=c(a3[1],NA, tail(a3)[1]))
f3 = rep(sample(-5:5,Nf,TRUE), each=length(t)/Nf)
f3 = zoo::rollmean(f3,1,fill=c(f3[1],NA, tail(f3)[1]))
f2 = rep(sample(-5:5,Nf,TRUE), each=length(t)/Nf)
f2 = zoo::rollmean(f2,1,fill=c(f2[1],NA, tail(f2)[1]))
f1 = rep(sample(-5:5,Nf,TRUE), each=length(t)/Nf)
f1 = zoo::rollmean(f1,1,fill=c(f1[1],NA, tail(f1)[1]))
z=(circle(a,p[1],f[1]) + circle(a1,p[2],f1)+ circle(a2,p[3],f2)+ circle(a3,p[4],f3))
z2=1+x+1i*y+ 2*stepper+ .5*width*Re(z) +
1i*width*(Im(z)-min(Im(z))-1i*min(Im(z)))/(max(Im(z))-min(Im(z)))
points(z2[1:(length(z2)*ratio)],...)
}
res=4000
png("fortytwolines.png",width=res*ratio,height=res,type="cairo")
par(bg="#ddeeff",col="blue",mar=10*c(1,1,1,1))
plot(NA,xlim=(c(-N/2,N/2*(1-(2*(1-ratio))))),ylim=c(0,N)+.1,asp=1,ann=FALSE,axes=FALSE)
for(i in 0:(N)) abline(h=i-0.5,lty="dotted",lwd=3)
for(i in 0:(ratio*N+1)) abline(v=i-0.5-N/2,lty="dotted",lwd=3)
for(i in 1:N){
drawchar(-N/2+.1,i+.1-1,width = ratio,01,
p=c(0,pi/2,2*pi*runif(2)),
f=sample(-5:5,4,TRUE),
pch=19,
cex=runif(10000)^4,
col=hsv(.6,.2,.1,0.05))
}
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment