This file contains hidden or 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
# Hilbert curve in R | |
# Make some matrices to do rotation and flip | |
rotmat = function(theta) matrix(c(cos(theta),-sin(theta),sin(theta), cos(theta)),nrow=2) | |
rotclock = rotmat(pi/2) | |
rotaclock = rotmat(-pi/2) | |
flip=matrix(c(-1,0,0,1),nrow=2) | |
ident=matrix(c(1,0,0,1),nrow=2) | |
# Define the recursive function to generate the points in the right order |
This file contains hidden or 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
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,...){ |
This file contains hidden or 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
par(mfrow=c(1,1)) | |
par(mar=c(0,0,0,0)) | |
l=1.2 | |
# variables | |
res=2000 | |
n=1000 | |
x <- y <- seq(-l,l, length.out=res) | |
c <- outer(x,y*1i,FUN="+") | |
z <- matrix(0.0, nrow=res, ncol=res) | |
o <- matrix(1e5, nrow=res, ncol=res) |
This file contains hidden or 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
par(mfrow=c(1,1)) | |
par(mar=c(0,0,0,0)) | |
l=1.2 | |
# variables | |
res=1000 | |
n=500 | |
x <- y <- seq(-l,l, length.out=res) | |
c <- outer(x,y*1i,FUN="+") | |
z <- matrix(0.0, nrow=res, ncol=res) | |
o <- matrix(1e5, nrow=res, ncol=res) |
This file contains hidden or 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/ | |
# ignore the warnings, THIS IS ART! | |
library(ggplot2) | |
cols <- c("#b8e1c5", "#3ac9fb", "#fadacc","#fcb2c6", | |
"#002f88", "#fd7a5d","#00B850", "#091a22") |
This file contains hidden or 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 |
This file contains hidden or 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)))) |
This file contains hidden or 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
# The formula to iterate | |
logisticMap <- function(x, r) r * x * (1-x) | |
# Iterate N times from starting point | |
makeMap <- function(x , r, N){ | |
for(i in 2:N) x[i] <- logisticMap(x[i-1], r) | |
x | |
} | |
# How many iterations? |
This file contains hidden or 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
# Code to generate Bezier 'mesh' images inspired by the work of Jacquie Tran (https://art.jacquietran.com/) | |
# Function to calculate Bezier curves | |
bezierz <- function(z1,z2,ct,ct2,ct3,l,o=2){ | |
ll=1-l | |
if(o==3) return(z1*ll^4 + 4*ct*ll^3*l + 6*ct2*ll^2*l^2 + 4*ct3*ll*l^3 + z2*l^4) | |
if(o==2) return(z1*ll^3 + 3*ct*ll^2*l + 3*ct2*ll*l^2 + z2*l^3) | |
if(o==1) return(z1*ll^2 + 2*ct*ll*l + z2*l^2) | |
} |
This file contains hidden or 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
# Set random number seed for reproducibility | |
set.seed(2210) | |
# Number of starting points | |
N=5000 | |
# Describe the flow function | |
flow <- function(z,bs) { | |
fz <- ((z+bs[1])*(z+bs[2])*(z+bs[3])*(z+bs[4])*(z+bs[8]))/ | |
((z+bs[5])*(z+bs[6])*(z+bs[7])) |
NewerOlder