Generative Art with the Polar Coordinates

“Fun with Polar coordinates”

Author

Janith Wanniarachchi

Published

May 29, 2020

Explanation

This was a fun little experiment I wanted to do where I wanted to let a couple of children run around randomly in their lunch break maybe and plot their movements on a polar coordinates.

So the number of bois are set by n_bois and the number of seconds(or time points) they have their lunch break is set by recess_time. First I set the initial points of the bois as follows. These were simply set to be cartesian coordinates so that I can simply convert them to polar and see how it goes. Xi=Unif(100,100)Yi=Unif(100,100) And then for each tth time point I calculated the following values

anglet=Unif(0,180)speedt=Unif(10,1000)t=1,2,...,recesstimeanglesi=Unif(anglet,anglet)speedi=Unif(speedt,speedt)i=1,2,...,n_bois

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
set.seed(42)
theme_set(theme_void())

n_bois <- 100
a <- tibble(x=runif(n=n_bois,-100,100),
            y=runif(n=n_bois,-100,100),
            time=1,
            tag=seq(1,n_bois))

recess_time <- 360

radian <- function(degree){
  (degree / 360) * 2 * pi  
}

for(i in 1:recess_time){
  angle_val <- runif(1,0,180)
  speed_val <-runif(1,10,1000)
  angles <- runif(n_bois,-angle_val,angle_val)
  speed <- runif(n_bois,-speed_val,speed_val)
  start_index <- length(a$x)-n_bois+1
  end_index <- length(a$x)
  b <- tibble(x = a$x[start_index:end_index] + speed * cos(radian(angles)),
              y = a$y[start_index:end_index] + speed * sin(radian(angles)),
              time = i,
              tag=seq(1,n_bois))
  a <- rbind(a,b)
}

ggplot(a,aes(x,y))+
  geom_point(aes(color=time,group=tag),
                 size=0.5,alpha=0.8,show.legend = FALSE) +
  geom_line(aes(color=time,group=tag),show.legend = FALSE) +
  coord_polar() + 
  scale_color_gradient(low="#83a4d4",high="#b6fbff")