Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(readr)
- library(stringr)
- oos <- read_csv("Documents/oos.txt", col_names = FALSE)
- flatoos <- str_flatten(oos$X1, " ")
- splitflatoos <- strsplit(flatoos, " ")
- nchar(splitflatoos[[1]][1])
- len_oos <- c()
- # change len_oos[i]== to desired n \in Z>0 for words of length n
- for(i in 1:length(splitflatoos[[1]])){
- #print(i)
- len_oos[i] <- nchar(splitflatoos[[1]][i])
- if(len_oos[i]==17){
- print(splitflatoos[[1]][i])
- }
- }
- len_oos <- (len_oos[which(len_oos!=0)])
- hist(len_oos, col="red", xlab="Number of Characters in a Word", main="", breaks=18)
- plot(c(0, 18), c(0, 18), type= "n", xlab = "", ylab = "")
- rect(1, 17, 2, 18, col=length_1112, border=NA)
- length_12 <- "#000EFF"
- length_34 <- "#0086FF"
- length_56 <- "#00FFFF"
- length_78 <- "#15FF7F"
- length_910 <- "#2BFF00"
- length_1112 <- "#95F900"
- length_1314 <- "#FFF300"
- length_1516 <- "#FF7900"
- length_1718 <- "#FF0000"
- #produces rows decreasing alpha proportional to length of word
- for(i in 0:17){
- for(j in 1:((17^2)/17)){
- rect(i%%19, (18-j), (1+i)%%19, (19-j), col=rgb(1, 0, 0, 1-(0.95*((i%%19)/18))), border=NA)
- }
- }
- plotmax <- 200 #438 is max
- plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
- for(i in 0:(plotmax-1)){
- for(j in 1:plotmax){
- #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
- #print(len_oos[j+((i-1)*10)]) this works
- if(len_oos[j+(i*plotmax)] == 1 || len_oos[j+(i*plotmax)] == 2 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 3 || len_oos[j+(i*plotmax)] == 4 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 5 || len_oos[j+(i*plotmax)] == 6 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 7 || len_oos[j+(i*plotmax)] == 8 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 9 || len_oos[j+(i*plotmax)] == 10 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 11 || len_oos[j+(i*plotmax)] == 12 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 13 || len_oos[j+(i*plotmax)] == 14 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 15 || len_oos[j+(i*plotmax)] == 16 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
- } else {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
- }
- }
- }
- ### Brownian Document ###
- #check <- c()
- sample_me <- c(-1, 1)
- start_length <- 0
- plotmax <- 200
- plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
- for(i in 0:(plotmax-1)){
- for(j in 1:plotmax){
- start_length <- start_length + sample(sample_me)[1]
- if(start_length >= 18){
- start_length <- 18
- }
- if(start_length <= 1){
- start_length <- 1
- }
- #check[j+(i*plotmax)] <- start_length
- if(start_length == 1 || start_length == 2) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
- } else if(start_length == 3 || start_length == 4 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
- } else if(start_length == 5 || start_length == 6 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
- } else if(start_length == 7 || start_length == 8 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
- } else if(start_length == 9 || start_length == 10 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
- } else if(start_length == 11 || start_length == 12 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
- } else if(start_length == 13 || start_length == 14 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
- } else if(start_length == 15 || start_length == 16 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
- } else {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
- }
- }
- }
- ### White Document ###
- sample_me_white <- c(1:18)
- plotmax <- 200
- plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
- for(i in 0:(plotmax-1)){
- for(j in 1:plotmax){
- white_value <- sample(sample_me_white)[1]
- #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
- #print(len_oos[j+((i-1)*10)]) this works
- if(white_value == 1 || white_value == 2) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
- } else if(white_value == 3 || white_value == 4 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
- } else if(white_value == 5 || white_value == 6 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
- } else if(white_value == 7 || white_value == 8 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
- } else if(white_value == 9 || white_value == 10 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
- } else if(white_value == 11 || white_value == 12 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
- } else if(white_value == 13 || white_value == 14 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
- } else if(white_value == 15 || white_value == 16 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
- } else {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
- }
- }
- }
- lookat <- hist(len_oos, breaks=18, col="red", main="", xlab="Word Length")
- lookat$counts
- lookat$breaks
- ### True Pink* NOPE###
- plotsampler <- c()
- index_boi <- 17
- for(i in 1:18){
- plotsampler <- c(plotsampler, rep(i, 2^index_boi))
- print(2^index_boi)
- index_boi <- index_boi - 1
- }
- plotmax <- 100
- plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
- for(i in 0:(plotmax-1)){
- for(j in 1:plotmax){
- pink_value <- sample(plotsampler)[1]
- #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
- #print(len_oos[j+((i-1)*10)]) this works
- if(pink_value == 1 || pink_value == 2) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
- } else if(pink_value == 3 || pink_value == 4 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
- } else if(pink_value == 5 || pink_value == 6 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
- } else if(pink_value == 7 || pink_value == 8 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
- } else if(pink_value == 9 || pink_value == 10 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
- } else if(pink_value == 11 || pink_value == 12 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
- } else if(pink_value == 13 || pink_value == 14 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
- } else if(pink_value == 15 || pink_value == 16 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
- } else {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
- }
- }
- }
- ### Drawing a plot, square by square OR line by line ###
- ## Brownian has an interesting mode, so a good starting place ##
- library(magick)
- sample_me <- c(-1, 1)
- start_length <- 0
- plotmax <- 100
- frame <- 0
- plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "", axes=FALSE)
- for(i in 0:(plotmax-1)){
- for(j in 1:plotmax){
- start_length <- start_length + sample(sample_me)[1]
- if(start_length >= 18){
- start_length <- 18
- }
- if(start_length <= 1){
- start_length <- 1
- }
- #check[j+(i*plotmax)] <- start_length
- if(start_length == 1 || start_length == 2) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
- } else if(start_length == 3 || start_length == 4 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
- } else if(start_length == 5 || start_length == 6 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
- } else if(start_length == 7 || start_length == 8 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
- } else if(start_length == 9 || start_length == 10 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
- } else if(start_length == 11 || start_length == 12 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
- } else if(start_length == 13 || start_length == 14 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
- } else if(start_length == 15 || start_length == 16 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
- } else {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
- }
- if(frame%%15==14){
- p <- recordPlot()
- if(frame <10){
- name <- paste('00000', frame, '.png', sep = '')
- }
- if(frame <100 && frame >=10){
- name <- paste('0000', frame, '.png', sep = '')
- }
- if(frame <1000 && frame >=100){
- name <- paste('000', frame, '.png', sep = '')
- }
- if(frame <10000 && frame >=1000){
- name <- paste('00', frame, '.png', sep = '')
- }
- if(frame >=10000){
- name <- paste('0', frame, '.png', sep = '')
- }
- png(name, width=400, height=600)
- replayPlot(p)
- dev.off()
- }
- frame <- frame + 1
- }
- }
- # library(magick)
- # my_command <- 'convert *.png -delay 0.2 -loop 1 brown.gif'
- # system(my_command)
- setwd("~/GIF Holder")
- files <- list.files(path="~/GIF Holder", pattern=".png",all.files=T, full.names=F, no.. = T)
- list_of_images = lapply(files, image_read)
- image_list <- c()
- for (i in 1:length(list_of_images)){
- image_list[i] <- list_of_images[i]
- }
- animation <- image_animate(image_scale(image_join(image_list), "400x600"), fps = 100, dispose = "previous")
- image_write(animation, "brownian.gif")
- ### Switch to OOS ###
- library(magick)
- plotmax <- 100
- frame <- 0
- plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "", axes=FALSE)
- for(i in 0:(plotmax-1)){
- for(j in 1:plotmax){
- #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
- #print(len_oos[j+((i-1)*10)]) this works
- if(len_oos[j+(i*plotmax)] == 1 || len_oos[j+(i*plotmax)] == 2 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 3 || len_oos[j+(i*plotmax)] == 4 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 5 || len_oos[j+(i*plotmax)] == 6 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 7 || len_oos[j+(i*plotmax)] == 8 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 9 || len_oos[j+(i*plotmax)] == 10 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 11 || len_oos[j+(i*plotmax)] == 12 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 13 || len_oos[j+(i*plotmax)] == 14 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
- } else if(len_oos[j+(i*plotmax)] == 15 || len_oos[j+(i*plotmax)] == 16 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
- } else {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
- }
- if(frame%%15==14){
- p <- recordPlot()
- if(frame <10){
- name <- paste('00000', frame, '.png', sep = '')
- }
- if(frame <100 && frame >=10){
- name <- paste('0000', frame, '.png', sep = '')
- }
- if(frame <1000 && frame >=100){
- name <- paste('000', frame, '.png', sep = '')
- }
- if(frame <10000 && frame >=1000){
- name <- paste('00', frame, '.png', sep = '')
- }
- if(frame >=10000){
- name <- paste('0', frame, '.png', sep = '')
- }
- png(name, width=400, height=600)
- replayPlot(p)
- dev.off()
- }
- frame <- frame + 1
- }
- }
- # library(magick)
- # my_command <- 'convert *.png -delay 0.2 -loop 1 brown.gif'
- # system(my_command)
- setwd("~/GIF Holder")
- files <- list.files(path="~/GIF Holder", pattern=".png",all.files=T, full.names=F, no.. = T)
- list_of_images = lapply(files, image_read)
- image_list <- c()
- for (i in 1:length(list_of_images)){
- image_list[i] <- list_of_images[i]
- }
- animation <- image_animate(image_scale(image_join(image_list), "400x600"), fps = 100, dispose = "previous")
- image_write(animation, "oos.gif")
- ### Switch to White ###
- library(magick)
- sample_me_white <- c(1:18)
- plotmax <- 100
- frame <- 0
- plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "", axes=FALSE)
- for(i in 0:(plotmax-1)){
- for(j in 1:plotmax){
- white_value <- sample(sample_me_white)[1]
- #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
- #print(len_oos[j+((i-1)*10)]) this works
- if(white_value == 1 || white_value == 2) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
- } else if(white_value == 3 || white_value == 4 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
- } else if(white_value == 5 || white_value == 6 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
- } else if(white_value == 7 || white_value == 8 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
- } else if(white_value == 9 || white_value == 10 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
- } else if(white_value == 11 || white_value == 12 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
- } else if(white_value == 13 || white_value == 14 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
- } else if(white_value == 15 || white_value == 16 ) {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
- } else {
- rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
- }
- if(frame%%15==14){
- p <- recordPlot()
- if(frame <10){
- name <- paste('00000', frame, '.png', sep = '')
- }
- if(frame <100 && frame >=10){
- name <- paste('0000', frame, '.png', sep = '')
- }
- if(frame <1000 && frame >=100){
- name <- paste('000', frame, '.png', sep = '')
- }
- if(frame <10000 && frame >=1000){
- name <- paste('00', frame, '.png', sep = '')
- }
- if(frame >=10000){
- name <- paste('0', frame, '.png', sep = '')
- }
- png(name, width=400, height=600)
- replayPlot(p)
- dev.off()
- }
- frame <- frame + 1
- }
- }
- # library(magick)
- # my_command <- 'convert *.png -delay 0.2 -loop 1 brown.gif'
- # system(my_command)
- setwd("~/GIF Holder")
- files <- list.files(path="~/GIF Holder", pattern=".png",all.files=T, full.names=F, no.. = T)
- list_of_images = lapply(files, image_read)
- image_list <- c()
- for (i in 1:length(list_of_images)){
- image_list[i] <- list_of_images[i]
- }
- animation <- image_animate(image_scale(image_join(image_list), "400x600"), fps = 100, dispose = "previous")
- image_write(animation, "white.gif")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement