Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.53 KB | None | 0 0
  1. library(readr)
  2. library(stringr)
  3. oos <- read_csv("Documents/oos.txt", col_names = FALSE)
  4.  
  5. flatoos <- str_flatten(oos$X1, " ")
  6.  
  7. splitflatoos <- strsplit(flatoos, " ")
  8.  
  9. nchar(splitflatoos[[1]][1])
  10.  
  11. len_oos <- c()
  12.  
  13. # change len_oos[i]== to desired n \in Z>0 for words of length n
  14.  
  15. for(i in 1:length(splitflatoos[[1]])){
  16. #print(i)
  17.  
  18. len_oos[i] <- nchar(splitflatoos[[1]][i])
  19.  
  20. if(len_oos[i]==17){
  21. print(splitflatoos[[1]][i])
  22. }
  23.  
  24. }
  25.  
  26. len_oos <- (len_oos[which(len_oos!=0)])
  27.  
  28. hist(len_oos, col="red", xlab="Number of Characters in a Word", main="", breaks=18)
  29.  
  30.  
  31. plot(c(0, 18), c(0, 18), type= "n", xlab = "", ylab = "")
  32. rect(1, 17, 2, 18, col=length_1112, border=NA)
  33.  
  34. length_12 <- "#000EFF"
  35. length_34 <- "#0086FF"
  36. length_56 <- "#00FFFF"
  37. length_78 <- "#15FF7F"
  38. length_910 <- "#2BFF00"
  39. length_1112 <- "#95F900"
  40. length_1314 <- "#FFF300"
  41. length_1516 <- "#FF7900"
  42. length_1718 <- "#FF0000"
  43.  
  44.  
  45.  
  46. #produces rows decreasing alpha proportional to length of word
  47.  
  48. for(i in 0:17){
  49. for(j in 1:((17^2)/17)){
  50. rect(i%%19, (18-j), (1+i)%%19, (19-j), col=rgb(1, 0, 0, 1-(0.95*((i%%19)/18))), border=NA)
  51. }
  52. }
  53.  
  54. plotmax <- 200 #438 is max
  55.  
  56. plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
  57.  
  58. for(i in 0:(plotmax-1)){
  59. for(j in 1:plotmax){
  60. #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
  61. #print(len_oos[j+((i-1)*10)]) this works
  62. if(len_oos[j+(i*plotmax)] == 1 || len_oos[j+(i*plotmax)] == 2 ) {
  63. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
  64. } else if(len_oos[j+(i*plotmax)] == 3 || len_oos[j+(i*plotmax)] == 4 ) {
  65. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
  66. } else if(len_oos[j+(i*plotmax)] == 5 || len_oos[j+(i*plotmax)] == 6 ) {
  67. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
  68. } else if(len_oos[j+(i*plotmax)] == 7 || len_oos[j+(i*plotmax)] == 8 ) {
  69. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
  70. } else if(len_oos[j+(i*plotmax)] == 9 || len_oos[j+(i*plotmax)] == 10 ) {
  71. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
  72. } else if(len_oos[j+(i*plotmax)] == 11 || len_oos[j+(i*plotmax)] == 12 ) {
  73. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
  74. } else if(len_oos[j+(i*plotmax)] == 13 || len_oos[j+(i*plotmax)] == 14 ) {
  75. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
  76. } else if(len_oos[j+(i*plotmax)] == 15 || len_oos[j+(i*plotmax)] == 16 ) {
  77. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
  78. } else {
  79. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
  80. }
  81. }
  82. }
  83.  
  84. ### Brownian Document ###
  85.  
  86.  
  87. #check <- c()
  88.  
  89. sample_me <- c(-1, 1)
  90.  
  91. start_length <- 0
  92.  
  93. plotmax <- 200
  94.  
  95. plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
  96.  
  97. for(i in 0:(plotmax-1)){
  98. for(j in 1:plotmax){
  99.  
  100. start_length <- start_length + sample(sample_me)[1]
  101.  
  102. if(start_length >= 18){
  103. start_length <- 18
  104. }
  105. if(start_length <= 1){
  106. start_length <- 1
  107. }
  108.  
  109. #check[j+(i*plotmax)] <- start_length
  110.  
  111. if(start_length == 1 || start_length == 2) {
  112. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
  113. } else if(start_length == 3 || start_length == 4 ) {
  114. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
  115. } else if(start_length == 5 || start_length == 6 ) {
  116. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
  117. } else if(start_length == 7 || start_length == 8 ) {
  118. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
  119. } else if(start_length == 9 || start_length == 10 ) {
  120. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
  121. } else if(start_length == 11 || start_length == 12 ) {
  122. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
  123. } else if(start_length == 13 || start_length == 14 ) {
  124. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
  125. } else if(start_length == 15 || start_length == 16 ) {
  126. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
  127. } else {
  128. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
  129. }
  130. }
  131. }
  132.  
  133.  
  134.  
  135.  
  136. ### White Document ###
  137.  
  138.  
  139. sample_me_white <- c(1:18)
  140.  
  141. plotmax <- 200
  142.  
  143. plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
  144.  
  145. for(i in 0:(plotmax-1)){
  146. for(j in 1:plotmax){
  147. white_value <- sample(sample_me_white)[1]
  148. #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
  149. #print(len_oos[j+((i-1)*10)]) this works
  150. if(white_value == 1 || white_value == 2) {
  151. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
  152. } else if(white_value == 3 || white_value == 4 ) {
  153. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
  154. } else if(white_value == 5 || white_value == 6 ) {
  155. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
  156. } else if(white_value == 7 || white_value == 8 ) {
  157. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
  158. } else if(white_value == 9 || white_value == 10 ) {
  159. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
  160. } else if(white_value == 11 || white_value == 12 ) {
  161. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
  162. } else if(white_value == 13 || white_value == 14 ) {
  163. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
  164. } else if(white_value == 15 || white_value == 16 ) {
  165. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
  166. } else {
  167. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
  168. }
  169. }
  170. }
  171.  
  172. lookat <- hist(len_oos, breaks=18, col="red", main="", xlab="Word Length")
  173. lookat$counts
  174. lookat$breaks
  175.  
  176.  
  177. ### True Pink* NOPE###
  178.  
  179. plotsampler <- c()
  180.  
  181. index_boi <- 17
  182.  
  183. for(i in 1:18){
  184. plotsampler <- c(plotsampler, rep(i, 2^index_boi))
  185. print(2^index_boi)
  186. index_boi <- index_boi - 1
  187. }
  188.  
  189.  
  190. plotmax <- 100
  191.  
  192. plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "")
  193.  
  194. for(i in 0:(plotmax-1)){
  195. for(j in 1:plotmax){
  196. pink_value <- sample(plotsampler)[1]
  197. #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
  198. #print(len_oos[j+((i-1)*10)]) this works
  199. if(pink_value == 1 || pink_value == 2) {
  200. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
  201. } else if(pink_value == 3 || pink_value == 4 ) {
  202. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
  203. } else if(pink_value == 5 || pink_value == 6 ) {
  204. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
  205. } else if(pink_value == 7 || pink_value == 8 ) {
  206. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
  207. } else if(pink_value == 9 || pink_value == 10 ) {
  208. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
  209. } else if(pink_value == 11 || pink_value == 12 ) {
  210. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
  211. } else if(pink_value == 13 || pink_value == 14 ) {
  212. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
  213. } else if(pink_value == 15 || pink_value == 16 ) {
  214. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
  215. } else {
  216. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
  217. }
  218. }
  219. }
  220.  
  221. ### Drawing a plot, square by square OR line by line ###
  222.  
  223.  
  224. ## Brownian has an interesting mode, so a good starting place ##
  225.  
  226. library(magick)
  227.  
  228. sample_me <- c(-1, 1)
  229.  
  230. start_length <- 0
  231.  
  232. plotmax <- 100
  233.  
  234. frame <- 0
  235.  
  236. plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "", axes=FALSE)
  237.  
  238. for(i in 0:(plotmax-1)){
  239. for(j in 1:plotmax){
  240.  
  241. start_length <- start_length + sample(sample_me)[1]
  242.  
  243. if(start_length >= 18){
  244. start_length <- 18
  245. }
  246. if(start_length <= 1){
  247. start_length <- 1
  248. }
  249.  
  250. #check[j+(i*plotmax)] <- start_length
  251.  
  252.  
  253. if(start_length == 1 || start_length == 2) {
  254. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
  255. } else if(start_length == 3 || start_length == 4 ) {
  256. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
  257. } else if(start_length == 5 || start_length == 6 ) {
  258. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
  259. } else if(start_length == 7 || start_length == 8 ) {
  260. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
  261. } else if(start_length == 9 || start_length == 10 ) {
  262. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
  263. } else if(start_length == 11 || start_length == 12 ) {
  264. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
  265. } else if(start_length == 13 || start_length == 14 ) {
  266. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
  267. } else if(start_length == 15 || start_length == 16 ) {
  268. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
  269. } else {
  270. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
  271. }
  272.  
  273. if(frame%%15==14){
  274. p <- recordPlot()
  275.  
  276. if(frame <10){
  277. name <- paste('00000', frame, '.png', sep = '')
  278. }
  279. if(frame <100 && frame >=10){
  280. name <- paste('0000', frame, '.png', sep = '')
  281. }
  282. if(frame <1000 && frame >=100){
  283. name <- paste('000', frame, '.png', sep = '')
  284. }
  285. if(frame <10000 && frame >=1000){
  286. name <- paste('00', frame, '.png', sep = '')
  287. }
  288. if(frame >=10000){
  289. name <- paste('0', frame, '.png', sep = '')
  290. }
  291.  
  292. png(name, width=400, height=600)
  293.  
  294. replayPlot(p)
  295.  
  296. dev.off()
  297. }
  298.  
  299. frame <- frame + 1
  300. }
  301. }
  302.  
  303. # library(magick)
  304. # my_command <- 'convert *.png -delay 0.2 -loop 1 brown.gif'
  305. # system(my_command)
  306. setwd("~/GIF Holder")
  307. files <- list.files(path="~/GIF Holder", pattern=".png",all.files=T, full.names=F, no.. = T)
  308. list_of_images = lapply(files, image_read)
  309.  
  310.  
  311.  
  312. image_list <- c()
  313.  
  314. for (i in 1:length(list_of_images)){
  315. image_list[i] <- list_of_images[i]
  316. }
  317.  
  318. animation <- image_animate(image_scale(image_join(image_list), "400x600"), fps = 100, dispose = "previous")
  319. image_write(animation, "brownian.gif")
  320.  
  321. ### Switch to OOS ###
  322.  
  323. library(magick)
  324.  
  325. plotmax <- 100
  326.  
  327. frame <- 0
  328.  
  329. plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "", axes=FALSE)
  330.  
  331. for(i in 0:(plotmax-1)){
  332. for(j in 1:plotmax){
  333. #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
  334. #print(len_oos[j+((i-1)*10)]) this works
  335. if(len_oos[j+(i*plotmax)] == 1 || len_oos[j+(i*plotmax)] == 2 ) {
  336. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
  337. } else if(len_oos[j+(i*plotmax)] == 3 || len_oos[j+(i*plotmax)] == 4 ) {
  338. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
  339. } else if(len_oos[j+(i*plotmax)] == 5 || len_oos[j+(i*plotmax)] == 6 ) {
  340. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
  341. } else if(len_oos[j+(i*plotmax)] == 7 || len_oos[j+(i*plotmax)] == 8 ) {
  342. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
  343. } else if(len_oos[j+(i*plotmax)] == 9 || len_oos[j+(i*plotmax)] == 10 ) {
  344. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
  345. } else if(len_oos[j+(i*plotmax)] == 11 || len_oos[j+(i*plotmax)] == 12 ) {
  346. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
  347. } else if(len_oos[j+(i*plotmax)] == 13 || len_oos[j+(i*plotmax)] == 14 ) {
  348. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
  349. } else if(len_oos[j+(i*plotmax)] == 15 || len_oos[j+(i*plotmax)] == 16 ) {
  350. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
  351. } else {
  352. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
  353. }
  354.  
  355. if(frame%%15==14){
  356. p <- recordPlot()
  357.  
  358. if(frame <10){
  359. name <- paste('00000', frame, '.png', sep = '')
  360. }
  361. if(frame <100 && frame >=10){
  362. name <- paste('0000', frame, '.png', sep = '')
  363. }
  364. if(frame <1000 && frame >=100){
  365. name <- paste('000', frame, '.png', sep = '')
  366. }
  367. if(frame <10000 && frame >=1000){
  368. name <- paste('00', frame, '.png', sep = '')
  369. }
  370. if(frame >=10000){
  371. name <- paste('0', frame, '.png', sep = '')
  372. }
  373.  
  374. png(name, width=400, height=600)
  375.  
  376. replayPlot(p)
  377.  
  378. dev.off()
  379. }
  380.  
  381. frame <- frame + 1
  382.  
  383.  
  384.  
  385. }
  386. }
  387.  
  388.  
  389.  
  390.  
  391.  
  392. # library(magick)
  393. # my_command <- 'convert *.png -delay 0.2 -loop 1 brown.gif'
  394. # system(my_command)
  395. setwd("~/GIF Holder")
  396. files <- list.files(path="~/GIF Holder", pattern=".png",all.files=T, full.names=F, no.. = T)
  397. list_of_images = lapply(files, image_read)
  398.  
  399.  
  400.  
  401. image_list <- c()
  402.  
  403. for (i in 1:length(list_of_images)){
  404. image_list[i] <- list_of_images[i]
  405. }
  406.  
  407. animation <- image_animate(image_scale(image_join(image_list), "400x600"), fps = 100, dispose = "previous")
  408. image_write(animation, "oos.gif")
  409.  
  410. ### Switch to White ###
  411.  
  412. library(magick)
  413.  
  414. sample_me_white <- c(1:18)
  415.  
  416. plotmax <- 100
  417.  
  418. frame <- 0
  419.  
  420. plot(c(0, plotmax), c(0, plotmax), type= "n", xlab = "", ylab = "", axes=FALSE)
  421.  
  422. for(i in 0:(plotmax-1)){
  423. for(j in 1:plotmax){
  424. white_value <- sample(sample_me_white)[1]
  425. #print(j+(i*plotmax)) #This is an index from the 1th word to the 100th word.
  426. #print(len_oos[j+((i-1)*10)]) this works
  427. if(white_value == 1 || white_value == 2) {
  428. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_12, border=NA)
  429. } else if(white_value == 3 || white_value == 4 ) {
  430. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_34, border=NA)
  431. } else if(white_value == 5 || white_value == 6 ) {
  432. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_56, border=NA)
  433. } else if(white_value == 7 || white_value == 8 ) {
  434. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_78, border=NA)
  435. } else if(white_value == 9 || white_value == 10 ) {
  436. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_910, border=NA)
  437. } else if(white_value == 11 || white_value == 12 ) {
  438. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1112, border=NA)
  439. } else if(white_value == 13 || white_value == 14 ) {
  440. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1314, border=NA)
  441. } else if(white_value == 15 || white_value == 16 ) {
  442. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1516, border=NA)
  443. } else {
  444. rect(j-1, (plotmax-1)-i, j, (plotmax)-i, col=length_1718, border=NA)
  445. }
  446.  
  447. if(frame%%15==14){
  448. p <- recordPlot()
  449.  
  450. if(frame <10){
  451. name <- paste('00000', frame, '.png', sep = '')
  452. }
  453. if(frame <100 && frame >=10){
  454. name <- paste('0000', frame, '.png', sep = '')
  455. }
  456. if(frame <1000 && frame >=100){
  457. name <- paste('000', frame, '.png', sep = '')
  458. }
  459. if(frame <10000 && frame >=1000){
  460. name <- paste('00', frame, '.png', sep = '')
  461. }
  462. if(frame >=10000){
  463. name <- paste('0', frame, '.png', sep = '')
  464. }
  465.  
  466. png(name, width=400, height=600)
  467.  
  468. replayPlot(p)
  469.  
  470. dev.off()
  471. }
  472.  
  473. frame <- frame + 1
  474.  
  475. }
  476. }
  477.  
  478.  
  479.  
  480.  
  481. # library(magick)
  482. # my_command <- 'convert *.png -delay 0.2 -loop 1 brown.gif'
  483. # system(my_command)
  484. setwd("~/GIF Holder")
  485. files <- list.files(path="~/GIF Holder", pattern=".png",all.files=T, full.names=F, no.. = T)
  486. list_of_images = lapply(files, image_read)
  487.  
  488.  
  489.  
  490. image_list <- c()
  491.  
  492. for (i in 1:length(list_of_images)){
  493. image_list[i] <- list_of_images[i]
  494. }
  495.  
  496. animation <- image_animate(image_scale(image_join(image_list), "400x600"), fps = 100, dispose = "previous")
  497. image_write(animation, "white.gif")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement