Skip to content

Instantly share code, notes, and snippets.

View georgemsavva's full-sized avatar

George Savva georgemsavva

  • Quadram Institute Bioscience
View GitHub Profile
# 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")
# 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
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))))
# 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?
@georgemsavva
georgemsavva / bezier.r
Last active January 10, 2023 10:10
Code to generate Bezier grids for genuary 2023
# 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)
}
@georgemsavva
georgemsavva / flow.r
Last active November 5, 2022 21:16
R script to make a flow field based on a rational function in complex space
# 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]))
@georgemsavva
georgemsavva / rosette.R
Last active May 1, 2022 07:22
Create an image from a rosette function.
library(ggplot2)
library(data.table)
## Implement ideas from creating symmetry
## chapter 7
f <- function(z,a,m,n) a*(z^m*Conj(z)^n)
# Set resolution
N=2000
@georgemsavva
georgemsavva / codeasart3.R
Last active April 4, 2022 22:23
code as art work in progress
# For the point.in.poly function
library(sp)
# For 'createPolygons'
library(gglogo)
# To tween polygons
library(transformr)
# To make a gif!
library(gifski)
# I'm running the code like this because I want to captue the whole call during the execution.
@georgemsavva
georgemsavva / codeasart2.R
Last active October 31, 2021 12:23
R script for code/art 2. You need to have ffmpeg installed for this to work
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);
@georgemsavva
georgemsavva / codeasart.R
Created October 12, 2021 21:15
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()+