Last active
April 13, 2024 07:44
-
-
Save georgemsavva/6f37d263833385f618e71c40a292c707 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
# There is some explanation for why the bitwise operator functions do what they do here: | |
# https://inventwithpython.com/blog/2021/08/02/algorithmic-art-with-the-bitfielddraw-module/ | |
# for the colour palettes | |
library(RColorBrewer) | |
# Set the aspect ratio | |
ratio = 5/4 | |
# How many images do we want | |
for(j in 1:100){ | |
# for the jth image, set the seed to j | |
set.seed(j) | |
# open a new png | |
png(filename=sprintf("bitwise%05d.png",j),width=2000,height=2000*ratio,type="cairo") | |
# Set up a new blank plot with fixed margin, white background, exact axis, no annotation | |
par(mar=4*c(1,1,1,1), bg="white", xaxs="i",yaxs="i") | |
plot(NA,xlim=c(0,1),ylim=c(ratio,0),ann=F,axes=F, asp=1) | |
# How many layers per plot? | |
for(i in 1:10){ | |
# Choose a palette for this layer | |
p = brewer.pal.info |> rownames() |> sample(1) | |
# What is the base modulus for this layer | |
t=sample(25*i,1) | |
# What is the grid size for this layer? | |
N=6*2^sample(1:8,1) | |
# Set up the x and y axes | |
x = seq(0,1,l=N+1) | |
y = seq(0,ratio,l=(N*ratio)+1) | |
# Pick a random bitwise function for this layer | |
f = sample(list(bitwAnd,bitwXor,bitwOr),1)[[1]] | |
# Now plot the layer! We let the modulus vary along the y axis to make the gradient | |
image(x,y,outer(1:N, 1:(N*ratio), \(x,y) f(x+y+64,y-x+64)%%(t+floor(y/10))), | |
add=TRUE,col=brewer.pal(n=floor(t/2),p)[1:t]) | |
} | |
# Close the plotting device | |
dev.off() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment