{"id":32199,"date":"2015-01-05T00:06:43","date_gmt":"2015-01-05T00:06:43","guid":{"rendered":"http:\/\/rafaelfajardo.com\/portfolio\/ayearincode-for-a-while-now-ive-wanted-to-do\/"},"modified":"2018-12-06T12:44:15","modified_gmt":"2018-12-06T19:44:15","slug":"ayearincode-for-a-while-now-ive-wanted-to-do","status":"publish","type":"post","link":"https:\/\/rafaelfajardo.com\/portfolio\/ayearincode-for-a-while-now-ive-wanted-to-do\/","title":{"rendered":""},"content":{"rendered":"<div id='gallery-1' class='gallery galleryid-32199 gallery-columns-3 gallery-size-thumbnail'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https:\/\/rafaelfajardo.com\/portfolio\/ayearincode-for-a-while-now-ive-wanted-to-do\/attachment\/32200\/'><img loading=\"lazy\" decoding=\"async\" width=\"100\" height=\"100\" src=\"https:\/\/rafaelfajardo.com\/portfolio\/wp-content\/uploads\/tumblr_nhof1bpEFM1teec4eo1_500-100x100.gif\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" srcset=\"https:\/\/rafaelfajardo.com\/portfolio\/wp-content\/uploads\/tumblr_nhof1bpEFM1teec4eo1_500-100x100.gif 100w, https:\/\/rafaelfajardo.com\/portfolio\/wp-content\/uploads\/tumblr_nhof1bpEFM1teec4eo1_500-300x300.gif 300w\" sizes=\"auto, (max-width: 100px) 100vw, 100px\" \/><\/a>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n\n<p><a class=\"tumblr_blog\" href=\"http:\/\/ayearincode.tumblr.com\/post\/107156918596\/for-a-while-now-ive-wanted-to-do-some-work-with\">ayearincode<\/a>:<\/p>\n<blockquote>\n<p>For a while now I\u2019ve wanted to do some work with <a href=\"http:\/\/mathworld.wolfram.com\/CellularAutomaton.html\">cellular automaton<\/a> based image manipulation. This first step is based on a variation of Conway\u2019s <a href=\"http:\/\/mathworld.wolfram.com\/GameofLife.html\">game of life<\/a>. In my processing sketch below, you\u2019ll see that instead of using discrete state rules, I\u2019m using weighted probabilities to determine whether a cells is born, survives, or dies.<\/p>\n<pre>boolean[][] cells;\nint[][] tallies;\n\nvoid setup (){\n  size(100,100);\n  cells = new boolean[width][height];\n  tallies = new int[width][height];\n}\n\nvoid draw(){\n  evaluateCells();\n  updateCells();\n  renderGeneration();\n  saveFrame(\"output\/CA_001-###.PNG\");\n}\n\nvoid evaluateCells(){\n  tallies = new int[width][height];\n  for(int x = 0 ; x &lt; width ; x++){\n    for(int y = 0 ; y &lt; height ; y++){\n      tallies[x][y] = tallyNeighbors(x, y);      \n    }\n  }\n}\n\nint tallyNeighbors(int _x, int _y){ \n  int tally = 0;\n  int x = 0;\n  int y = 0;\n  for(int i = 0 ; i &lt; 3 ; i++){\n    for(int j = 0 ; j &lt; 3 ; j++){     \n      int neighbor_x = _x+(i-1);\n      int neighbor_y = _y+(j-1);      \n      if( neighbor_x &lt; 0){\n        x = width - 1;\n      } else if(neighbor_x == width){\n        x = 0;\n      } else {\n        x =  neighbor_x;\n      }\n      if( neighbor_y &lt; 0){\n        y = height - 1;\n      } else if(neighbor_y == height){\n        y = 0;\n      } else {\n        y = neighbor_y;\n      }    \n      if(cells[x][y] == true){\n        tally++;\n      }      \n    }\n  }\n  return tally;\n}\n\nvoid updateCells(){\n  boolean[][] newCells = new boolean[width][height];\n  for(int x = 0 ; x &lt; width ; x++){\n    for(int y = 0 ; y &lt; height ; y++){\n      if(cells[x][y] == true){\n        if(tallies[x][y] == 0){\n          newCells[x][y] = probability(0);\n        } else if (tallies[x][y] == 1){\n          newCells[x][y] = probability(25);\n        } else if (tallies[x][y] == 2){\n          newCells[x][y] = probability(50);\n        } else if (tallies[x][y] == 3){\n          newCells[x][y] = probability(100);\n        } else if (tallies[x][y] == 4){\n          newCells[x][y] = probability(100);\n        } else if (tallies[x][y] == 5){\n          newCells[x][y] = probability(50);\n        } else if (tallies[x][y] == 6){\n          newCells[x][y] = probability(25);\n        } else if (tallies[x][y] == 7){\n          newCells[x][y] = probability(10);\n        } else if (tallies[x][y] == 8){\n          newCells[x][y] = probability(0);\n        }\n      } else {\n        if(tallies[x][y] == 0){\n          newCells[x][y] = probability(0.5);\n        } else if (tallies[x][y] == 1){\n          newCells[x][y] = probability(1);\n        } else if (tallies[x][y] == 2){\n          newCells[x][y] = probability(50);\n        } else if (tallies[x][y] == 3){\n          newCells[x][y] = probability(75);\n        } else if (tallies[x][y] == 4){\n          newCells[x][y] = probability(100);\n        } else if (tallies[x][y] == 5){\n          newCells[x][y] = probability(100);\n        } else if (tallies[x][y] == 6){\n          newCells[x][y] = probability(75);\n        } else if (tallies[x][y] == 7){\n          newCells[x][y] = probability(25);\n        } else if (tallies[x][y] == 8){\n          newCells[x][y] = probability(0);\n        }\n      }\n    }\n  }\n  cells = newCells;\n}\n\nboolean probability(float _percentChance){\n  if( random(100) &lt; _percentChance ){\n    return true;\n  } else {\n    return false;\n  }\n}\n\nvoid renderGeneration(){ \n  loadPixels();\n  for( int x = 0 ; x &lt; width ; x++ ){\n    for( int y = 0 ; y &lt; height ; y++ ){\n      if(cells[x][y] == false){\n        pixels[x+(height*y)]=color(255);\n      } else {\n        pixels[x+(height*y)]=color(0);\n      }      \n    }\n  }\n  updatePixels(); \n}<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>ayearincode: For a while now I\u2019ve wanted to do some work with cellular automaton based image manipulation. This first step is based on a variation of Conway\u2019s game of life. In my processing sketch below, you\u2019ll see that instead of using discrete state rules, I\u2019m using weighted probabilities to determine whether a cells is born, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[1539],"class_list":["post-32199","post","type-post","status-publish","format-gallery","hentry","tag-emergent-digital-practices","post_format-post-format-gallery"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6PWot-8nl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/posts\/32199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/comments?post=32199"}],"version-history":[{"count":1,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/posts\/32199\/revisions"}],"predecessor-version":[{"id":32201,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/posts\/32199\/revisions\/32201"}],"wp:attachment":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/media?parent=32199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/categories?post=32199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/tags?post=32199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}