[
  {
    "path": ".gitignore",
    "content": "**/out/*\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\nCopyright (c) 2015 Baku Hashimoto\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "golly/export-otca-metapixels.py",
    "content": "from __future__ import division\r\n\r\nimport golly as g\r\nfrom PIL import Image\r\nfrom math import floor, ceil, log\r\nimport os\r\nimport json\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\nexportDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/golly-exported\"\r\n\r\nname = \"otca\"\r\n\r\nduration = None#8 #int( g.getgen() )\r\n\r\nisReset = True\r\n\r\nexpand = 0\r\nbound = [0, 0, 2048, 2048]\r\n\r\notcaInterval = 35328\r\notcaStep = 64\r\n\r\nstep = otcaInterval / otcaStep\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\ndef log( data ):\r\n\tg.note( json.dumps(data) )\r\n\r\ndef getPalette():\r\n\tcolors = g.getcolors()\r\n\r\n\tpalette = {}\r\n\r\n\tfor i in xrange( 0, len(colors), 4 ):\r\n\t\tstate = colors[ i ]\r\n\t\trVal = colors[ i + 1 ]\r\n\t\tgVal = colors[ i + 2 ]\r\n\t\tbVal = colors[ i + 3 ]\r\n\t\tpalette[ state ] = ( rVal, gVal, bVal )\r\n\r\n\treturn palette\r\n\r\ndef main( step = 1, start = 0 ):\r\n\tglobal bound, expand, duration\r\n\r\n\t# get selection and set to boundary\r\n\tbound = g.getselrect()\r\n\r\n\tif duration == None:\r\n\t\tduration = int( g.getgen() )\r\n\r\n\tif isReset:\r\n\t\tg.reset()\r\n\r\n\tif len( bound ) == 0:\r\n\t\tg.note( \"No selection.\" )\r\n\t\tg.exit()\r\n\r\n\t# get current Golly states\r\n\tif bound == None:\r\n\t\tbound[ 0 ] -= expand\r\n\t\tbound[ 1 ] -= expand\r\n\t\tbound[ 2 ] += expand * 2\r\n\t\tbound[ 3 ] += expand * 2\r\n\r\n\tleft   = bound[ 0 ]\r\n\ttop    = bound[ 1 ]\r\n\twidth  = bound[ 2 ]\r\n\theight = bound[ 3 ]\r\n\r\n\tpalette = getPalette()\r\n\tcells = g.getcells( bound )\r\n\tisMultiStates = len(cells) % 2 == 1\r\n\tcellW = 3 if isMultiStates else 2\r\n\r\n\t# create image and destination directory\r\n\tdstDir = \"%s/%s\" % (exportDir, name)\r\n\tif not os.path.exists( dstDir ):\r\n\t\tos.makedirs( dstDir )\r\n\t# else:\r\n\t# \tg.note( \"destination folder already exists\" )\r\n\t# \tg.exit()\r\n\r\n\t# log( cells )\r\n\r\n\tfor i in xrange( duration ):\r\n\t\tg.show( \"Processing... %d / %d\" % (i+1, duration) )\r\n\t\tg.run( 1 )\r\n\t\tg.update()\r\n\t\tcells = g.getcells( bound )\r\n\r\n\t\t# create image\r\n\t\timg = Image.new( \"RGB\", ( width, height ) )\r\n\t\tcellLen = int( floor( len(cells)/cellW ) * cellW )\r\n\r\n\t\tfor i in xrange( 0, cellLen, cellW ):\r\n\t\t\tx = cells[ i ]\r\n\t\t\ty = cells[ i + 1 ]\r\n\t\t\tstate = cells[ i + 2 ] if isMultiStates else 1\r\n\t\t\timg.putpixel( (x-left, y-top), palette[state] )\r\n\r\n\t\t# save\r\n\t\tgen = int( g.getgen() )\r\n\t\timg.save( \"%s/%s_%08d.png\" % (dstDir, name, gen) )\r\n\r\n#---------------------------------------------\r\n# main\r\n\r\nmain()\r\n\r\n\r\n"
  },
  {
    "path": "golly/export_large.py",
    "content": "from __future__ import division\r\n\r\nimport golly as g\r\nfrom PIL import Image\r\nfrom math import floor, ceil, log\r\nimport os\r\nimport json\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\nexportDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/golly-exported/otca\"\r\n\r\n\r\n\r\n# common\r\n# duration = 147 #int( g.getgen() )\r\n\r\notcaDur = 35328\r\nworldWidth = 30730\r\n\r\n# 1/16x (1920)\r\nduration = 64\r\nratio = 8\r\nsubdiv = 1\r\nskipBound = 1\r\n# skipFrame = int(genDur / duration)\r\n\r\n# ad\r\n# name = \"ad_x%02d\" % ratio\r\n# bound = [4, 3, 1, 1]\r\n\r\n# da\r\n# name = \"da_x%02d\" % ratio\r\n# bound = [5, 2, 1, 1]\r\n\r\n# dd\r\n# name = \"dd_x%02d\" % ratio\r\n# bound = [0, 0, 1, 1]\r\n\r\n# aa\r\nname = \"aa_x%02d\" % ratio\r\nbound = [8, 3, 1, 1]\r\n\r\nbound[0] -= 8\r\nbound[1] -= 8\r\n\r\n# 1/8x\r\n# ratio = 8\r\n# subdiv = 2\r\n# skipBound = 2\r\n# skipFrame = 1000\r\n# bound = [2, 2, 11, 11]\r\n\r\n# 1/4x\r\n# ratio = 4\r\n# subdiv = 2\r\n# skipBound = 2\r\n# skipFrame = 1000\r\n# bound = [2, 2, 9, 8]\r\n\r\n\r\n# 1/2x\r\n# ratio = 2\r\n# subdiv = 2\r\n# skipBound = 2\r\n# skipFrame = 1000\r\n# bound = [3, 3, 6, 6]\r\n\r\n\r\n# 1/1x\r\n# ratio = 1\r\n# subdiv = 1\r\n# skipBound = 1\r\n# skipFrame = 1\r\n\r\n\r\n# dead or alive\r\n# bound = [0, 0, 1, 1]\r\n# mode = \"dead\"\r\n\r\n# bound = [2, 5, 1, 1]\r\n# mode = \"aliv\"\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\ndef log( data ):\r\n\tg.note( json.dumps(data) )\r\n\r\ndef getPalette():\r\n\tcolors = g.getcolors()\r\n\r\n\tpalette = {}\r\n\r\n\tfor i in xrange( 0, len(colors), 4 ):\r\n\t\tstate = colors[ i ]\r\n\t\trVal = colors[ i + 1 ]\r\n\t\tgVal = colors[ i + 2 ]\r\n\t\tbVal = colors[ i + 3 ]\r\n\t\tpalette[ state ] = ( rVal, gVal, bVal )\r\n\r\n\treturn palette\r\n\r\ndef main( step = 1, start = 0 ):\r\n\tglobal bound, expand\r\n\r\n\tg.reset()\r\n\tg.run(otcaDur)\r\n\r\n\t# get current Golly states\r\n\tcellWidth = 2048\r\n\tbound[ 0 ] = bound[0] * cellWidth\r\n\tbound[ 1 ] = bound[1] * cellWidth\r\n\tbound[ 2 ] = bound[2] * cellWidth\r\n\tbound[ 3 ] = bound[3] * cellWidth\r\n\r\n\tleft   = bound[ 0 ]\r\n\ttop    = bound[ 1 ]\r\n\twidth  = bound[ 2 ]\r\n\theight = bound[ 3 ]\r\n\r\n\tpalette = getPalette()\r\n\tcells = g.getcells( [0, 0, 1, 1] )\r\n\tisMultiStates = len(cells) % 2 == 1\r\n\tcellW = 2\r\n\r\n\t# create image and destination directory\r\n\tdstDir = \"%s/%s\" % (exportDir, name)\r\n\tif not os.path.exists( dstDir ):\r\n\t\tos.makedirs( dstDir )\r\n\t# else:\r\n\t# \tg.note( \"destination folder already exists\" )\r\n\t# \tg.exit()\r\n\r\n\timgWidth = int( width / ratio )\r\n\timgHeight = int ( height / ratio )\r\n\r\n\tboundWidth = ratio / subdiv\r\n\r\n\r\n\tpb = [0, 0, boundWidth, boundWidth] # pixel bound\r\n\r\n\ti = x = y = bx = by = 0\r\n\r\n\tframeCount = 0\r\n\tstep = int(otcaDur / duration)\r\n\r\n\tfor i in xrange(0, duration):\r\n\t\tg.show(\"Processing... %d / %d\" % (i+1, duration))\r\n\t\tg.run(step)\r\n\t\tg.update()\r\n\r\n\t\timg = Image.new(\"RGB\", (imgWidth, imgHeight))\r\n\r\n\t\tfor y in xrange(imgHeight):\r\n\t\t\tfor x in xrange(imgWidth):\r\n\r\n\t\t\t\tfor by in xrange(0, subdiv, skipBound):\r\n\t\t\t\t\tfor bx in xrange(0, subdiv, skipBound):\r\n\t\t\t\t\t\tpb[0] = left + x * ratio + bx * boundWidth\r\n\t\t\t\t\t\tpb[1] = top  + y * ratio + by * boundWidth\r\n\t\t\t\t\t\tcells = g.getcells(pb)\r\n\t\t\t\t\t\tif len( cells ) > 0:\r\n\t\t\t\t\t\t\timg.putpixel((x, y), (255, 255, 255))\r\n\t\t\t\t\t\t\tbreak\r\n\r\n\t\t\t\t\telse:\r\n\t\t\t\t\t\tcontinue\r\n\t\t\t\t\tbreak\r\n\r\n\t\t# save\r\n\t\t# img.save( \"%s/%s_%02dx_%s_%08d.png\" % (dstDir, name, ratio, mode, i) )\r\n\t\t# img.save( \"%s/%s_%02dx_%08d.png\" % (dstDir, name, ratio, i) )\r\n\t\timg.save(\"%s/%s_%04d.png\" % (dstDir, name, i))\r\n\r\n\r\n\tg.show(\"Done.\")\r\n\r\n\r\n\r\n#---------------------------------------------\r\n# main\r\n\r\nmain()\r\n\r\n\r\n"
  },
  {
    "path": "golly/golly_python_script_to_output_meta-life_animation.py",
    "content": "from __future__ import division\r\n\r\nimport golly as g\r\nfrom PIL import Image\r\nfrom math import floor, ceil, log\r\nimport os\r\nimport json\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\nexportDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/golly-exported\"\r\n\r\nname = \"galaxy-sample\"\r\n\r\nduration = 8 #int( g.getgen() )\r\n\r\nisReset = True\r\n\r\nexpand = 0\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\ndef log( data ):\r\n\tg.note( json.dumps(data) )\r\n\r\ndef getPalette():\r\n\tcolors = g.getcolors()\r\n\r\n\tpalette = {}\r\n\r\n\tfor i in xrange( 0, len(colors), 4 ):\r\n\t\tstate = colors[ i ]\r\n\t\trVal = colors[ i + 1 ]\r\n\t\tgVal = colors[ i + 2 ]\r\n\t\tbVal = colors[ i + 3 ]\r\n\t\tpalette[ state ] = ( rVal, gVal, bVal )\r\n\r\n\treturn palette\r\n\r\ndef main( step = 1, start = 0 ):\r\n\tglobal bound, expand, duration\r\n\r\n\t# get selection and set to boundary\r\n\tbound = g.getselrect()\r\n\r\n\tif duration == None:\r\n\t\tduration = int( g.getgen() )\r\n\r\n\tif isReset:\r\n\t\tg.reset()\r\n\r\n\tif len( bound ) == 0:\r\n\t\tg.note( \"No selection.\" )\r\n\t\tg.exit()\r\n\r\n\t# get current Golly states\r\n\tbound[ 0 ] -= expand\r\n\tbound[ 1 ] -= expand\r\n\tbound[ 2 ] += expand * 2\r\n\tbound[ 3 ] += expand * 2\r\n\r\n\tleft   = bound[ 0 ]\r\n\ttop    = bound[ 1 ]\r\n\twidth  = bound[ 2 ]\r\n\theight = bound[ 3 ]\r\n\r\n\tpalette = getPalette()\r\n\tcells = g.getcells( bound )\r\n\tisMultiStates = len(cells) % 2 == 1\r\n\tcellW = 3 if isMultiStates else 2\r\n\r\n\t# create image and destination directory\r\n\tdstDir = \"%s/%s\" % (exportDir, name)\r\n\tif not os.path.exists( dstDir ):\r\n\t\tos.makedirs( dstDir )\r\n\t# else:\r\n\t# \tg.note( \"destination folder already exists\" )\r\n\t# \tg.exit()\r\n\r\n\t# log( cells )\r\n\r\n\tfor i in xrange( duration ):\r\n\t\tg.show( \"Processing... %d / %d\" % (i+1, duration) )\r\n\t\tg.run( 1 )\r\n\t\tg.update()\r\n\t\tcells = g.getcells( bound )\r\n\r\n\t\t# create image\r\n\t\timg = Image.new( \"RGB\", ( width, height ) )\r\n\t\tcellLen = int( floor( len(cells)/cellW ) * cellW )\r\n\r\n\t\tfor i in xrange( 0, cellLen, cellW ):\r\n\t\t\tx = cells[ i ]\r\n\t\t\ty = cells[ i + 1 ]\r\n\t\t\tstate = cells[ i + 2 ] if isMultiStates else 1\r\n\t\t\timg.putpixel( (x-left, y-top), palette[state] )\r\n\r\n\t\t# save\r\n\t\tgen = int( g.getgen() )\r\n\t\timg.save( \"%s/%s_%08d.png\" % (dstDir, name, gen) )\r\n\r\n#---------------------------------------------\r\n# main\r\n\r\nmain()\r\n\r\n\r\n"
  },
  {
    "path": "golly/last-shiki.py",
    "content": "from __future__ import division\r\n\r\nimport golly as g\r\nfrom PIL import Image\r\nfrom math import floor, ceil, log\r\nimport os\r\nimport json\r\nimport datetime\r\nimport locale\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\nsrcPath = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ae/shiki_3.tif\"\r\ndstDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/last-shiki\"\r\n\r\nexpand = 100\r\n\r\nrepeat = 20\r\n\r\ninterval = 3\r\n\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\ndef log( data ):\r\n\tg.note( json.dumps(data) )\r\n\r\n\r\ndef main( step = 1, start = 0 ):\r\n\r\n\t# set dir name from current date\r\n\td = datetime.datetime.today()\r\n\r\n\tdirName = \"shiki_%02d-%02d-%02d-%02d\" % (d.day, d.hour, d.minute, d.second)\r\n\r\n\t# create directory\r\n\texportDir = \"%s/%s\" % (dstDir, dirName)\r\n\tif not os.path.exists( exportDir ):\r\n\t\tos.makedirs( exportDir )\r\n\r\n\r\n\t# get bound\r\n\r\n\tsize = getImageSize( srcPath )\r\n\r\n\tbound = [\r\n\t\t-expand,\r\n\t\t-expand,\r\n\t\tsize[0] + expand * 2,\r\n\t\tsize[1] + expand * 2\r\n\t]\r\n\r\n\t# loop\r\n\r\n\tfor f in xrange( repeat ):\r\n\t\tg.show( \"Processing... %d / %d\" % (f+1, repeat) )\r\n\t\t\r\n\t\tloadImage( srcPath )\r\n\t\tg.run( 1 )\r\n\t\tg.update()\r\n\r\n\t\tfor i in xrange( interval ):\r\n\t\t\tg.run( 1 )\r\n\t\t\tg.update()\r\n\t\t\tframe = f * interval + i\r\n\t\t\tsaveImage( bound, \"%s/%s/%s_%06d.png\" % (dstDir, dirName, dirName, frame) )\r\n\r\n\r\n\r\ndef saveImage( bound, path ):\r\n\r\n\tleft = bound[0]\r\n\ttop = bound[1]\r\n\twidth = bound[2]\r\n\theight = bound[3]\r\n\r\n\tcellW = 2\r\n\r\n\t# create image\r\n\timg = Image.new( \"RGB\", ( width, height ) )\r\n\tcells = g.getcells( bound )\r\n\tcellLen = len( cells )\r\n\r\n\twhite = ( 255, 255, 255 )\r\n\r\n\tfor i in xrange( 0, cellLen, 2 ):\r\n\t\tx = cells[ i ]\r\n\t\ty = cells[ i + 1 ]\r\n\t\timg.putpixel( (x-left, y-top), (255, 255, 255) )\r\n\r\n\t# save\r\n\timg.save( path )\r\n\r\n\r\n\r\ndef getImageSize( path ):\r\n\r\n\timg = Image.open( path )\r\n\treturn img.size\r\n\r\n\r\ndef loadImage( path ):\r\n\r\n\timg = Image.open( path )\r\n\tsize = img.size\r\n\r\n\tc = None\r\n\tstate = None\r\n\r\n\tfor y in xrange( 0, size[1] ):\r\n\t\tfor x in xrange( 0, size[0] ):\r\n\r\n\t\t\tc = img.getpixel( (x, y) )\r\n\r\n\t\t\tif c[0] > 128:\r\n\t\t\t\tg.setcell( x, y, 1 )\r\n\r\n#---------------------------------------------\r\n# main\r\n\r\nmain()\r\n\r\n\r\n"
  },
  {
    "path": "golly/load-image.py",
    "content": "from __future__ import division\r\n\r\nimport golly as g\r\nfrom PIL import Image\r\nfrom math import floor, ceil, log\r\nimport os\r\nimport json\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\nsrcPath = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ae/a_frame.png\"\r\n\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\ndef log( data ):\r\n\tg.note( json.dumps(data) )\r\n\r\n\r\ndef main( step = 1, start = 0 ):\r\n\t\r\n\timg = Image.open( srcPath )\r\n\tsize = img.size\r\n\r\n\tfor y in xrange( 0, size[1] ):\r\n\t\tfor x in xrange( 0, size[0] ):\r\n\r\n\t\t\tc = img.getpixel( (x, y) )\r\n\r\n\t\t\tstate = 1 if c[0] > 128 else 0\r\n\t\t\tg.setcell( x, y, state )\r\n\r\n\r\n\r\n#---------------------------------------------\r\n# main\r\n\r\nmain()\r\n\r\n\r\n# 0.7019105 * ( 114.953 * tan( 53.13/ 180 * pi / 2) )"
  },
  {
    "path": "golly/rotate.py",
    "content": "from __future__ import division\r\n\r\nimport golly as g\r\nfrom PIL import Image\r\nfrom math import floor, ceil, log\r\nimport os\r\nimport json\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\n\r\n#---------------------------------------------\r\n# settings\r\n\r\ndef log( data ):\r\n\tg.note( json.dumps(data) )\r\n\r\ndef main():\r\n\r\n\t# get selection and set to boundary\r\n\tbound = g.getselrect()\r\n\tif len( bound ) == 0:\r\n\t\tg.note( \"No selection.\" )\r\n\t\tg.exit()\r\n\r\n\t# get current Golly states\r\n\tleft   = bound[ 0 ]\r\n\ttop    = bound[ 1 ]\r\n\twidth  = bound[ 2 ]\r\n\theight = bound[ 3 ]\r\n\r\n\tfor y in xrange( 0, height ):\r\n\t\tfor x in xrange( 0, width ):\r\n\r\n\t\t\tstate = g.getcell( left + x, top + y )\r\n\t\t\tg.setcell( height - y - 600, x - 600, state )\r\n\r\n#---------------------------------------------\r\n# main\r\n\r\nmain()\r\n\r\n\r\n"
  },
  {
    "path": "golly/step_generation.py",
    "content": "from __future__ import division\r\n\r\nimport golly as g\r\n\r\n\r\ndef main():\r\n\r\n\tg.run(35328)\r\n\r\n\r\n\r\n# def main():\r\n\r\n# \tw = 2048\r\n\r\n# \t# g.select([0, 0, w, w])\r\n\r\n# \t# g.select([-w, -w, w, w])\r\n\t\r\n\r\n#---------------------------------------------\r\n# main\r\n\r\nmain()\r\n\r\n\r\n"
  },
  {
    "path": "others/ResizeBorder.pbk",
    "content": "<languageVersion : 1.0;>\r\n\r\nkernel ResizeBorder\r\n<   namespace : \"bk\";\r\n    vendor : \"Baku Hashimoot\";\r\n    version : 1;\r\n>\r\n{\r\n    input image4 src;\r\n    output pixel4 dst;\r\n\r\n    parameter float width\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       1.0;\r\n        defaultValue:   1.0;\r\n        displayName:    \"Width\";\r\n    >;\r\n    \r\n    parameter float height\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       1.0;\r\n        defaultValue:   1.0;\r\n        displayName:    \"Height\";\r\n    >;\r\n    \r\n    parameter float left\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Left\";\r\n    >;\r\n    \r\n    parameter float right\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Right\";\r\n    >;\r\n    \r\n    parameter float top\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Top\";\r\n    >;\r\n    \r\n    parameter float bottom\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Bottom\";\r\n    >;\r\n    \r\n    parameter float2 origin\r\n    <\r\n        minValue:       float2( 0.0, 0.0 );\r\n        maxValue:       float2( 1.0, 1.0 );\r\n        defaultValue:   float2( 0.0, 0.0 );\r\n        displayName:    \"Origin\";\r\n    >;\r\n    \r\n    parameter float2 size\r\n    <\r\n        minValue:       float2( 0.0, 0.0 );\r\n        maxValue:       float2( 2048.0, 2048.0 );\r\n        defaultValue:   float2( 100.0, 100.0 );\r\n        displayName:    \"Input Size\";\r\n    >;\r\n    \r\n    float map( float x, float inMin, float inMax, float outMin, float outMax ) {\r\n    \r\n        return ( x - inMin ) * ( outMax - outMin ) / ( inMax - inMin ) + outMin;\r\n    \r\n    }\r\n    \r\n    float resize( float x, float w, float xi, float xo, float bi, float bo ) {\r\n    \r\n        float xm;\r\n    \r\n        if ( xo - xi >= bi + bo ) {\r\n        \r\n            if ( x < xi + bi ) {\r\n                \r\n                xm = x - xi;\r\n                \r\n            } else if ( x < xo - bo ) {\r\n            \r\n                xm = x - xi; //map( x, xi + bi, xo - bo, bi, w - bo );\r\n                \r\n                \r\n            } else {\r\n            \r\n                xm = w - ( xo - x ); //map( x, xo - bo, xo, w - bo, w );\r\n                \r\n            }\r\n        \r\n        } else {\r\n        \r\n            if ( x < (xi+xo) / 2.0 ) {\r\n            \r\n                xm = x - xi;\r\n            \r\n            } else {\r\n            \r\n                xm = w - ( xo - x );\r\n            \r\n            }\r\n        \r\n        }\r\n        \r\n        return xm;\r\n    }\r\n\r\n    void evaluatePixel()\r\n    {\r\n        float2 pos = outCoord();\r\n        \r\n        float2 t = float2( width, height );\r\n        \r\n        float2 rectA = origin * size - origin * size * t;\r\n        float2 rectB = origin * size + ( float2(1.0, 1.0) - origin ) * size * t;\r\n        \r\n        pos.x = resize( pos.x, size.x, rectA.x, rectB.x, left, right );\r\n        pos.y = resize( pos.y, size.y, rectA.y, rectB.y, top, bottom );\r\n        \r\n        dst = sampleNearest( src, pos );\r\n        \r\n    }\r\n}\r\n"
  },
  {
    "path": "others/ResizeBorderTrim.pbk",
    "content": "<languageVersion : 1.0;>\r\n\r\nkernel ResizeBorderTrim\r\n<   namespace : \"bk\";\r\n    vendor : \"Baku Hashimoto\";\r\n    version : 1;\r\n>\r\n{\r\n    input image4 src;\r\n    output pixel4 dst;\r\n\r\n    parameter float trimTop\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       2048.0;\r\n        defaultValue:   0.0;\r\n        displayName:    \"Trim Top\";\r\n    >;\r\n    \r\n    parameter float trimRight\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       2048.0;\r\n        defaultValue:   0.0;\r\n        displayName:    \"Trim Right\";\r\n    >;\r\n    \r\n    parameter float trimBottom\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       2048.0;\r\n        defaultValue:   0.0;\r\n        displayName:    \"Trim Bottom\";\r\n    >;\r\n    \r\n    parameter float trimLeft\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       2048.0;\r\n        defaultValue:   0.0;\r\n        displayName:    \"Trim Left\";\r\n    >;\r\n    \r\n    parameter float top\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Top\";\r\n    >;\r\n   \r\n    parameter float right\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Right\";\r\n    >;\r\n    \r\n    parameter float bottom\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Bottom\";\r\n    >;\r\n    \r\n    parameter float left\r\n    <\r\n        minValue:       0.0;\r\n        maxValue:       100.0;\r\n        defaultValue:   30.0;\r\n        displayName:    \"Border Left\";\r\n    >;\r\n    \r\n    parameter float2 origin\r\n    <\r\n        minValue:       float2( 0.0, 0.0 );\r\n        maxValue:       float2( 1.0, 1.0 );\r\n        defaultValue:   float2( 0.0, 0.0 );\r\n        displayName:    \"Origin\";\r\n    >;\r\n    \r\n    parameter float2 size\r\n    <\r\n        minValue:       float2( 0.0, 0.0 );\r\n        maxValue:       float2( 2048.0, 2048.0 );\r\n        defaultValue:   float2( 100.0, 100.0 );\r\n        displayName:    \"Input Size\";\r\n    >;\r\n    \r\n    float map( float x, float inMin, float inMax, float outMin, float outMax ) {\r\n    \r\n        return ( x - inMin ) * ( outMax - outMin ) / ( inMax - inMin ) + outMin;\r\n    \r\n    }\r\n    \r\n    float resize( float x, float w, float xi, float xo, float bi, float bo ) {\r\n    \r\n        float xm;\r\n    \r\n        if ( xo - xi >= bi + bo ) {\r\n        \r\n            if ( x < xi + bi ) {\r\n                \r\n                xm = x - xi;\r\n                \r\n            } else if ( x < xo - bo ) {\r\n            \r\n                xm = x - xi; //map( x, xi + bi, xo - bo, bi, w - bo );\r\n                \r\n                \r\n            } else {\r\n            \r\n                xm = w - ( xo - x ); //map( x, xo - bo, xo, w - bo, w );\r\n                \r\n            }\r\n        \r\n        } else {\r\n        \r\n            if ( x < (xi+xo) / 2.0 ) {\r\n            \r\n                xm = x - xi;\r\n            \r\n            } else {\r\n            \r\n                xm = w - ( xo - x );\r\n            \r\n            }\r\n        \r\n        }\r\n        \r\n        return xm;\r\n    }\r\n\r\n    void evaluatePixel()\r\n    {\r\n        float2 pos = outCoord();\r\n        \r\n        float2 rectA = float2( trimLeft, trimTop );\r\n        float2 rectB = float2( size.x - trimRight, size.y - trimBottom );\r\n        \r\n        pos.x = resize( pos.x, size.x, rectA.x, rectB.x, left, right );\r\n        pos.y = resize( pos.y, size.y, rectA.y, rectB.y, top, bottom );\r\n        \r\n        dst = sampleNearest( src, pos );\r\n        \r\n    }\r\n}\r\n"
  },
  {
    "path": "others/p5.sh",
    "content": "#!/bin/sh\n\nfunction usage_exit() {\n\techo \"Usage: p5 sketch-path [--args sketch-args..]\"\n\texit 1\n}\n\n\n# get full path of sketch directory\nif [ \"$1\" == \"\" -o \"$1\" == \"--args\" ]; then\n\tusage_exit\nfi\nsketch=$1\nabsPath=$(cd $(dirname $1) && pwd)/$(basename $1)\n\n# extract arguments\nshift\nif [ \"$1\" == \"--args\" ]; then\n\tshift\nelse\n\twhile [ \"$1\" != \"\" ]\n\tdo\n\t\tshift\n\tdone\n\nfi\n\n# run sketch\nprocessing-java --sketch=${absPath} --run ${@}"
  },
  {
    "path": "p5/cell_division_test/CellDivision.pde",
    "content": "\n\nfloat gaussianRange = 4;\nfloat detail = 0.05;\nint minGen = 3;\n\n\nPGraphics divideCell( int w, int h, int minWidth ) {\n\n    ArrayList< Cell > cells = new ArrayList< Cell >();\n    ArrayList< Cell > divided = new ArrayList< Cell >();\n\n    float tx, ty;\n    boolean proceed;\n    int px, py;\n    Cell c;\n    Cell[] nc = new Cell[ 4 ];\n    PGraphics g = createGraphics( w, h );\n\n    cells.add( new Cell( 0, 0, w, h ) );\n\n    while ( cells.size() > 0 ) {\n\n        println( \"start\" + cells.get(0).generation );\n\n        for ( int i = cells.size() - 1; i >= 0; i-- ) {\n\n            c = cells.get( i );\n\n            //c.print();\n            //println(\" -> \");\n\n            // divide vertical\n            tx = ( c.w / 2 - minWidth ) / gaussianRange;\n            px = int( c.w / 2 + randomGaussian() * tx );\n            \n            ty = ( c.h / 2 - minWidth ) / gaussianRange;\n            py = int( c.h / 2 + randomGaussian() * ty );\n\n            // 0 1\n            // 2 3\n            nc[0] = new Cell( c.x, c.y, px, py );\n            nc[1] = new Cell( c.x + px, c.y, c.w - px, py );\n            nc[2] = new Cell( c.x, c.y + py, px, c.h - py );\n            nc[3] = new Cell( c.x + px, c.y + py, c.w - px, c.h - py );\n            \n            for ( int j = 0; j < nc.length; j++ ) {\n                \n                nc[j].generation = c.generation + 1;\n                \n                if ( nc[j].generation < minGen ) {\n                    \n                    proceed = true;\n                \n                } else {\n                \n                    proceed = random(1) > detail;\n                \n                }\n            \n                if ( nc[j].w >= minWidth * 2 && nc[j].h >= minWidth * 2 && proceed ) {\n                    cells.add( nc[j] );\n                } else {\n                    divided.add( nc[j] );\n                }\n            }\n            \n            cells.remove( i );\n        }\n\n        g.beginDraw();\n        g.background( 0 );\n        g.noStroke();\n\n        for ( int i = 0; i < cells.size(); i++ ) {\n\n            c = cells.get( i );\n            g.fill( c.fill );\n            g.rect( c.x, c.y, c.w, c.h );\n        }\n\n        g.endDraw();\n\n        image( g, 0, 0 );\n    }\n\n    // draw\n\n    g.beginDraw();\n    g.background( 0 );\n    g.noStroke();\n\n    for ( int i = 0; i < divided.size(); i++ ) {\n\n        c = divided.get( i );\n        g.fill( c.fill );\n        g.rect( c.x, c.y, c.w, c.h );\n    }\n\n    g.endDraw();\n\n    return g;\n}\n\n\nclass Cell {\n\n    int x, y, w, h;\n    color fill;\n    int generation;\n\n    Cell( int _x, int _y, int _w, int _h ) {\n\n        this.x = _x;\n        this.y = _y;\n        this.w = _w;\n        this.h = _h;\n        this.fill = color( random(255), random(255), random(255) );\n        this.generation = 0;\n    }\n\n    void print() {\n\n        println( this.x + \"\\t\" + this.y + \"\\t\" + this.w + \"\\t\" + this.h );\n    }\n}"
  },
  {
    "path": "p5/cell_division_test/cell_division_test.pde",
    "content": "\nint w = 100 + 24;\n\nvoid setup() {\n    size( 640, 640 );\n    PGraphics cell = divideCell( width, height, 10 );\n\n    image( cell, 0, 0 );\n}"
  },
  {
    "path": "p5/cell_division_test/util.pde",
    "content": "\n\n\nvoid changeWindowSize(int w, int h) {\n\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n    \n}"
  },
  {
    "path": "p5/cubist/cubist.pde",
    "content": "import java.util.Collections;\nimport ffff.*;\n\n//---------------------------------------------\n// config\n\nString srcDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist/src\";\nString dstDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist/out\";\n\nString filename = \"cell_a_4\";\n\nint duration = 24;\n\nint inRand = 2;\n\nint moveWidth = 600;\nfloat moveAmpOpposite = 0.7;\n\nfloat moveRand = 0.5; \n\n//---------------------------------------------\n// main\n\nPImage src;\n\nboolean[][] filled; \n\nArrayList< Rect > rects = new ArrayList< Rect >();\nArrayList< UIRect > uiRects = new ArrayList< UIRect >();\n\nint[] inFrames;\nRect[] fromRects, toRects;\n\n\nvoid setup() {\n\n    noSmooth();\n    \n    ArrayList< String > arguments = getArgs();\n    \n    if ( arguments.size() > 0 ) {\n        \n        filename = arguments.get( 0 );\n    }\n    \n\n    src = loadImage( srcDir + \"/\" + filename + \".png\" );\n\n    changeWindowSize( src.width, src.height );\n\n    filled = new boolean[ width ][ height ];\n\n    // initialize fiiled\n    for ( int y = 0; y < height; y++ ) {\n        for ( int x = 0; x < width; x++ ) {\n            filled[x][y] = src.get( x, y ) == color( 0 );\n        }\n    }\n\n    // search\n    searchRect( 1.5, 20 );\n    searchRect( max( width, height ), 3 );\n\n    loadUI();\n    uiRects = generateUIRects( rects );\n    \n    // shuffle\n    Collections.shuffle( uiRects );\n    \n    // calc in frame and determine move rect\n    inFrames = new int[ uiRects.size() ];\n    fromRects = new Rect[ uiRects.size() ];\n    toRects = new Rect[ uiRects.size() ];\n    \n    UIRect ur;\n    \n    for ( int i = 0; i < uiRects.size(); i++ ) {\n        \n        ur = uiRects.get( i );\n        \n        int dir = int( random( 4 ) );\n        int mfw = int( 600 * (1 + random( moveRand ) ) );   // move width ( fromt )\n        int mow = int( mfw * moveAmpOpposite );\t\t  // move width ( opposite )\n        \n        toRects[i] = new Rect( ur.x, ur.y, ur.w, ur.h );\n        inFrames[i] = int( random( inRand ) );\n        \n        if ( dir == 0 ) { // N\n            \n            fromRects[i] = new Rect( ur.x, ur.y - mfw, ur.w, ur.h + mfw - mow );\n            \n        } else if ( dir == 1 ) { // E\n        \n            fromRects[i] = new Rect( ur.x + mow, ur.y, ur.w + mfw - mow, ur.h );\n            \n        } else if ( dir == 2 ) { // S\n        \n            fromRects[i] = new Rect( ur.x, ur.y + mow, ur.w, ur.h + mfw - mow );\n            \n        } else if ( dir == 3 ) { // W\n        \n            fromRects[i] = new Rect( ur.x - mfw, ur.y, ur.w + mfw - mow, ur.h );\n            \n        }   \n    }\n}\n\n\nvoid draw() {\n    \n    // save Color map\n    if ( frameCount == 1 ) {\n        background( 0 );\n        noStroke();\n        \n        for ( int i = 0; i < uiRects.size(); i++ ) {\n            fill( random(255), random(255), random(255) );\n            rect( uiRects.get( i ).x, uiRects.get( i ).y, uiRects.get( i ).w, uiRects.get( i ).h );\n        }\n        \n        saveFrame( dstDir + \"/\" + filename + \"/\" + filename + \"_map.png\" );\n    }\n    \n    background( 0 );\n    noStroke();\n    \n    UIRect ur;\n    float t;\n\n    for ( int i = 0; i < uiRects.size(); i++ ) {\n        \n        ur = uiRects.get( i );\n        \n        if ( inFrames[i] < frameCount ) {\n            \n            // update\n            t = min( float( frameCount - inFrames[i] - 1) / duration, 1.0 );\n            t = 1 - t;\n            \n            t = pow( t, 3 );\n            t = 1 - t;\n            \n            ur.interpolate( t, fromRects[i], toRects[i] );\n            ur.draw();\n        }\n        \n        //break;\n    }\n    \n    saveFrame( dstDir + \"/\" + filename + \"/\" + filename + \"_####.png\" );\n    \n    if ( frameCount > duration + 2 ) {\n        exit();\n    }\n}"
  },
  {
    "path": "p5/cubist/rect.pde",
    "content": "\nvoid searchRect( float maxAspect, int minWidth ) {\n    \n    for ( int y = 0; y < height; y++ ) {\n        for ( int x = 0; x < width; x++ ) {\n            \n            if ( !filled[x][y] ) {\n                \n                // start searching\n                Rect r = findRect( x, y );\n                \n                if ( r.w >= minWidth && r.h >= minWidth && r.aspect() <= maxAspect && 1.0 / r.aspect() <= maxAspect ) {\n                \n                    checkSearchedRect( r );\n                    rects.add( r );\n                }\n            }\n        }\n    }\n    \n    println( \"end search: aspect=\", maxAspect, \"minWidth=\", minWidth ); \n}\n\nvoid checkSearchedRect( Rect r ) {\n    \n    // fill\n    for ( int _y = r.y; _y <= r.bottom(); _y++ ) {\n        for ( int _x = r.x; _x <= r.right(); _x++ ) {\n            filled[_x][_y] = true;\n        }\n    }\n    \n}\n\nRect findRect( int x, int y ) {\n    \n    Rect r = new Rect( x, y, 1, 1 );\n    Rect outer = new Rect();\n    \n    // expand top\n    \n    /*outer.copy( r );\n    do {\n        outer.y -= 1;\n        outer.h += 2;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );*/\n\n    // expand right\n    outer.copy( r );\n    do {\n        outer.w += 1;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );\n    \n    // expand bottom\n    outer.copy( r );\n    do {\n        outer.h += 1;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );\n    \n    /*// expand left\n    outer.copy( r );\n    do {\n        outer.x -= 1;\n        outer.w += 2;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );*/\n    \n    return r;\n}\n\nboolean searchRectEdge( Rect r ) {\n    \n    \n    if ( r.x < 0 || r.y < 0 || r.right() >= width || r.bottom() >= height ) {\n        return false;\n    }\n    \n    // horizontal edge\n    for ( int x = r.x; x <= r.right(); x++ ) {\n        if ( filled[x][r.y] || filled[x][r.bottom()] ) {\n            return false;\n        }\n    }\n    \n    // vertical edge\n    for ( int y = r.y; y <= r.bottom(); y++ ) {\n        if( filled[r.x][y] || filled[r.right()][y] ) {\n            return false;\n        }\n    }\n    \n    return true;\n}"
  },
  {
    "path": "p5/cubist/ui.pde",
    "content": "\nString partsDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist/parts\";\n\nArrayList< UI > uiList = new ArrayList< UI >();\n    \n    \nvoid loadUI() {\n\n    // smaller --> bigger\n    uiList.add( new UI( partsDir+\"/dot.png\", 1, 1, 1, 1 ) );\n    uiList.add( new UI( partsDir+\"/button.png\", 2, 2, 2, 2 ) );\n    uiList.add( new UI( partsDir+\"/icon.png\", 6, 6, 24, 6 ) );\n    uiList.add( new UI( partsDir+\"/menu.png\", 19, 2, 1, 19 ) );\n    uiList.add( new UI( partsDir+\"/button_b.png\", 8, 8, 8, 8 ) );\n    uiList.add( new UI( partsDir+\"/window_a.png\", 31, 54, 31, 31 ) );\n    \n    \n}\n\nArrayList< UIRect > generateUIRects( ArrayList< Rect > rects ) {\n    \n    Rect r;\n    UI ui= new UI();\n    ArrayList< UIRect > uiRects = new ArrayList< UIRect >();\n    \n    for ( int i = 0; i < rects.size(); i++ ) {\n        \n        r = rects.get( i );\n        \n        \n        for ( int j = 0; j < uiList.size(); j++ ) {\n            \n            \n            if ( !uiList.get( j ).isSupport( r ) ) {\n                break;\n            }\n            ui = uiList.get( j );\n        }\n        \n        uiRects.add( new UIRect( ui, r ) );\n    }\n    \n    return uiRects;\n}\n\n\nclass UI {\n    \n    PImage uiTopLeft, uiTopRight, uiBottomLeft, uiBottomRight, uiTop, uiRight, uiBottom, uiLeft, uiCenter;\n    int top, right, bottom, left;\n    \n    String name;\n    \n    UI() {\n    }\n    \n    UI( String path, int top, int right, int bottom, int left ) {\n        \n        this.top = top;\n        this.right = right;\n        this.bottom = bottom;\n        this.left = left;\n        \n        PImage img = loadImage( path );\n        int w = img.width, h = img.height;\n        \n        uiTopLeft     = decomposeToUIPart( img, 0, 0, left, top );\n        uiTopRight    = decomposeToUIPart( img, w - right, 0, right, top );\n        uiBottomLeft  = decomposeToUIPart( img, 0, h - bottom, left, bottom );\n        uiBottomRight = decomposeToUIPart( img, w - right, h - bottom, right, bottom );\n        \n        uiTop    = decomposeToUIPart( img, left, 0, w - left - right, top );\n        uiBottom = decomposeToUIPart( img, left, h - bottom, w - left - right, bottom );\n        uiLeft   = decomposeToUIPart( img, 0, top, left, h - top - bottom );\n        uiRight  = decomposeToUIPart( img, w - right, top, right, h - top - bottom );\n        \n        uiCenter = decomposeToUIPart( img, left, top, w - left - right, h - top - bottom );\n        \n        \n        \n    }\n    \n    boolean isSupport( Rect r ) {\n        \n        return r.w >= left + right + 1 && r.h >= top + bottom + 1;\n    }\n    \n    void drawToGraphics( PGraphics pg, Rect r ) {\n        \n        int et = r.y + top,\n            er = r.x + r.w - right,\n            eb = r.y + r.h - bottom,\n            el = r.x + left,\n            ew = r.w - left - right,\n            eh = r.h - top - bottom;\n        \n        pg.image( uiTopLeft, r.x, r.y );\n        pg.image( uiTopRight, er, r.y );\n        pg.image( uiBottomLeft, r.x, eb );\n        pg.image( uiBottomRight, er, eb );\n        \n        pg.image( uiTop, el, r.y, ew, top );\n        pg.image( uiBottom, el, eb, ew, bottom );\n        pg.image( uiLeft, r.x, et, left, eh );\n        pg.image( uiRight, er, et, right, eh );\n        \n        pg.image( uiCenter, el, et, ew, eh );\n    }\n    \n    void draw( Rect r ) {\n        \n        int et = r.y + top,\n            er = r.x + r.w - right,\n            eb = r.y + r.h - bottom,\n            el = r.x + left,\n            ew = r.w - left - right,\n            eh = r.h - top - bottom;\n        \n        image( uiTopLeft, r.x, r.y );\n        image( uiTopRight, er, r.y );\n        image( uiBottomLeft, r.x, eb );\n        image( uiBottomRight, er, eb );\n        \n        image( uiTop, el, r.y, ew, top );\n        image( uiBottom, el, eb, ew, bottom );\n        image( uiLeft, r.x, et, left, eh );\n        image( uiRight, er, et, right, eh );\n        \n        image( uiCenter, el, et, ew, eh );\n        \n    }\n}\n\nPImage decomposeToUIPart( PImage img, int x, int y, int w, int h ) {\n    PImage part = createImage( w, h, RGB );\n    \n    part.copy( img, x, y, w, h, 0, 0, w, h );\n    \n    return part;\n}\n\n\n/*\n\ncolor uiGray = color( 204, 206, 204 ),\n      uiWhite = color( 252, 254, 252 ),\n      uiBlack = color( 124, 126, 124 );\n      \nPImage renderUI( ArrayList< Rect > rects, int w, int h, int scale ) {\n\n    PGraphics pg = createGraphics( width * scale, height * scale );\n    Rect r;\n    \n    \n    \n    pg.beginDraw();\n    pg.background( 0 );\n    pg.noStroke();\n    \n    \n    for ( int i = 0; i < rects.size(); i++ ) {\n    \n        r = rects.get(i);\n        \n        renderBevel( pg, r, scale, 2 );\n    }\n    \n    pg.endDraw();\n    \n    \n    return pg.get();\n\n}\n\nvoid renderBevel( PGraphics pg, Rect r, int scale, int w ) {\n    \n    pg.fill( uiGray );\n    pg.rect( r.x * scale, r.y * scale, r.w * scale, r.h * scale );\n    \n    pg.fill( uiBlack );\n    pg.rect( ( r.x + r.w ) * scale - w, r.y * scale, w, r.h * scale );\n    pg.rect( r.x * scale, ( r.y + r.h ) * scale - w, r.w * scale, w );\n        \n    pg.fill( uiWhite );\n    for ( int i = 0; i < w; i++ ) {\n        pg.rect( r.x * scale + i, r.y * scale, 1, r.h * scale - i );\n        pg.rect( r.x * scale, r.y * scale + i, r.w * scale - i, 1 );\n    }\n}*/"
  },
  {
    "path": "p5/cubist/util.pde",
    "content": "class Rect {\n\n    int x, y, w, h;\n    \n    Rect() {\n        x = y = w = h = 0;\n    }\n    \n    Rect( int _x, int _y, int _w, int _h ) {\n        x = _x;\n        y = _y;\n        w = _w;\n        h = _h;\n    }\n    \n    void print() {\n        println( x + \"\\t\" + y + \"\\t\" + w + \"\\t\" + h );\n    }\n    \n    int right() {\n        return x + w - 1;\n    }\n    \n    int bottom() {\n        return y + h - 1;\n    }\n    \n    float aspect() {\n        return float( w ) / float( h );\n    }\n    \n    void interpolate( float t, Rect a, Rect b ) {\n        \n        x = int( a.x + ( b.x - a.x ) * t );\n        y = int( a.y + ( b.y - a.y ) * t );\n        w = int( a.w + ( b.w - a.w ) * t );\n        h = int( a.h + ( b.h - a.h ) * t );\n    }\n    \n    void draw() {\n        rect( x, y, w, h );\n    }\n    \n    void copy( Rect r ) {\n        x = r.x;\n        y = r.y;\n        w = r.w;\n        h = r.h;\n    }\n}\n\nclass UIRect extends Rect {\n    \n    UI ui;\n\n    UIRect( UI ui, Rect r ) {\n        \n        super( r.x, r.y, r.w, r.h );\n        this.ui = ui;\n    }\n    \n    void draw() {\n        \n        ui.draw( this );\n    }\n\n}"
  },
  {
    "path": "p5/cubist_galaxy/cubist_galaxy.pde",
    "content": "import java.util.Collections;\n\n//---------------------------------------------\n// config\n\nString srcDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist-galaxy/src\";\nString dstDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist-galaxy/out\";\n\nString filename = \"cell_h\";\n\nint duration = 6;\n\nint inRand = 0;\n\nint border = 1;\n\n//---------------------------------------------\n// main\n\nPImage src;\n\nboolean[][] filled; \n\nArrayList< Rect > rects = new ArrayList< Rect >();\nArrayList< UIRect > uiRects = new ArrayList< UIRect >();\n\nint[] inFrames;\nRect[] fromRects, toRects;\n\n\nvoid setup() {\n\n    noSmooth();\n    frameRate(300);\n    \n    ArrayList< String > arguments = getArgs();\n    \n    if ( arguments.size() > 0 ) {\n        filename = arguments.get( 0 );\n    }\n    \n    loadAndSearch( srcDir + \"/\" + filename + \".png\" );\n    //loadAndSearch( srcDir + \"/\" + filename + \"_2.png\" );\n    //loadAndSearch( srcDir + \"/\" + filename + \"_3.png\" );\n    //loadAndSearch( srcDir + \"/\" + filename + \"_4.png\" );\n\n    loadUI();\n    uiRects = generateUIRects( rects );\n    \n    // shuffle\n    Collections.shuffle( uiRects );\n    \n    // calc in frame and determine move rect\n    fromRects = new Rect[ uiRects.size() ];\n    toRects = new Rect[ uiRects.size() ];\n    inFrames = new int[ uiRects.size() ];\n    UIRect ur;\n    \n    Rect tr;\n    \n    for ( int i = 0; i < uiRects.size(); i++ ) {\n        \n        ur = uiRects.get( i );\n        \n        int cx = ur.x + int(ur.w / 2);\n        int cy = ur.y + int(ur.h / 2);\n        \n        tr = new Rect(ur.x, ur.y, ur.w, ur.h);\n        tr.w -= border * 2;\n        tr.h -= border * 2;\n        tr.x += border;\n        tr.h += border;\n        toRects[i] = tr;\n        fromRects[i] = new Rect(cx, cy, 0, 0);  \n        inFrames[i] = int(random(inRand));\n    }\n}\n\n\nvoid draw() {\n    \n    background( 0 );\n    noStroke();\n    \n    UIRect ur;\n    float t;\n\n    for ( int i = 0; i < uiRects.size(); i++ ) {\n        \n        ur = uiRects.get( i );\n        \n        if (inFrames[i] < frameCount) {\n            // update\n            t = min( float(frameCount-inFrames[i]-1) / duration, 1.0 );\n            t = 1 - t;\n            \n            t = pow( t, 1 );\n            t = 1 - t;\n            \n            ur.interpolate( t, fromRects[i], toRects[i] );\n            ur.draw();\n        }\n        \n        //break;\n    }\n    \n    saveFrame( dstDir + \"/\" + filename + \"/\" + filename + \"_####.png\" );\n    \n    if ( frameCount > duration + inRand + 2 ) {\n        exit();\n    }\n}"
  },
  {
    "path": "p5/cubist_galaxy/rect.pde",
    "content": "color[] colors = {\n    color(255, 0, 0),\n    color(0, 255, 0),\n    color(0, 0, 255),\n    color(255, 255, 0)\n};\n\n\nvoid loadAndSearch( String path ) {\n    \n    src = loadImage( path );\n\n    changeWindowSize( src.width, src.height );\n\n    filled = new boolean[ width ][ height ];\n\n    // initialize fiiled\n    for ( int i = 0; i < colors.length; i++ ) {\n    \n        for ( int y = 0; y < height; y++ ) {\n            for ( int x = 0; x < width; x++ ) {\n                filled[x][y] = src.get( x, y ) != colors[i];\n            }\n        }\n    \n        // search\n        searchRect( 1.5, 20 );\n        searchRect( max( width, height ), 3 );\n        \n    }\n\n\n\n}\n\n\nvoid searchRect( float maxAspect, int minWidth ) {\n    \n    for ( int y = 0; y < height; y++ ) {\n        for ( int x = 0; x < width; x++ ) {\n            \n            if ( !filled[x][y] ) {\n                \n                // start searching\n                Rect r = findRect( x, y );\n                \n                if ( r.w >= minWidth && r.h >= minWidth && r.aspect() <= maxAspect && 1.0 / r.aspect() <= maxAspect ) {\n                \n                    checkSearchedRect( r );\n                    rects.add( r );\n                }\n            }\n        }\n    }\n    \n    println( \"end search: aspect=\", maxAspect, \"minWidth=\", minWidth ); \n}\n\nvoid checkSearchedRect( Rect r ) {\n    \n    // fill\n    for ( int _y = r.y; _y <= r.bottom(); _y++ ) {\n        for ( int _x = r.x; _x <= r.right(); _x++ ) {\n            filled[_x][_y] = true;\n        }\n    }\n    \n}\n\nRect findRect( int x, int y ) {\n    \n    Rect r = new Rect( x, y, 1, 1 );\n    Rect outer = new Rect();\n    \n    // expand top\n    \n    /*outer.copy( r );\n    do {\n        outer.y -= 1;\n        outer.h += 2;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );*/\n\n    // expand right\n    outer.copy( r );\n    do {\n        outer.w += 1;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );\n    \n    // expand bottom\n    outer.copy( r );\n    do {\n        outer.h += 1;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );\n    \n    /*// expand left\n    outer.copy( r );\n    do {\n        outer.x -= 1;\n        outer.w += 2;\n        \n        if ( searchRectEdge( outer ) ) {\n            r.copy( outer );\n        } else {\n            break;\n        }\n    } while ( true );*/\n    \n    return r;\n}\n\nboolean searchRectEdge( Rect r ) {\n    \n    \n    if ( r.x < 0 || r.y < 0 || r.right() >= width || r.bottom() >= height ) {\n        return false;\n    }\n    \n    // horizontal edge\n    for ( int x = r.x; x <= r.right(); x++ ) {\n        if ( filled[x][r.y] || filled[x][r.bottom()] ) {\n            return false;\n        }\n    }\n    \n    // vertical edge\n    for ( int y = r.y; y <= r.bottom(); y++ ) {\n        if( filled[r.x][y] || filled[r.right()][y] ) {\n            return false;\n        }\n    }\n    \n    return true;\n}"
  },
  {
    "path": "p5/cubist_galaxy/ui.pde",
    "content": "import java.util.Collections;\nimport java.util.Comparator;  \n\nString partsDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist-galaxy/_parts\";\n\nArrayList< UI > uiList = new ArrayList< UI >();\n    \n    \nvoid loadUI() {\n\n    // smaller --> bigger\n    uiList.add( new UI( partsDir+\"/p00.png\", 3, 3, 3, 3 ) );\n    uiList.add( new UI( partsDir+\"/p01.png\", 2, 2, 2, 2 ) );\n    uiList.add( new UI( partsDir+\"/p02.png\", 1, 1, 1, 1 ) );\n    uiList.add( new UI( partsDir+\"/p03.png\", 6, 6, 6, 6 ) );\n    //uiList.add( new UI( partsDir+\"/p04.png\", 14, 14, 14, 14 ) );\n    //uiList.add( new UI( partsDir+\"/p05.png\", 14, 14, 14, 14 ) );\n    uiList.add( new UI( partsDir+\"/p06.png\", 8, 9, 8, 8 ) );\n    uiList.add( new UI( partsDir+\"/p07.png\", 1, 1, 1, 1 ) );\n    uiList.add( new UI( partsDir+\"/p08.png\", 8, 2, 2, 2 ) );\n    uiList.add( new UI( partsDir+\"/p09.png\", 8, 2, 2, 6 ) );\n    uiList.add( new UI( partsDir+\"/p10.png\", 5, 5, 13, 5 ) );\n    uiList.add( new UI( partsDir+\"/p11.png\", 5, 5, 13, 5 ) );\n    uiList.add( new UI( partsDir+\"/p12.png\", 6, 6, 6, 6 ) );\n    uiList.add( new UI( partsDir+\"/p13.png\", 6, 6, 6, 6 ) );\n    uiList.add( new UI( partsDir+\"/p14.png\", 16, 15, 14, 10 ) );\n    \n    \n}\n\nArrayList< UIRect > generateUIRects( ArrayList< Rect > rects ) {\n    \n    Rect r;\n    UI ui = new UI();\n    ArrayList< UIRect > uiRects = new ArrayList< UIRect >();\n    ArrayList< UI > supported = new ArrayList< UI >();\n    \n    for ( int i = 0; i < rects.size(); i++ ) {\n        \n        r = rects.get( i );\n        supported.clear();\n        \n        for ( int j = 0; j < uiList.size(); j++ ) {\n            \n            if ( uiList.get(j).isSupport(r) ) {\n                supported.add( uiList.get(j) );\n            }\n        }\n        \n        if ( supported.size() > 0 ) {\n            \n            Collections.sort( supported, new UIComparator() );\n            Collections.reverse( supported );\n            \n            int maxIndex = Math.max(1, ceil( supported.size() / 3 ) );\n            int index = int( random(maxIndex) );\n            \n            ui = supported.get(index);\n            uiRects.add(new UIRect(ui, r));\n            \n        }\n    }\n    \n    return uiRects;\n}\n\nclass UIComparator implements Comparator< UI > {\n    \n    public int compare(UI ui1, UI ui2) {\n        return ui1.getMinArea() < ui2.getMinArea() ? -1 : 1;\n    }\n}\n\n\nclass UI {\n    \n    PImage uiTopLeft, uiTopRight, uiBottomLeft, uiBottomRight, uiTop, uiRight, uiBottom, uiLeft, uiCenter;\n    int top, right, bottom, left;\n    \n    String name;\n    \n    UI() {\n    }\n    \n    UI( String path, int top, int right, int bottom, int left ) {\n        \n        this.top = top;\n        this.right = right;\n        this.bottom = bottom;\n        this.left = left;\n        \n        PImage img = loadImage( path );\n        int w = img.width, h = img.height;\n        \n        uiTopLeft     = decomposeToUIPart( img, 0, 0, left, top );\n        uiTopRight    = decomposeToUIPart( img, w - right, 0, right, top );\n        uiBottomLeft  = decomposeToUIPart( img, 0, h - bottom, left, bottom );\n        uiBottomRight = decomposeToUIPart( img, w - right, h - bottom, right, bottom );\n        \n        uiTop    = decomposeToUIPart( img, left, 0, w - left - right, top );\n        uiBottom = decomposeToUIPart( img, left, h - bottom, w - left - right, bottom );\n        uiLeft   = decomposeToUIPart( img, 0, top, left, h - top - bottom );\n        uiRight  = decomposeToUIPart( img, w - right, top, right, h - top - bottom );\n        \n        uiCenter = decomposeToUIPart( img, left, top, w - left - right, h - top - bottom );\n        \n        \n        \n    }\n    \n    boolean isSupport( Rect r ) {\n        \n        return r.w >= left + right && r.h >= top + bottom;\n    }\n    \n    int getMinArea() {\n       return (left + right) * (top + bottom);\n    }\n    \n    void drawToGraphics( PGraphics pg, Rect r ) {\n        \n        int et = r.y + top,\n            er = r.x + r.w - right,\n            eb = r.y + r.h - bottom,\n            el = r.x + left,\n            ew = r.w - left - right,\n            eh = r.h - top - bottom;\n        \n        pg.image( uiTopLeft, r.x, r.y );\n        pg.image( uiTopRight, er, r.y );\n        pg.image( uiBottomLeft, r.x, eb );\n        pg.image( uiBottomRight, er, eb );\n        \n        pg.image( uiTop, el, r.y, ew, top );\n        pg.image( uiBottom, el, eb, ew, bottom );\n        pg.image( uiLeft, r.x, et, left, eh );\n        pg.image( uiRight, er, et, right, eh );\n        \n        pg.image( uiCenter, el, et, ew, eh );\n    }\n    \n    void draw( Rect r ) {\n        \n        int et = r.y + top,\n            er = r.x + r.w - right,\n            eb = r.y + r.h - bottom,\n            el = r.x + left,\n            ew = r.w - left - right,\n            eh = r.h - top - bottom;\n            \n        if ( !isSupport(r) ) {\n            return;\n        }\n        \n        image( uiTopLeft, r.x, r.y );\n        image( uiTopRight, er, r.y );\n        image( uiBottomLeft, r.x, eb );\n        image( uiBottomRight, er, eb );\n        \n        image( uiTop, el, r.y, ew, top );\n        image( uiBottom, el, eb, ew, bottom );\n        image( uiLeft, r.x, et, left, eh );\n        image( uiRight, er, et, right, eh );\n        \n        image( uiCenter, el, et, ew, eh );\n        \n    }\n}\n\nPImage decomposeToUIPart( PImage img, int x, int y, int w, int h ) {\n    PImage part = createImage( w, h, RGB );\n    \n    part.copy( img, x, y, w, h, 0, 0, w, h );\n    \n    return part;\n}\n\n\n/*\n\ncolor uiGray = color( 204, 206, 204 ),\n      uiWhite = color( 252, 254, 252 ),\n      uiBlack = color( 124, 126, 124 );\n      \nPImage renderUI( ArrayList< Rect > rects, int w, int h, int scale ) {\n\n    PGraphics pg = createGraphics( width * scale, height * scale );\n    Rect r;\n    \n    \n    \n    pg.beginDraw();\n    pg.background( 0 );\n    pg.noStroke();\n    \n    \n    for ( int i = 0; i < rects.size(); i++ ) {\n    \n        r = rects.get(i);\n        \n        renderBevel( pg, r, scale, 2 );\n    }\n    \n    pg.endDraw();\n    \n    \n    return pg.get();\n\n}\n\nvoid renderBevel( PGraphics pg, Rect r, int scale, int w ) {\n    \n    pg.fill( uiGray );\n    pg.rect( r.x * scale, r.y * scale, r.w * scale, r.h * scale );\n    \n    pg.fill( uiBlack );\n    pg.rect( ( r.x + r.w ) * scale - w, r.y * scale, w, r.h * scale );\n    pg.rect( r.x * scale, ( r.y + r.h ) * scale - w, r.w * scale, w );\n        \n    pg.fill( uiWhite );\n    for ( int i = 0; i < w; i++ ) {\n        pg.rect( r.x * scale + i, r.y * scale, 1, r.h * scale - i );\n        pg.rect( r.x * scale, r.y * scale + i, r.w * scale - i, 1 );\n    }\n}*/"
  },
  {
    "path": "p5/cubist_galaxy/util.pde",
    "content": "void changeWindowSize(int w, int h) {\n\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n    \n}\n\nArrayList< String > getArgs() {\n    \n    ArrayList< String > arguments = new ArrayList< String >();\n    \n    try {\n        for ( int i = 0; i < args.length; i++ ) {\n            arguments.add( args[i] );\n        }\n    } catch ( Exception e ) {\n        return arguments;\n    }\n    \n    return arguments;\n}\n\nString getFileName( String path ) {\n    \n    String filename = new File( path ).getName();\n    int point = filename.lastIndexOf(\".\");\n    \n    if (point != -1) {\n        return filename.substring(0, point);\n    } \n    \n    return filename;\n}\n\nString getDirectory( String path ) {\n    \n    return new File( path ).getParent();\n}\n\nclass Rect {\n\n    int x, y, w, h;\n    \n    Rect() {\n        x = y = w = h = 0;\n    }\n    \n    Rect( int _x, int _y, int _w, int _h ) {\n        x = _x;\n        y = _y;\n        w = _w;\n        h = _h;\n    }\n    \n    void print() {\n        println( x + \"\\t\" + y + \"\\t\" + w + \"\\t\" + h );\n    }\n    \n    int right() {\n        return x + w - 1;\n    }\n    \n    int bottom() {\n        return y + h - 1;\n    }\n    \n    float aspect() {\n        return float( w ) / float( h );\n    }\n    \n    void interpolate( float t, Rect a, Rect b ) {\n        \n        x = int( a.x + ( b.x - a.x ) * t );\n        y = int( a.y + ( b.y - a.y ) * t );\n        w = int( a.w + ( b.w - a.w ) * t );\n        h = int( a.h + ( b.h - a.h ) * t );\n    }\n    \n    void draw() {\n        rect( x, y, w, h );\n    }\n    \n    void copy( Rect r ) {\n        x = r.x;\n        y = r.y;\n        w = r.w;\n        h = r.h;\n    }\n}\n\nclass UIRect extends Rect {\n    \n    UI ui;\n\n    UIRect( UI ui, Rect r ) {\n        \n        super( r.x, r.y, r.w, r.h );\n        this.ui = ui;\n    }\n    \n    void draw() {\n        \n        ui.draw( this );\n    }\n\n}"
  },
  {
    "path": "p5/dla/Particle.pde",
    "content": "// ---------------\n// Particle.pde\n// ---------------\n\n// neighbor\nint nlen = 8;\nint[] nx = {  0, +1, +1, +1,  0, -1, -1, -1 };\nint[] ny = { -1, -1,  0, +1, +1, +1,  0, -1 };\n\n// weight\nfloat weight;\nfloat weightRandom = 5.8;\nfloat[] weightBk = new float[ nlen ];\n\nclass Particle\n{\n    int x, y;\n    boolean isSeed = false;\n    boolean stuck = false;\n    boolean isOut = false;\n    \n    Particle( int threshold ) {\n        reset( threshold );\n    }\n\n    void reset( int threshold ) {\n        // keep choosing random spots until an empty one is found\n        do {\n            x = floor( random(width) );//floor( random(width/2) ) * 2;\n            y = floor( random(height) );//floor( random(height/2) ) * 2;\n        \n        } while (field[y * width + x] || (weightMap.get( x, y ) & 0xff) < threshold );\n    }\n\n    void update() {\n        // move around\n        if (!stuck) {\n            \n            // read weight\n            //weightSum = 0;\n            /*for ( int i = 0; i < nlen; i++ ) {\n            \n                weightSum += pow( float( map.get( x + nx[i], y + ny[i] ) & 0xff ), 3 );\n                weightBk[ i ] = weightSum;\n                //print( weightSum + \"\\t\" );\n            }\n            \n            \n            r = random( weightSum );\n            \n            \n            //println( \"|\" + r );\n            \n            for ( int i = 0; i < nlen; i++ ) {\n            \n                if ( r <= weightBk[i] ) {\n                    x += nx[i];\n                    y += ny[i];\n                    break;\n                }\n            }*/\n            \n            float maxWeight = -weightRandom * 2;\n            int maxDir = 0;\n            \n            for ( int i = 0; i < nlen; i++ ) {\n                weight = float( weightMap.get( x + nx[i], y + ny[i] ) & 0xff ) / 255.0 + random( -weightRandom, weightRandom );\n                if ( weight > maxWeight ) {\n                    maxDir = i;\n                    maxWeight = weight;\n                }\n            }\n            \n            x += nx[ maxDir ];\n            y += ny[ maxDir ];\n            \n            \n            /*x += round(random(-1, 1));\n            y += round(random(-1, 1));*/\n            \n            \n            \n            /*if ( random(1) < 0.1 ) {\n                \n                if ( x > width / 2 ) \n                    x -= 1;\n                else\n                    x += 1;\n                \n                if ( y > height / 2 )\n                    y -= 1;\n                else\n                    y += 1;\n                 \n            \n            } else {\n            \n                x += round(random(-1, 1));\n                y += round(random(-1, 1));\n            \n            }*/\n            \n            \n            // diagonal random walk\n            //r = int( random( 0, 4 ) );\n            //if ( r == 0 ) {\n            //    x += 1; y -= 1;\n            //} else if ( r == 1 ) {\n            //    x += 1; y += 1;\n            //} else if ( r == 2 ) {\n            //    x -= 1; y += 1;\n            //} else if ( r == 3 ) {\n            //    x -= 1; y -= 1;\n            //}\n            \n            isOut = false;\n            \n            if ( x < 0 ) {\n                x = 0;\n                isOut = true;\n            }\n            if ( y < 0 ) {\n                y = 0;\n                isOut = true;\n            }\n            if ( x >= width ) {\n                x = width - 1;\n                isOut = true;\n            }\n            if ( y >= height ) {\n                y = height - 1;\n                isOut = true;\n            }\n            \n            if ( isOut ) {\n                return;\n            }\n            \n\n            // test if something is next to us\n            if ( !alone() ) {\n                stuck = true;\n                field[y * width + x] = true;        \n            }\n        }\n    }\n\n    // returns true if no neighboring pixels\n    boolean alone() {\n        \n        int cx = x;\n        int cy = y;\n\n        // get positions\n        int lx = cx-1;\n        int rx = cx+1;\n        int ty = cy-1;\n        int by = cy+1;\n\n        // if bound\n        if (cx <= 0 || cx >= width || \n            lx <= 0 || lx >= width || \n            rx <= 0 || rx >= width || \n            cy <= 0 || cy >= height || \n            ty <= 0 || ty >= height || \n            by <= 0 || by >= height) return true;\n\n        // pre multiply the ys\n        cy *= width;\n        by *= width;\n        ty *= width;\n    \n        // N, W, E, S\n        \n        int neumann =\n            ( field[cx + ty] ? 1 : 0 ) +\n            ( field[lx + cy] ? 1 : 0 ) +\n            ( field[rx + cy] ? 1 : 0 ) +\n            ( field[cx + by] ? 1 : 0 );\n            \n        /*boolean corner = \n            field[lx + ty] || \n            field[lx + by] ||\n            field[rx + ty] ||\n            field[rx + by];*/\n            \n        if ( neumann == 1 ) {\n            return false;\n        }\n       \n\n        return true;\n\n    }  \n}"
  },
  {
    "path": "p5/dla/Point.pde",
    "content": "class Point {\n    \n    int x, y;\n    \n    Point( int _x, int _y ) {\n        x = _x;\n        y = _y;\n    }\n    \n    int index() {\n        return x + y * width;\n    }\n}"
  },
  {
    "path": "p5/dla/dla.pde",
    "content": "//---------------------------------------------\n// config\n\nString weightMapPath = \"../_dat/dla-weight-map.png\";\nString destDir = \"out\"; \n\nString filename = \"dla_neumann_cell_large\";\n\nint particleCount = 10000;\n\n//---------------------------------------------\n// main\n\nPImage weightMap;\nint exportedCount = 0;\n\nArrayList< Particle >  particles = new ArrayList< Particle >();\nboolean[] field;\n\nPoint seed;\n\nvoid setup() {\n    size(10, 10, P2D);\n    noSmooth();\n    \n    weightMap = loadImage(weightMapPath);\n    \n    changeWindowSize( weightMap.width, weightMap.height );\n    \n    File[] existsImages = listImageFiles(destDir);\n    exportedCount = existsImages.length - 1;\n    println( exportedCount );\n    \n    // create an array that stores the position of our particles\n    field = new boolean[width * height];\n    \n  \n    // make particles\n    for(int i=0; i < particleCount; i++) {\n        particles.add( new Particle( 10 ) );\n    }\n    \n    // make seed\n    for ( int i = 0; i < 40; i++ ) {\n        Particle seed = new Particle( 220 );\n        seed.isSeed = true;\n        seed.stuck = true;\n        particles.add( seed );\n        \n        field[seed.x + seed.y * width] = true;\n    }\n}\n\n\nvoid draw() {\n    \n        \n    // udapte dla\n    background( 0 ); \n    noFill();\n    noStroke();\n    \n    Particle p;\n    \n    for(int i = 0, l = particles.size(); i < l; i++) {\n        \n        p = particles.get( i );\n        p.update();\n        \n        if ( p.stuck ) {\n            \n            if ( p.isSeed ) {\n                fill( 255, 255, 0 );\n            } else {\n                fill( 255, 0, 0 );\n            }\n        \n        } else {\n            fill( 0, 0, 255 );\n        }\n        \n        rect( p.x, p.y, 1, 1 );\n     }\n}\n\nvoid keyPressed() {\n        \n    String path = destDir + \"/\" + filename + \"/\" + filename + \"_\" + String.format( \"%04d\", exportedCount++ ) + \".png\";\n    println( \"saved: \" + path );\n    saveFrame( path );\n}"
  },
  {
    "path": "p5/dla/util.pde",
    "content": "import java.io.FilenameFilter;\n\nvoid changeWindowSize(int w, int h) {\n\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n    \n}\n\nFile[] listImageFiles(String path) {\n    \n    File file = new File(resolveRelativePath(path));\n    \n    if (file.isDirectory()) {\n        \n        FilenameFilter filter = new FilenameFilter() {\n            public boolean accept(File dir, String name) {\n                String ext = \"\";\n                int dotIndex = name.lastIndexOf('.');\n                if ((dotIndex > 0) && (dotIndex < name.length() - 1 )) {\n                    ext = name.substring(dotIndex + 1).toLowerCase();\n                }\n                return (ext.equals(\"png\"));\n            }\n        };\n        return file.listFiles(filter);\n        \n    } else {\n        // If it's not a directory\n        return new File[0];\n    }\n}\n\nString resolveRelativePath(String path) {\n    File file = new File(sketchPath(\"\") + path);\n    \n    try {\n        return file.getCanonicalPath();\n    } catch (Exception e) {\n        return null;\n    }\n}"
  },
  {
    "path": "p5/dla_animate/dla_animate.pde",
    "content": "import processing.video.*;\n\n//---------------------------------------------\n// config\n\nString mapDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/dla-net\";\nString dstDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/root\";\n\nString filename = \"root\";\n\nboolean isSave = true;\n\n//---------------------------------------------\n// main\n\nPImage map, field, buff;\n\nArrayList< Point > frontier = new ArrayList< Point >();\n\ncolor colorSeed = color( 255, 255, 0 );\ncolor colorRoot = color( 255, 0, 0 );\ncolor colorFrontier = color( 0, 255, 255 );\ncolor colorReproduced = color( 0, 0, 255 );\n\nint nlen = 4;\nint[] nx = {  0, +1,  0, -1 };\nint[] ny = { -1,  0, +1,  0 };\n\n// 8 \n//int nlen = 8;\n//int[] nx = {  0, +1, +1, +1,  0, -1, -1, -1 };\n//int[] ny = { -1, -1,  0, +1, +1, +1,  0, -1 };\n\nvoid setup() {\n    noSmooth();\n    frameRate( 24 );\n    \n    map = loadImage( mapDir + \"/\" + filename + \".png\" );\n    \n    changeWindowSize( map.width, map.height );\n    \n    \n    field = createImage( width, height, RGB );\n    buff  = createImage( width, height, RGB );\n    \n    PImage uiImg = subdivideToUI();\n    uiImg.save( dstDir + \"/\" + filename + \"_ui.png\" );\n    \n    // search seed\n    color c;\n    int x, y;\n    \n    for ( y = 0; y < height; y++ ) {\n        for ( x = 0; x < width; x++ ) {\n        \n           c = map.get( x, y );\n           \n           if ( c == colorSeed ) {\n               field.set( x, y, colorFrontier );\n           }\n           if ( c == colorRoot ) {\n               field.set( x, y, colorRoot ); \n           }\n        }\n    }\n    \n    //exit();\n}\n\nvoid draw() {\n    \n    if ( frameCount == 1 && isSave ) {\n        image( field, 0, 0 );\n        saveFrame( dstDir + \"/\" + filename + \"/\" + filename + \"_0000\" );\n    }\n    \n    \n    // update\n    int x, y, frontierCount = 0;\n    color c;\n    \n    buff.copy( field, 0, 0, width, height, 0, 0, width, height );\n    \n    for ( y = 0; y < height; y++ ) {\n        for ( x = 0; x < width; x++ ) {\n            \n            c = buff.get( x, y );\n            \n            if ( c == colorFrontier ) {\n            \n                for ( int i = 0; i < nlen; i++ ) {\n                \n                    if( field.get( x + nx[i], y + ny[i] ) == colorRoot ) {\n                        field.set( x + nx[i], y + ny[i], colorFrontier );\n                        frontierCount++;\n                    }\n                }\n                \n                field.set( x, y, colorReproduced );\n            }\n        }\n    }\n    \n    background( 0 );\n    \n    \n    // draw current image and save\n    image( field, 0, 0 );\n    \n    // and save\n    if ( isSave ) {\n        \n        saveFrame( dstDir + \"/\" + filename + \"/\" + filename + \"_####\" );\n    }\n    \n    if ( frontierCount == 0 ) {\n        exit();\n    }   \n}\n\nclass Point {\n    \n    int x, y;\n    \n    Point( int _x, int _y ) {\n        x = _x;\n        y = _y;\n    }\n    \n    int index() {\n        return x + y * width;\n    }\n    \n    int neighbor( int _x, int _y ) {\n        \n        int nx = x + _x,\n            ny = x + _y;\n            \n        if ( nx < 0 || nx >= width || ny < 0 || ny >= height ) {\n            return -1;\n        }\n        \n        return ny * width + nx;\n    }\n}"
  },
  {
    "path": "p5/dla_animate/ui.pde",
    "content": "color uiGray = color( 204, 206, 204 ),\n      uiWhite = color( 252, 254, 252 ),\n      uiBlack = color( 124, 126, 124 );\n\nPImage renderUI( ArrayList< Rect > rects, int w, int h, int scale ) {\n\n    \n    PGraphics pg = createGraphics( width * scale, height * scale );\n    Rect r;\n    \n    \n    \n    pg.beginDraw();\n    pg.background( 0 );\n    pg.noStroke();\n    \n    \n    for ( int i = 0; i < rects.size(); i++ ) {\n    \n        r = rects.get(i);\n        \n        renderBevel( pg, r, scale, 2 );\n    }\n    \n    pg.endDraw();\n    \n    \n    return pg.get();\n\n}\n\nvoid renderBevel( PGraphics pg, Rect r, int scale, int w ) {\n    \n    pg.fill( uiGray );\n    pg.rect( r.x * scale, r.y * scale, r.w * scale, r.h * scale );\n    \n    pg.fill( uiBlack );\n    pg.rect( ( r.x + r.w ) * scale - w, r.y * scale, w, r.h * scale );\n    pg.rect( r.x * scale, ( r.y + r.h ) * scale - w, r.w * scale, w );\n        \n    pg.fill( uiWhite );\n    for ( int i = 0; i < w; i++ ) {\n        pg.rect( r.x * scale + i, r.y * scale, 1, r.h * scale - i );\n        pg.rect( r.x * scale, r.y * scale + i, r.w * scale - i, 1 );\n    }\n        \n    \n\n\n}"
  },
  {
    "path": "p5/dla_animate/util.pde",
    "content": "void changeWindowSize(int w, int h) {\n\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n}\n\n\nPImage subdivideToUI() {\n\n    // find frontier\n    \n    ArrayList< Point > search = new ArrayList< Point >();\n    ArrayList< Rect > rects = new ArrayList< Rect >();\n    \n    PImage img = createImage( width, height, RGB );\n    img.copy( map, 0, 0, width, height, 0, 0, width, height );\n    \n    for ( int y = 0; y < height; y++ ) {\n        for ( int x = 0; x < width; x++ ) {\n            \n            if ( img.get( x, y ) == colorSeed ) {\n                \n                if( img.get( x, y-1 ) == colorRoot ) search.add( new Point( x, y-1 ) );\n                if( img.get( x+1, y ) == colorRoot ) search.add( new Point( x+1, y ) );\n                if( img.get( x, y+1 ) == colorRoot ) search.add( new Point( x, y+1 ) );\n                if( img.get( x-1, y ) == colorRoot ) search.add( new Point( x-1, y ) );\n                \n                Rect r = new Rect( x, y, 1, 1 );\n                rects.add( r );\n                deleteRoot( img, r );\n                \n            }\n        }\n    }\n    \n    do {\n        \n        // search rect\n        Point p;\n        int x, y;\n        int x0, y0, x1, y1;\n        \n        boolean hasVertical, hasHorizontal;\n        \n        for ( int i = search.size() - 1; i >= 0; i-- ) {\n            \n        \n            p = search.get( i );\n            x = p.x;\n            y = p.y;\n            \n            hasHorizontal = img.get( x-1, y ) == colorRoot || img.get( x+1, y ) == colorRoot;\n            hasVertical   = img.get( x, y-1 ) == colorRoot || img.get( x, y+1 ) == colorRoot;\n            \n            if ( hasHorizontal && hasVertical ) {\n            \n                if ( random(1) > 0.5 ) {\n                    hasHorizontal = false;\n                } else {\n                    hasVertical = false;\n                }\n            }\n            \n            // search\n            if ( hasHorizontal ) {\n            \n                x0 = searchDir( search, img, p, -1, 0 ).x;\n                x1 = searchDir( search, img, p, +1, 0 ).x;\n                y0 = y;\n                y1 = y;\n            \n            } else {\n            \n                x0 = x;\n                x1 = x;\n                y0 = searchDir( search, img, p, 0, -1 ).y;\n                y1 = searchDir( search, img, p, 0, +1 ).y;\n                \n            }\n            \n            Rect r = new Rect( x0, y0, x1-x0+1, y1-y0+1 );\n            rects.add( r );\n            deleteRoot( img, r );\n            search.remove( i );\n            \n            for ( int ry = r.y; ry < r.y + r.h; ry++ ) {\n                for ( int rx = r.x; rx < r.x + r.w; rx++ ) {\n                    if( img.get( rx, ry-1 ) == colorRoot ) search.add( new Point( rx, ry-1 ) );\n                    if( img.get( rx+1, ry ) == colorRoot ) search.add( new Point( rx+1, ry ) );\n                    if( img.get( rx, ry+1 ) == colorRoot ) search.add( new Point( rx, ry+1 ) );\n                    if( img.get( rx-1, ry ) == colorRoot ) search.add( new Point( rx-1, ry ) );\n                }\n            }\n        }\n    \n    } while( search.size() > 0 );\n    \n    \n    // draw\n    return renderUI( rects, width, height, 8 );\n    \n}\n\n\n\nPoint searchDir( ArrayList< Point > search, PImage img, Point origin, int dx, int dy ) {\n\n    int x = origin.x,\n        y = origin.y;\n    \n    while ( img.get( x+dx, y+dy ) == colorRoot ) {\n        \n        x += dx;\n        y += dy;\n    }\n    \n    return new Point( x, y );\n}\n\n\nvoid deleteRoot( PImage img, Rect r ) {\n\n    for ( int y = r.y; y < r.y + r.h; y++ ) {\n        for ( int x = r.x; x < r.x + r.w; x++ ) {\n            img.set( x, y, color( 0 ) );\n        }\n    }\n}\n\n\n\nclass Rect {\n\n    int x, y, w, h;\n    \n    Rect( int _x, int _y, int _w, int _h ) {\n        x = _x;\n        y = _y;\n        w = _w;\n        h = _h;\n    }\n    \n    void print() {\n        println( x + \"\\t\" + y + \"\\t\" + w + \"\\t\" + h );\n    }\n\n}"
  },
  {
    "path": "p5/filling/filling.pde",
    "content": "//----------------------------------------\n// config\n\nString srcDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/filling/_src/\";\nString destDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/filling\";\nString filename = \"squares_qr_for_filling\";\n\nint duration = 15;\nint startRand = 3;\nint minLen = 10;\n\n\n//----------------------------------------\n// main\n\n\nint[][] dirs;\n\n//int N = 0b1,\n//    E = 0b10,\n//    S = 0b100,\n//    W = 0b1000,\n//    X = 0b10000,  // undefined\n//    V = 0b100000; // empty\n\nPImage shape;\n\nint IE = 0, IS = 1, IW = 2, IN = 3;\nint E = 0b1,\n    S = 0b10,\n    W = 0b100,\n    N = 0b1000;\n\nboolean[][] filled;\n\nint[] dx = { +1,  0, -1,  0 };\nint[] dy = {  0, +1,  0, -1 };\n\nArrayList< Chain > chain;\n\nArrayList< Frontier > frontier = new ArrayList< Frontier >();\n\nvoid setup() {\n    \n    shape = loadImage( srcDir + \"/\" + filename + \".png\" );\n    \n    changeWindowSize( shape.width, shape.height );\n    \n    filled = new boolean[ shape.width ][ shape.height ];\n    \n    for ( int y = 0; y < shape.height; y++ ) {\n       for ( int x = 0; x < shape.width; x++ ) {\n           filled[x][y] = shape.get( x, y ) == color( 0 );\n       }   \n    }\n    \n    chain = new ArrayList< Chain >();\n    \n    int x = 0, y = 0, dir = 0, d = 0;\n    \n    while ( true ) {\n    \n       // find start point\n       outerloop:\n       for ( y = 0; y < shape.height; y++ ) {\n           for ( x = 0; x < shape.width; x++ ) {\n               if ( !filled[x][y] ) break outerloop;\n           }\n       }\n       \n       if ( x == shape.width || y == shape.width ) break;\n        \n       dir = IE;\n        \n       chain.add( new Chain( x, y, true ) );\n       filled[x][y] = true;\n       \n       while( true ) {\n           \n           for ( int i = 0; i < 4; i++ ) {\n               d = (dir + 3 + i ) % 4;\n               if ( !isFilled( x + dx[d], y + dy[d] ) ) break;\n           }\n            \n           if ( (d+2) % 4 == dir ) { // dead end\n               break;\n           }\n            \n           dir = d;\n            \n           x += dx[ dir ];\n           y += dy[ dir ];\n            \n           chain.add( new Chain( x, y, false ) );\n           filled[x][y] = true;\n       }\n    }\n    \n    int i = 0;\n    while ( i < chain.size() ) {\n        \n        Frontier f = new Frontier();\n        f.start = i;\n        f.inTime = int( random( 1, startRand+1 ) );\n        f.end = i + duration - f.inTime - 1;\n        \n        if ( f.end >= chain.size() ) {\n            f.end = chain.size() - 1;\n        }\n        \n        for ( int j = i+1; j < f.end; j++ ) {\n            \n            if ( chain.get(j).begin ) {\n                f.end = j - 1;\n            }\n        }\n        \n        f.setRange();\n        \n        frontier.add( f );\n        \n        i = f.end + 1;\n    }\n    \n    passed = new boolean[ shape.width ][ shape.height ];\n    \n    for (y = 0; y < shape.height; y++ ) {\n        for ( x = 0; x < shape.width; x++ ) {\n            passed[x][y] = false;\n        }\n    }\n    \n    noStroke();\n    background( 0 );\n    \n}\n\nboolean[][] passed;\n\nvoid draw() {\n    \n    for ( int y = 0; y < shape.height; y++ ) {\n        for ( int x = 0; x < shape.width; x++ ) {\n            if ( passed[x][y] ) {\n                fill( 0, 0, 255 );\n                rect( x, y, 1, 1 );\n            }\n        }\n    }\n    \n    Frontier f;\n    Chain c;\n    \n    if ( frameCount > 1 ) {\n        for ( int i = frontier.size() - 1; i >= 0; i-- ) {\n            \n           f = frontier.get( i );\n           c = chain.get( f.index );\n            \n           if ( frameCount - 1 >= f.inTime ) {\n               fill( 255, 0, 0 );\n               rect( c.x, c.y, 1, 1 );\n           }\n            \n           c.passed = true;\n           passed[ c.x ][ c.y ] = true;\n        }\n    }\n    \n    \n    for ( int i = frontier.size() - 1; i >= 0; i-- ) {\n        \n       f = frontier.get( i );\n       c = chain.get( f.index );\n        \n       if ( frameCount - 1 >= f.inTime ) {\n           \n           if ( !f.next() ) {\n               frontier.remove( i );\n           }\n       }\n    }\n    \n    saveFrame( destDir + \"/filling_\" + filename + \"/filling_\" + filename + \"_####.png\" );\n    \n    if (frameCount == duration + 2 ) {\n       println( \"end\", frameCount );\n       exit();\n    }\n    \n}\n\nboolean isFilled( int x, int y ) {\n    if ( x < 0 || y < 0 || x >= shape.width || y >= shape.height )\n        return true;\n    \n    return filled[x][y];\n}\n\nclass Frontier {\n    int index, dir, inTime, start, end;\n    \n    void setRange() {\n        \n        dir = int(random(2)) * 2 - 1;\n        if ( dir == 1 ) {\n            index = start;\n        } else {\n            index = end;\n        }\n    }\n    \n    boolean next() {\n        index += dir;\n        return start <= index && index <= end;\n    }\n}\n\n\nclass Chain {\n    \n    int x, y;\n    boolean begin;\n    boolean passed = false;\n    \n    Chain( int _x, int _y, boolean _begin ) {\n        x = _x;\n        y = _y;\n        begin = _begin;\n    }\n    \n}"
  },
  {
    "path": "p5/filling/util.pde",
    "content": "void changeWindowSize(int w, int h) {\n\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n    \n}"
  },
  {
    "path": "p5/life_like/ca.pde",
    "content": "boolean[] survive, birth;\n\n//-------------------------------------------------------\n// rules\n\n// conway's game of life\nint[] birthNum = { 3 };\nint[] surviveNum = { 2, 3 };\n\n//// replicator\n//int[] birthNum = { 1, 3, 5, 7 };\n//int[] surviveNum = { 1, 3, 5, 7 };\n\n// small-replicator\n//int[] birthNum = { 2, 5 };\n//int[] surviveNum = { 4 };\n\n// 34 Life\n//int[] birthNum = { 3, 4 };\n//int[] surviveNum = { 3, 4 };\n\n// 2x2\n//int[] birthNum = { 3, 6 };\n//int[] surviveNum = { 1, 2, 5 };\n\n// day and night\n//int[] birthNum = {3, 6, 7, 8 };\n//int[] surviveNum = { 3, 4, 6, 7, 8 };\n\n// HighLife\n//int[] birthNum = {3, 6};\n//int[] surviveNum = { , 3};\n\n// Morley\n//int[] birthNum = {3, 6, 8};\n//int[] surviveNum = {2, 4, 5};\n\n// Diamoeba\n//int[] birthNum = {3, 5, 6, 7, 8};\n//int[] surviveNum = {5, 6, 7, 8};\n\n// explosive one\n//int[] birthNum = {1, 7};\n//int[] surviveNum = {7, 8};\n\n// explosive two\n//int[] birthNum = {1, 4, 5};\n//int[] surviveNum = {3, 4};\n\n// gnarl\n//int[] birthNum = {1};\n//int[] surviveNum = {1};\n\n//// coagulations\n//int[] birthNum = {3, 7, 8};\n//int[] surviveNum = {2, 3, 4, 5, 6, 7, 8};\n\n//// mazectric\n//int[] birthNum = {3};\n//int[] surviveNum = {1, 2, 3, 4, 5};\n\n// amoeba\n//int[] birthNum = {1, 3, 5, 8};\n//int[] surviveNum = {3, 5, 7};\n\n// Serviettes\n//int[] birthNum = {2, 3, 4};\n//int[] surviveNum = {};\n\n//-------------------------------------------------------\n// class & methods\n\nclass LifeLikeCA\n{\n    PImage field, buff;\n    int fw, fh;\n    \n    LifeLikeCA(PImage initCond) {\n        \n        fw = initCond.width;\n        fh = initCond.height;\n        \n        field = initCond;\n        buff = createImage(fw, fh, RGB);\n        \n    }\n    \n    void draw(int x, int y) {\n    \n        image(field, x, y);\n    \n    }\n    \n    void update() {\n        \n        int aliveNum;\n        color next;\n        \n        buff.copy(field, 0, 0, fw, fh, 0, 0, fw, fh);\n    \n        for (int y = 0; y < fh; y++) {\n            for (int x = 0; x < fw; x++) {\n    \n                aliveNum = getAliveCount(buff, x, y);\n                next = colorDead;\n                \n                if (buff.get(x, y)  == colorAlive) {\n                    if (survive[aliveNum]) {\n                        next = colorAlive;\n                    }\n                } else {\n                    if (birth[aliveNum]) {\n                        next = colorAlive;\n                    }\n                }\n    \n                field.set(x, y, next);\n            }\n        }\n    }\n}\n\nvoid setupLifeLikeRules() {\n  \n   // init rules\n    survive = new boolean[9];\n    birth  = new boolean[9];\n\n    for (int i = 0; i < 8; i++) {\n        survive[i] = false;\n        birth[i] = false;\n    }\n\n    for (int i = 0; i < surviveNum.length; i++) {\n        survive[surviveNum[i]] = true;\n    }\n    for (int i = 0; i < birthNum.length; i++) {\n        birth[birthNum[i]] = true;\n    }\n}\n\nint getAliveCount(PImage field, int x, int y) {\n\n    int neighbors = 0;\n\n    neighbors += getStatus(field,   x, y-1);\n    neighbors += getStatus(field, x+1, y-1);\n    neighbors += getStatus(field, x+1,   y);\n    neighbors += getStatus(field, x+1, y+1);\n    neighbors += getStatus(field,   x, y+1);\n    neighbors += getStatus(field, x-1, y+1);\n    neighbors += getStatus(field, x-1,   y);\n    neighbors += getStatus(field, x-1, y-1);\n\n    return neighbors;\n}\n\nint getStatus(PImage field, int x, int y) {\n\n    if (x < 0 || field.width <= x || y < 0 || field.height <= y) {\n        return 0;\n    } else {\n        return field.get(x, y) != colorDead ? 1 : 0;\n    }\n}"
  },
  {
    "path": "p5/life_like/life_like.pde",
    "content": "//-------------------------------------------------------\n// config\n\nfinal color colorAlive = color( 255 );\nfinal color colorDead = color( 0 );\n\nfinal String dstName = \"out/####.png\";\nfinal String srcName = \"../_dat/init-cond.png\";\nfinal boolean isSave = true;\nfinal int scale = 1;\n\n//-------------------------------------------------------\n// main\n\nLifeLikeCA ca;\n\nvoid setup() {\n    \n    // init ca\n    PImage initCond = loadImage( srcName );\n    setupLifeLikeRules();\n    ca = new LifeLikeCA( initCond );\n    \n    // setup\n    noSmooth();\n    changeWindowSize( initCond.width * scale, initCond.height * scale );\n}\n\nvoid draw() {\n    \n    background( 0 );\n    resetMatrix();\n    scale( scale );\n    \n    ca.draw( 0, 0 );\n    ca.update();\n    \n    if ( isSave ) {\n        saveFrame( dstName );\n    }\n}"
  },
  {
    "path": "p5/life_like/util.pde",
    "content": "void changeWindowSize(int w, int h) {\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n}"
  },
  {
    "path": "p5/life_like_transition/ca.pde",
    "content": "final color colorAlive = color( 200 );\nfinal color colorDead  = color( 100 );\n\nfinal color colorSeed = color( 255, 0, 0 );\nfinal color colorEmpty= color( 0 );\nfinal color colorWall = color( 0, 255, 0 );\nfinal color colorTemp = color( 0, 0, 255 );\n\nclass LifeLikeCA\n{\n    //PImage field, buff;\n    \n    boolean[][] field, buff;\n    boolean[][] space, seed, wall, temp;\n    boolean[] birth = new boolean[ 9 ],\n              survive = new boolean[ 9 ];\n              \n    int[][] neighborsOffset = {\n        {  0, -1 },\n        { +1, -1 },\n        { +1,  0 },\n        { +1, +1 },\n        {  0, +1 },\n        { -1, +1 },\n        { -1,  0 },\n        { -1, -1 }\n    };\n    \n    int fw, fh;\n    int spaceCount;\n    int gen = 0;\n    \n    LifeLikeCA( PImage _initCond, int[] _birthCond, int[] _surviveCond ) {\n        \n        fw = _initCond.width;\n        fh = _initCond.height;\n        \n        // init field\n        field = new boolean[ fw ][ fh ];\n        buff  = new boolean[ fw ][ fh ];\n        \n        space = new boolean[ fw ][ fh ];\n        seed  = new boolean[ fw ][ fh ];\n        wall  = new boolean[ fw ][ fh ];\n        temp  = new boolean[ fw ][ fh ];\n        \n        color c;\n        \n        for ( int y = 0; y < fh; y++ ) {\n            for ( int x = 0; x < fw; x++ ) {\n                \n                c = _initCond.get( x, y );\n                \n                field[ x ][ y ] = c == colorSeed ? random(1) <= rate : false;\n                // init attr\n                space[x][y] = c != colorEmpty;\n                \n                seed[ x ][ y ] = c == colorSeed;\n                wall[ x ][ y ] = c == colorWall;\n                temp[ x ][ y ] = c == colorTemp;\n                \n                if ( x == 5 && y == 3 ) {\n                    println( seed[x][y] );\n                    println( red(c), green(c), blue(c) );\n                }\n                \n            }\n        }\n        \n        // init rules\n        for ( int i = 0; i < 8; i++ ) {\n            survive[i] = false;\n            birth[i] = false;\n        }\n    \n        for ( int i = 0; i < _surviveCond.length; i++ ) {\n            survive[ _surviveCond[i] ] = true;\n        }\n        for ( int i = 0; i < _birthCond.length; i++ ) {\n            birth[ _birthCond[i] ] = true;\n        }\n    }\n    \n    void clear() {\n        \n        for ( int y = 0; y < fh; y++ ) {\n            for ( int x = 0; x < fw; x++ ) {\n                field[ x ][ y ] = false;\n            }\n        }\n    }\n    \n    void updateSeed( PImage seedImg ) {\n        \n        //int seedCount = 0;\n    \n        color c;\n        for ( int y = 0; y < fh; y++ ) {\n            for ( int x = 0; x < fw; x++ ) {\n                c = seedImg.get( x, y );\n                seed[ x ][ y ] = c == colorSeed;\n                field[ x ][ y ] |= c == colorSeed; \n            }\n        }\n    }\n    \n    \n    void draw() {\n    \n        int x, y;\n        \n        noStroke();\n        \n        for ( y = 0; y < fh; y++ ) {\n            for ( x = 0; x < fw; x++ ) {\n                fill( field[ x ][ y ] ? colorAlive : colorDead );\n                rect( x, y, 1, 1 );\n            }\n        }\n    \n    }\n    \n    void save( String name ) {\n        //field.save( name );\n    }\n    \n    int width() {\n        return fw;\n    }\n    \n    int height() {\n        return fh;\n    }\n    \n    void update() {\n        \n        int x, y;\n        int alives;\n        \n        for ( y = 0; y < fh; y++ ) {\n            for (x = 0; x < fw; x++ ) {\n                buff[ x ][ y ] = field[ x ][ y ];\n            }\n        }\n    \n        for ( y = 0; y < fh; y++ ) {\n            for ( x = 0; x < fw; x++ ) {\n                if ( space[ x ][ y ] ) {\n                    if ( wall[ x ][ y ] ) {\n                        wall[ x ][ y ] = !canDestroyWall( x, y );\n                    } else {\n                        alives = getAliveCount( x, y ); \n                        field[ x ][ y ] = buff[ x ][ y ] ? survive[ alives ] : birth[ alives ];\n                    }\n                }\n            }\n        }\n        \n        gen++;\n    }\n    \n    boolean canDestroyWall( int x, int y ) {\n        \n        int ox, oy;\n        \n        for ( int i = 0; i < neighborsOffset.length; i++ ) {\n            ox = x + neighborsOffset[i][0];\n            oy = y + neighborsOffset[i][1];\n            if ( ox < 0 || fw <= ox || oy < 0 || fh <= oy ) {\n                continue;\n            }\n            if ( !seed[ ox ][ oy ] && buff[ ox ][ oy ] ) {\n                return true;\n            }\n        }\n        \n        return false;\n    }\n    \n    int getAliveCount( int x, int y ) {\n    \n        int neighbors = 0;\n    \n        neighbors += getStatus(  x , y-1 ) ? 1 : 0;\n        neighbors += getStatus( x+1, y-1 ) ? 1 : 0;\n        neighbors += getStatus( x+1,  y  ) ? 1 : 0;\n        neighbors += getStatus( x+1, y+1 ) ? 1 : 0;\n        neighbors += getStatus(  x , y+1 ) ? 1 : 0;\n        neighbors += getStatus( x-1, y+1 ) ? 1 : 0;\n        neighbors += getStatus( x-1,  y  ) ? 1 : 0;\n        neighbors += getStatus( x-1, y-1 ) ? 1 : 0;\n    \n        return neighbors;\n    }\n    \n    boolean getStatus( int x, int y ) {\n        if ( x < 0 || fw <= x || y < 0 || fh <= y ) {\n            return false;\n        } else {\n            return buff[ x ][ y ];\n        }\n    }\n    \n    \n}"
  },
  {
    "path": "p5/life_like_transition/life_like_transition.pde",
    "content": "//-------------------------------------------------------\n// config\n\nfinal String srcDir = \"../../ca/life-like-generation/_src\";\nfinal String dstDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/life-like-generation\";\nfinal String seedDir= \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/life-like-generation/_seed\";\n\nfinal boolean isSave = true;\n\nfinal int scale = 1;\n\n\nfinal color yellow = #FFFB44;\n\nfinal int mapEmpty       = 0;\nfinal int mapGenerated   = -2;\n\n\n//------------------------------\n// C UI Generate\n\n//String name = \"x11b_frame-only_sq\";\n//String name = \"x11b_radio\";\n//String name = \"metapixel-galaxy_corner\";\n//String name = \"x11b_button-c\";\n//String name = \"x11_planet|planet\";\n//String name = \"c_twin-button\";\n//String name = \"x11b_close\";\n//String name = \"c_saturn\";\n//String name = \"stars-sq3\";\n//String name = \"b-wire_1\";\n//String name = \"neuron-core\";\n//String name = \"x11b_button\";\n//String name = \"1sb_c4_wire\";\n\n\nfinal float rate = 1;\nfinal int maxLife = 5;\nfinal int maxTempLife = 1;  \nfinal int iterateCount = 2;\nfinal int aliveDur = 10;\nfinal boolean useSeedImg = false;\nfinal boolean needsSeparatedSeed = true;\nfinal int maxDur = 1000;\n\n//final int ratio = 2;\n\nint[] birthCond   = { 2, 3 };\nint[] surviveCond = { 2, 3 };\n\n\n//------------------------------\n// C UI Generate Galaxy\n\n//String name = \"galaxy_lg\";\n\n\n//final float rate = 0.5;\n//final int maxLife = 10;\n//final int maxTempLife = 4;\n//final int iterateCount = 1;\n//final int aliveDur = 8;\n//final boolean useSeedImg = true;\n//final boolean needsSeparatedSeed = false;\n//final int maxDur = 240;\n\n////final int ratio = 2;\n\n//int[] birthCond   = { 3 };\n//int[] surviveCond = { 2, 3 };\n\n\n//------------------------------\n// C extending line\n\n//String name = \"c_extending-line_1\";\n//String name = \"c_extending-line_2\";\n//String name = \"c_extending-line_3\";\n//String name = \"c_extending-line_4|a\";\n//String name = \"c_extending-line_4|b\";\n//String name = \"c_extending-line_5\";\n//String name = \"c_extending-line_6|a\";\n//String name = \"c_extending-line_6|b\";\n//String name = \"c_extending-line_7\";\n//String name = \"c_extending-line_8|a\";\n//String name = \"c_extending-line_8|b\";\n//String name = \"c_extending-line_9|a\";\n//String name = \"c_extending-line_9|b\";\n//String name = \"c_extending-line_10|a\";;\n//String name = \"c_extending-line_10|b\";\n\n//final float rate = 0.1;\n//final int maxLife = 3;\n//final int maxTempLife = 1; \n//final int iterateCount = 4;\n//final int aliveDur = 10;\n//final boolean useSeedImg = true;\n//final boolean needsSeparatedSeed = true;\n//final int maxDur = 50;\n\n////final int ratio = 2;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n//-------------------------------------------------------\n// main\n\n\n// var\n\nString[] arguments;\n\nint cx, cy;\n\nLifeLikeCA ca;\n\nint[][] map;\nint[][] curtDur;\n\nPImage initImg, uiImg;\nPImage renderImg;\n\nFile[] seedFiles;\nPImage seedImg;\n\nboolean isFinished;\n\nint ratio;\n\n\nvoid setup() {\n\n    load();\n\n    // draw\n    frameRate( 10 );\n    noSmooth();\n    background( 0 );\n}\n\nvoid load() {\n\n    // clean dst folder\n    File dstFolder = new File( dstDir + \"/\" + name );\n    deleteFile( dstFolder );\n\n    if ( useSeedImg ) {\n        File seedFolder = new File( seedDir + \"/\" + name );\n        seedFiles = seedFolder.listFiles();\n    }\n\n    if ( needsSeparatedSeed ) {\n        String initPath = srcDir + \"/\" + name + \"_seed.png\";\n        String uiPath   = srcDir + \"/\" + name + \".png\";\n        initImg = loadImage( initPath );\n        uiImg    = loadImage( uiPath );\n    } else {\n        String initPath = srcDir + \"/\" + name + \".png\";\n        initImg = loadImage( initPath );\n        uiImg = createImage( initImg.width, initImg.height, ARGB );\n    }\n\n    // init ca\n    \n    renderImg = createImage( uiImg.width, uiImg.height, ARGB );\n\n    ca = new LifeLikeCA( initImg, birthCond, surviveCond );\n    \n    ratio = renderImg.width / ca.width();\n    \n    println( ratio );\n\n    if ( useSeedImg ) {\n        ca.clear();\n    }\n\n    // init generated map\n    map = new int[ ca.width() ][ ca.height() ];\n    curtDur = new int[ ca.width() ][ ca.height() ];\n    for ( int y = 0; y < ca.height(); y++ ) {\n        for ( int x = 0; x < ca.width(); x++ ) {\n            map[ x ][ y ] = mapEmpty;\n        }\n    }\n\n    changeWindowSize( renderImg.width * scale, renderImg.height * scale );\n}\n\nvoid next() {\n    \n    if ( useSeedImg && frameCount - 1 < seedFiles.length ) {\n        seedImg = loadImage( seedFiles[ frameCount - 1 ].getAbsolutePath() );\n        ca.updateSeed( seedImg );\n        \n        for ( int y = 0; y < ca.height(); y++ ) {\n            for ( int x = 0; x < ca.width(); x++ ) {\n                if ( seedImg.get(x, y) == colorSeed && map[x][y] == mapEmpty ) {\n                    map[x][y] = 1;\n                }\n            }\n        }\n    }\n    \n    ca.update();\n    \n    isFinished = true;\n    \n    for ( int y = 0; y < ca.height(); y++ ) {\n\n        for ( int x = 0; x < ca.width(); x++ ) {\n            \n            if ( map[ x ][ y ] == mapGenerated ) {\n                continue;\n            }\n            \n            if ( xor( map[x][y] % 2 == 1, ca.field[x][y] ) ) {\n                \n                // if field changed\n                map[x][y]++;\n                curtDur[x][y] = 0;\n                \n            } else if ( map[x][y] != mapEmpty ) {\n                \n                // if not changed, increment \n                curtDur[x][y]++;\n            }\n            \n            // detect if the cell have to become \"generated\"\n            if ( map[x][y] != mapEmpty ) {\n                \n               if ( !ca.temp[x][y] ) {\n                   if ( curtDur[x][y] == aliveDur || map[x][y] == maxLife * 2 ) {\n                       map[x][y] = mapGenerated;\n                   }\n               } else {\n                   if ( curtDur[x][y] == aliveDur || map[x][y] == maxTempLife * 2 ) {\n                       map[x][y] = mapGenerated;\n                   }\n               }\n            }\n            \n            if ( ca.space[x][y] && (map[x][y] == mapEmpty || map[x][y] % 2 == 1) ) {\n                isFinished = false;\n            }\n        }\n    }\n\n    \n}\n\nvoid draw() {\n    \n    println( \"frame: \" +  (frameCount - 1) );\n\n    for ( int i = 0; i < iterateCount; i++ ) {\n        next();\n    }\n\n    noStroke();\n    background( 0 );\n    resetMatrix();\n    scale( scale );\n\n    color c;\n\n    for ( int y = 0; y < ca.height(); y++ ) {\n        for ( int x = 0; x < ca.width(); x++ ) {\n            \n            for ( int sy = 0; sy < ratio; sy++ ) {\n                for ( int sx = 0; sx < ratio; sx++ ) {\n                    \n                    if ( map[x][y] == mapEmpty ) {\n                      c = 0x0;\n                    } else if ( map[x][y] % 2 == 0 ) { // dead & pseudo dead\n                      c = uiImg.get( x*ratio + sx, y*ratio + sy );\n                    } else {\n                      c = yellow;\n                    }\n                    \n                    renderImg.set( x*ratio + sx, y*ratio + sy, c );\n                }\n            }\n        }\n    }\n    \n    //tint( 0, 0, 100 );\n    //image( initImg, 0, 0 );  \n    \n    //tint( 255 );\n\n    image( renderImg, 0, 0 );\n\n    if ( isSave ) {\n        renderImg.save( dstDir + \"/\" + name + \"/\" + name + \"_\" + String.format(\"%04d\", frameCount - 1) + \".png\" );\n    }\n\n    if ( isFinished || frameCount == maxDur ) {\n       println( \"duration:\" + frameCount );\n       exit();\n    }\n}"
  },
  {
    "path": "p5/life_like_transition/rules.pde",
    "content": "//// conway's game of life\n//int[] birthNum   = { 3 };\n//int[] surviveNum = { 2, 3 };\n\n//// replicator\n//int[] birthNum   = { 1, 3, 5, 7 };\n//int[] surviveNum = { 1, 3, 5, 7 };\n\n// small-replicator\n//int[] birthNum   = { 2, 5 };\n//int[] surviveNum = { 4 };\n\n// 34 Life\n//int[] birthNum   = { 3, 4 };\n//int[] surviveNum = { 3, 4 };\n\n// 2x2\n//int[] birthNum   = { 3, 6 };\n//int[] surviveNum = { 1, 2, 5 };\n\n// day and night\n//int[] birthNum   = { 3, 6, 7, 8 };\n//int[] surviveNum = { 3, 4, 6, 7, 8 };\n\n// HighLife\n//int[] birthNum   = { 3, 6 };\n//int[] surviveNum = { 2, 3 };\n\n//Morley\n//int[] birthNum   = { 3, 6, 8 };\n//int[] surviveNum = { 2, 4, 5 };\n\n// Diamoeba\n//int[] birthNum   = { 3, 5, 6, 7, 8 };\n//int[] surviveNum = { 5, 6, 7, 8 };\n\n// explosive one\n//int[] birthNum   = { 1, 7 };\n//int[] surviveNum = { 7, 8 };\n\n// explosive two\n//int[] birthNum   = { 1, 4, 5 };\n//int[] surviveNum = { 3, 4 };\n\n// gnarl\n//int[] birthNum   = { 1, 2 };\n//int[] surviveNum = { 1 };\n\n//// coagulations\n//int[] birthNum   = { 3, 7, 8 };\n//int[] surviveNum = { 2, 3, 4, 5, 6, 7, 8 };\n\n//// maze\n//int[] birthNum   = { 3 };\n//int[] surviveNum = { 1, 2, 3, 4, 5 };\n\n// maze\n//int[] birthNum   = { 1, 2, 3, 4, 5, 6 ,7, 8 };\n//int[] surviveNum = { 1, 2, 3, 4, 5 };\n\n// ameba\n//int[] birthNum   = { 1, 3, 5, 8 };\n//int[] surviveNum = { 3, 5, 7 };\n\n// exploding chaos in seeds\n//int[] birthNum   = { 2 };\n//int[] surviveNum = {  };\n\n// coral\n//int[] birthNum   = { 3 };\n//int[] surviveNum = { 4, 5, 6, 7, 8 };"
  },
  {
    "path": "p5/life_like_transition/settings.pde",
    "content": "//------------------------------\n// GUI params\n\n//String name = \"x11b_frame-only_sq\";\n\n//final float rate = 0.8;\n//final int maxLife = 2;\n//final int maxTempLife = 1; \n//final int iterateCount = 1;\n//final int aliveDur = 40;\n//final boolean useSeedImg = false;\n//final boolean needsSeparatedSeed = true;\n//final int maxDur = 180;\n\n//int[] birthCond   = { 1, 7 };\n//int[] surviveCond = { 7, 8 };\n\n//------------------------------\n// GUI params (manual)\n//final float rate = 1;\n//final int maxLife = 2;\n//final int maxTempLife = 1;\n//final int iterateCount = 1;\n//final int aliveDur = 10;\n//final boolean useSeedImg = false;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n//------------------------------\n// CUI params\n//final float rate = 1.0; // all\n//final int maxLife = 2;\n//final int maxTempLife = 1;\n//final int iterateCount = 1;\n//final int aliveDur = 10;\n//final boolean useSeedImg = true;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n\n\n//------------------------------\n// Expanding ( maze, contour ) -> P\n//final float rate = 1; // all\n//final int maxLife = 2;\n//final int maxTempLife = 1;\n//final int iterateCount = 3;\n//final int aliveDur = 10;\n//final boolean useSeedImg = false;\n\n//int[] birthCond   = { 3 };\n//int[] surviveCond = { 1,2,3,4 };\n\n//------------------------------\n// Expanding -> B\n//final float rate = 1; // all\n//final int maxLife = 3;\n//final int maxTempLife = 1;\n//final int iterateCount = 1;\n//final int aliveDur = 10;\n//final boolean useSeedImg = false;\n//final boolean needsSeparatedSeed = false;\n\n//int[] birthCond   = { 3 };\n//int[] surviveCond = { 2, 3 };\n\n//------------------------------\n// Expanding -> B\n//String name = \"city\";\n\n//final float rate = 1; // all\n//final int maxLife = 30000;\n//final int maxTempLife = 1;\n//final bint iterateCount = 1;\n//final int aliveDur = 100000;\n//finabl boolean useSeedImg = false;\n//final boolean needsSeparatedSeed = false;\n\n//int[] birthCond   = { 3 };\n//int[] surviveCond = { 1, 2, 3,b 4, 5 };\n\n//------------------------------\n// City Generatebbewg\n//String name = \"city_generate\";\n\n//final float rate = 1;\n//final int maxLife = 3;\n//final int maxTempLife = 1;\n//final int iterateCount = 1;\n//final int aliveDur = 10;\n//final boolean useSeedImg = true;bb\n//final boolean needsSeparatedSeed = true;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n//------------------------------\n// City Generate (fuulsize)\n//String name = \"city_fullsize\";\n\n//final float rate = 1;\n//final int maxLife = 3;\n//final int maxTempLife = 1;\n//final int iterateCount = 1;\n//final int aliveDur = 5;\n//final boolean useSeedImg = true;\n//final boolean needsSeparatedSeed = true;\n//final int maxDur = 180;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n\n//------------------------------\n// B over\n//String name = \"b_over_2\";\n//String name = \"b_top\";\n//String name = \"box_gen\";\n\n//final float rate = 1;\n//final int maxLife = 3;\n//final int maxTempLife = 1; \n//final int iterateCount = 1;\n//final int aliveDur = 10;\n//final boolean useSeedImg = false;\n//final boolean needsSeparatedSeed = true;\n//final int maxDur = 1000;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n//------------------------------\n// B side\n//String name = \"b_side\";\n\n//final float rate = 1;\n//final int maxLife = 5;\n//final int maxTempLife = 1; \n//final int iterateCount = 1;\n//final int aliveDur = 30;\n//final boolean useSeedImg = true;\n//final boolean needsSeparatedSeed = true;\n\n//final int maxDur = 275;gbg\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n\n//------------------------------\n// Vanish\n//String name = \"b_start_minimized\";\n//String name = \"b_start_terminal\";\n//String name = \"b_start_emacs\";\n//String name = \"b_start_toolbar\";\n\n//final float rate = 1;\n//final int maxLife = 3;\n//final int maxTempLife = 1; \n//final int iterateCount = 1;\n//final int aliveDur = 30;\n//final boolean useSeedImg = false;\n//final boolean needsSeparatedSeed = true;\n\n//final int maxDur = 275;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };\n\n\n//------------------------------\n// B extendingv\n//String name = \"b_start_terminal_extending\";\n//String name = \"b_start_emacs_extending\";\n//String name = \"b_start_toolbar_extending\";\n\n//final float rate = 1;\n//final int maxLife = 5;\n//final int maxTempLife = 1; \n//final int iterateCount = 3;\n//final int aliveDur = 20;\n//final boolean useSeedImg = true;\n//final boolean needsSeparatedSeed = false;\n\n//final int maxDur = 117;\n\n//int[] birthCond   = { 2, 3 };\n//int[] surviveCond = { 2, 3 };"
  },
  {
    "path": "p5/life_like_transition/util.pde",
    "content": "\n\nint getStatus( PImage field, int x, int y ) {\n\n    if ( x < 0 || field.width <= x || y < 0 || field.height <= y ) {\n        return 0;\n    } else {\n\n        return field.get( x, y ) != colorDead ? 1 : 0;\n    }\n}\n\nvoid changeWindowSize(int w, int h) {\n\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n    \n}\n\nString[] getArgs( String[] defaults ) {\n    \n    String[] arguments = new String[ defaults.length ];\n    \n    try {\n        for ( int i = 0; i < args.length; i++ ) {\n            arguments[i] = args[i];\n        }\n    } catch ( Exception e ) {\n    }\n    \n    for ( int i = 0; i < defaults.length; i++ ) {\n        if ( arguments[i] == null ) {\n            arguments[i] = defaults[i];\n        }\n    }\n    \n    return arguments;\n}\n\nvoid deleteFile( File f ) {\n\n    if ( !f.exists() ) {\n        return;\n    }\n    \n    if ( f.isFile() ) {\n    \n        f.delete();\n    \n    } else if ( f.isDirectory() ) {\n        \n        File[] files = f.listFiles();\n        \n        for ( int i = 0; i < files.length; i++ ) {\n            deleteFile( files[i] );\n        }\n        \n        f.delete();\n    }\n}\n\nboolean xor( boolean a, boolean b ) {\n    return (a && !b) || (!a && b);\n}"
  },
  {
    "path": "p5/morphing/morphing.pde",
    "content": "//-------------------------------------------------------\n// cofing\n\nString srcFolder = \"../_dat/lg\";\n\nint cellWidth = 4;\nint frameDuration = 4;\n\nfloat gamma = 1;\n\nboolean isSave = false;\n\n//-------------------------------------------------------\n// main\n\nFile[] files = null;\nint index = 0;\nint counter = 0;\n\nPImage img, prevImg, changedImg;\n\nint mapWidth, mapHeight;\n\nArrayList<Integer> sides = new ArrayList<Integer>();\nArrayList<Integer> corners = new ArrayList<Integer>();\n\nboolean[] flgNbr = { false, false, false, false, false, false, false, false };\n\nPVector[] neighborVec = {\n    new PVector( 0, -1),\n    new PVector(+1, -1),\n    new PVector(+1,  0),\n    new PVector(+1, +1),\n    new PVector( 0, +1),\n    new PVector(-1, +1),\n    new PVector(-1,  0),\n    new PVector(-1, -1)\n};\n\n\nvoid setup() {\n    \n   noSmooth();\n\n   files = listImageFiles(srcFolder);\n   \n   println(files.length);\n\n   img = loadImage(files[0].getAbsolutePath());\n   mapWidth = img.width;\n   mapHeight = img.height;\n   \n   changedImg = createImage(mapWidth, mapHeight, ARGB);\n\n   changeWindowSize(mapWidth * cellWidth, mapHeight * cellWidth);\n   noStroke();\n   \n   index++;\n}\n\nvoid draw() {\n    \n    background( 0 );\n    \n    color c, pc;\n    int dir;\n    \n    if ( counter == 0 ) {\n        \n        println(\"loading..\" + index);\n        img = loadImage(files[index].getAbsolutePath());\n        prevImg = loadImage(files[index-1].getAbsolutePath());\n   \n        for (int y = 0; y < mapHeight; y++) {\n            for (int x = 0; x < mapWidth; x++) {\n                \n                c = img.get( x, y );\n                pc = prevImg.get( x, y );\n                \n                // detect changed pix\n                if ( c != pc ) {\n                    dir = getDir(x, y, c);\n                    changedImg.set(x, y, color(c, dir + 1));\n                \n                } else {\n                    \n                    changedImg.set(x, y, color(0));\n                 \n                }\n            }\n        }\n        \n        if ( ++index == files.length ) {\n            exit();\n        }\n \n    }\n    \n    // draw animation\n    float t = float(counter) / frameDuration;\n    t = (float) Math.pow( t, gamma );\n\n    image(prevImg, 0, 0, mapWidth * cellWidth, mapHeight * cellWidth );\n    \n    for (int y = 0; y < mapHeight; y++) {\n        for (int x = 0; x < mapWidth; x++) {\n            \n            c = changedImg.get(x, y);\n            dir = int(alpha(c) - 1);\n            \n            if ( alpha(c) > 0 ) {\n                \n                resetMatrix();\n                scale( cellWidth );\n                translate( x, y );\n                \n                // normal\n                fill(color( red(c), green(c), blue(c)));\n                \n                if (dir == 0 )         rect(0, 0, 1, t);\n                else if (dir == 2)    rect(1-t, 0, t, 1);\n                else if (dir == 4)    rect(0, 1-t, 1, t);\n                else if (dir == 6)    rect(0, 0, t, 1);\n                \n                else if (dir == 1)    rect(1-t, 0, t, t );\n                else if (dir == 3)    rect(1-t, 1-t, t, t );\n                else if (dir == 5)    rect(1-t, 0, t, t );\n                else if (dir == 7)    rect(0, 0, t, t );\n                \n                else if (dir == 9)    rect((1-t)/2, (1-t)/2, t, t);\n                \n            } else {\n            \n            }\n        }\n    }\n    \n    if (isSave) {\n        saveFrame(\"out/morphing_#####.png\");\n    }\n    \n    // next\n    counter = ( counter + 1 ) % frameDuration;\n}\n\n\n// radial direction\n//int getDir( int x, int y ) {\n    \n//    int dir = 9; // koritsu\n    \n//    // search neighbor pixels\n//    for ( i = 0; i < neighborVec.length; i++ ) {\n        \n//        nx = x + int( neighborVec[i].x );\n//        ny = y + int( neighborVec[i].y );\n        \n//        flgNbr[i] = prevImg.get( nx, ny ) == c;\n//    }\n    \n//    sides.clear();\n    \n//    for ( i = 0; i < flgNbr.length; i+= 2 ) {\n//        if ( flgNbr[i] ) {\n//            sides.add( i );\n//        }\n//    }\n    \n//    if ( sides.size() > 0 ) {\n        \n//        int n = int( random( 0, sides.size() );\n//        dir = sides.get(n);\n    \n//    } else {\n        \n//        //dir = int( random(0, 4) * 2;\n        \n//        // normalized uv\n//        float u = x / float( mapWidth );\n//        float v = y / float( mapHeight );\n        \n//        if ( v > u ) {\n//            if ( v > -u + 1 ) {\n//                dir = 0;\n//            } else {\n//                dir = 2;\n//            }\n//        } else {\n//            if ( v > -u + 1 ) {\n//                dir = 6;\n//            } else {\n//                dir = 4;\n//            }\n//        }\n//    }\n//    return dir;\n//}\n\n// uniform direction\nint getDir(int x, int y, color targetColor) {\n    \n    int dir = 9; // alone\n    \n    // search neighbor pixels\n    for (int i = 0; i < neighborVec.length; i++) {\n        int nx = x + int(neighborVec[i].x);\n        int ny = y + int(neighborVec[i].y);\n        \n        flgNbr[i] = prevImg.get(nx, ny) == targetColor;\n    }\n    \n    sides.clear();\n    \n    for (int i = 0; i < flgNbr.length; i+= 2) {\n        if (flgNbr[i]) {\n            sides.add(i);\n        }\n    }\n    \n    if (sides.size() == 3) {\n        \n        if (!flgNbr[0])        dir = 4;\n        else if (!flgNbr[2])   dir = 6;\n        else if (!flgNbr[4])   dir = 0;\n        else if (!flgNbr[6])   dir = 2;\n    \n    } else if (sides.size() > 0) {\n        \n        int n = int(random(0, sides.size()));\n        dir = sides.get(n);\n    \n    } else {\n        \n        corners.clear();\n        \n        for (int i = 1; i < flgNbr.length; i += 2) {\n            if (flgNbr[i]) {\n                corners.add( i );\n            }\n        }\n        \n        if (corners.size() > 0) {\n            int n = int(random( 0, corners.size()));\n            dir = corners.get(n);  \n        } \n    }\n    \n    return dir;\n}"
  },
  {
    "path": "p5/morphing/util.pde",
    "content": "import java.io.FilenameFilter;\n\nvoid changeWindowSize(int w, int h) {\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n}\n\nFile[] listImageFiles(String path) {\n    \n    File file = new File(resolveRelativePath(path));\n    \n    if (file.isDirectory()) {\n        \n        FilenameFilter filter = new FilenameFilter() {\n            public boolean accept(File dir, String name) {\n                String ext = \"\";\n                int dotIndex = name.lastIndexOf('.');\n                if ((dotIndex > 0) && (dotIndex < name.length() - 1 )) {\n                    ext = name.substring(dotIndex + 1).toLowerCase();\n                }\n                return (ext.equals(\"png\"));\n            }\n        };\n        return file.listFiles(filter);\n        \n    } else {\n        // If it's not a directory\n        return null;\n    }\n}\n\nString resolveRelativePath(String path) {\n    File file = new File(sketchPath(\"\") + path);\n    try {\n        return file.getCanonicalPath();\n    } catch (Exception e) {\n        return null;\n    }\n}"
  },
  {
    "path": "p5/shiki/morph.pde",
    "content": "int DIR_STATIC = -1;\n\nclass Morph {\n\n    int cellSize;\n    int w, h;\n    int interval = 3;\n    float gamma = 0.7; // 1: linear\n\n    PImage curtImg, prevImg;\n    PGraphics pg;\n    \n    int[][] dirs;\n\n    // var\n    int counter = 0;\n    boolean[] flgNbr = new boolean[ 8 ];\n    ArrayList< Integer > sides = new ArrayList< Integer >();\n\n    float t;\n    int i, x, y, dir, nx, ny;\n    color c, pc;\n\n    // const\n    PVector[] neighborVec = {\n        new PVector(  0, -1 ), \n        new PVector( +1, -1 ), \n        new PVector( +1, 0 ), \n        new PVector( +1, +1 ), \n        new PVector(  0, +1 ), \n        new PVector( -1, +1 ), \n        new PVector( -1, 0 ), \n        new PVector( -1, -1 )\n    };\n\n    Morph( int _w, int _h, int _cellSize ) {\n        w = _w;\n        h = _h;\n        cellSize = _cellSize;\n\n        curtImg = createImage( w, h, RGB );\n        prevImg = createImage( w, h, RGB );\n        dirs = new int[ w ][ h ];\n        \n        pg = createGraphics( getWidth(), getHeight() );\n    }\n\n    int getWidth() {\n        return w * cellSize;\n    }\n\n    int getHeight() {\n        return h * cellSize;\n    }\n    \n    PImage getImage() {\n        return pg.get();\n    }\n\n    boolean availableNewFrame() {\n        return counter == 0;\n    }\n\n    void addFrame( PImage img ) {\n\n        prevImg.copy( curtImg, 0, 0, w, h, 0, 0, w, h );\n        curtImg.copy( img, 0, 0, w, h, 0, 0, w, h );\n\n        // diff frame\n\n        for ( y = 0; y < h; y++ ) {\n            for ( x = 0; x < w; x++ ) {\n\n                c = curtImg.get( x, y );\n                pc = prevImg.get( x, y );\n\n                // detect changed pix\n                if ( c != pc ) {\n                    \n                    dirs[ x ][ y ] = getDir( x, y );\n                    \n                } else {\n\n                    dirs[ x ][ y ] = DIR_STATIC;\n                }\n            }\n        }\n    }\n\n    void update() {\n\n        t = float( counter ) / interval;\n        t = (float) Math.pow( t, gamma );\n\n        // animation\n        pg.beginDraw();\n        pg.resetMatrix();\n        pg.noStroke();\n        pg.noSmooth();\n\n        pg.background( 0 );\n        pg.image( prevImg, 0, 0, getWidth(), getHeight() );\n\n        for ( y = 0; y < h; y++ ) {\n           for ( x = 0; x < w; x++ ) {\n\n               dir = dirs[ x ][ y ];\n\n               if ( dir != DIR_STATIC ) {\n\n                   pg.resetMatrix();\n                   pg.scale( cellSize );\n                   pg.translate( x, y );\n\n                   // normal\n                   pg.fill( curtImg.get( x, y ) );\n\n                   if ( dir == 0 )         pg.rect( 0, 0, 1, t );\n                   else if ( dir == 2 )    pg.rect( 1-t, 0, t, 1 );\n                   else if ( dir == 4 )    pg.rect( 0, 1-t, 1, t );\n                   else if ( dir == 6 )    pg.rect( 0, 0, t, 1 );\n\n                   else if ( dir == 1 )    pg.rect( 1-t, 0, t, t );\n                   else if ( dir == 3 )    pg.rect( 1-t, 1-t, t, t );\n                   else if ( dir == 5 )    pg.rect( 1-t, 0, t, t );\n                   else if ( dir == 7 )    pg.rect( 0, 0, t, t );\n\n                   else if ( dir == 9 )    pg.rect( (1-t)/2, (1-t)/2, t, t );\n               }\n           }\n        }\n        pg.endDraw();\n\n\n        // increment counter\n        counter = ( counter + 1 ) % interval;\n    }\n\n    void draw( int x, int y ) {\n\n        image( pg, x, y );\n    }\n\n\n    int getDir( int x, int y ) {\n\n\n        int dir = 9; // koritsu\n\n        // search neighbor pixels\n        for ( i = 0; i < neighborVec.length; i++ ) {\n\n            nx = x + int( neighborVec[i].x );\n            ny = y + int( neighborVec[i].y );\n\n            flgNbr[i] = prevImg.get( nx, ny ) == c;\n        }\n\n        sides.clear();\n\n        for ( i = 0; i < flgNbr.length; i+= 2 ) {\n            if ( flgNbr[i] ) {\n                sides.add( i );\n            }\n        }\n\n        if ( sides.size() > 0 ) {\n\n            int n = int( random( 0, sides.size() ) );\n            dir = sides.get(n);\n        } else {\n\n            dir = int( random(0, 4) ) * 2;\n\n\n            // radial uv\n            /*\n            float u = x / float( mapW );\n             float v = y / float( mapH );\n             \n             if ( v > u ) {\n             if ( v > -u + 1 ) {\n             dir = 0;\n             } else {\n             dir = 2;\n             }\n             } else {\n             if ( v > -u + 1 ) {\n             dir = 6;\n             } else {\n             dir = 4;\n             }\n             }*/\n        }\n\n        return dir;\n    }\n}"
  },
  {
    "path": "p5/shiki/shiki.command",
    "content": "#!/bin/sh\n\ncd \"/Volumes/MugiRAID1/Works/2015/13_oxff/0b\"\n\nsketch=\"./shiki_morph\"\ndir=\"../ca/shiki/01_lg/*\"\n\n\n\nfor d in $dir ; do\n\n\tif echo $d | grep 128; then\n\t\tp5 $sketch --args $d 8\n\telif echo $d | grep 256; then\n\t\tp5 $sketch --args $d 8\n\telif echo $d | grep 512; then\n\t\tp5 $sketch --args $d 4\n\telif echo $d | grep 1024; then\n\t\tp5 $sketch --args $d 4\n\tfi\ndone"
  },
  {
    "path": "p5/shiki/shiki.pde",
    "content": "//-------------------------------------------------------\n// Settings\n\nString[] defaultArgs = {\n   \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/shiki-other/01_lg/lg_die_hard\",\n   \"16\"\n};\n\n//-------------------------------------------------------\n// Processing\n\nString srcFolder;\nString destFolder = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/shiki/02_anim\";\nint cellSize;\n\nString name;\nFile[] files = null;\n\nint index;\n\nMorph morph;\nUIConverter uiConverter;\n\nPImage result;\n\nvoid setup() {\n    \n   //frameRate( 60 );\n   frameRate( 10 );\n   noSmooth();\n    \n   String[] arguments = getArgs( defaultArgs );\n    \n   srcFolder = arguments[ 0 ];\n   cellSize = Integer.parseInt( arguments[ 1 ] );\n    \n   files = listFiles( srcFolder );\n   PImage img = loadImage( files[0].getAbsolutePath() );\n    \n   morph = new Morph( img.width, img.height, cellSize );\n   uiConverter = new UIConverter( morph.getWidth(), morph.getHeight() );\n    \n   name = ( new File( srcFolder ) ).getName().replace( \"_lg\",  \"\" );\n   \n   changeWindowSize( morph.getWidth(), morph.getHeight() );\n    \n   loadUI();\n   \n}\n\nvoid draw() {\n    \n   if ( morph.availableNewFrame() ) {\n        \n       PImage img = loadImage( files[ index++ ].getAbsolutePath() );\n       morph.addFrame( img );\n   }\n    \n   morph.update();\n    \n   result = uiConverter.convert( morph.getImage() );\n    \n   image( result, 0, 0 );\n    \n   String frameSuffix = String.format( \"%04d\", (frameCount-1) );\n   result.save( destFolder + \"/\" + name + \"_anim\" + \"/\" + name + \"_anim_\" + frameCount + \".png\" );\n    \n    \n   if ( index == files.length ) {\n       exit();\n   }\n}"
  },
  {
    "path": "p5/shiki/ui.pde",
    "content": "class UI {\n    \n   PImage uiTopLeft, uiTopRight, uiBottomLeft, uiBottomRight, uiTop, uiRight, uiBottom, uiLeft, uiCenter;\n   int top, right, bottom, left;\n    \n   String name;\n    \n   UI() { }\n    \n   UI( String path, int top, int right, int bottom, int left ) {\n        \n       this.top = top;\n       this.right = right;\n       this.bottom = bottom;\n       this.left = left;\n        \n       PImage img = loadImage( path );\n       int w = img.width, h = img.height;\n        \n       uiTopLeft     = decomposeToUIPart( img, 0, 0, left, top );\n       uiTopRight    = decomposeToUIPart( img, w - right, 0, right, top );\n       uiBottomLeft  = decomposeToUIPart( img, 0, h - bottom, left, bottom );\n       uiBottomRight = decomposeToUIPart( img, w - right, h - bottom, right, bottom );\n        \n       uiTop    = decomposeToUIPart( img, left, 0, w - left - right, top );\n       uiBottom = decomposeToUIPart( img, left, h - bottom, w - left - right, bottom );\n       uiLeft   = decomposeToUIPart( img, 0, top, left, h - top - bottom );\n       uiRight  = decomposeToUIPart( img, w - right, top, right, h - top - bottom );\n        \n       uiCenter = decomposeToUIPart( img, left, top, w - left - right, h - top - bottom ); \n   }\n    \n   boolean isSupport( Rect r ) {\n        \n       return r.w >= left + right + 1 && r.h >= top + bottom + 1;\n   }\n   \n   int getMinArea() {\n       return (left + right) * (top + bottom);\n    }\n    \n   void drawToGraphics( PGraphics pg, Rect r ) {\n        \n      int et = r.y + top,\n          er = r.x + r.w - right,\n          eb = r.y + r.h - bottom,\n          el = r.x + left,\n          ew = r.w - left - right,\n          eh = r.h - top - bottom;\n        \n       pg.image( uiTopLeft, r.x, r.y );\n       pg.image( uiTopRight, er, r.y );\n       pg.image( uiBottomLeft, r.x, eb );\n       pg.image( uiBottomRight, er, eb );\n        \n       pg.image( uiTop, el, r.y, ew, top );\n       pg.image( uiBottom, el, eb, ew, bottom );\n       pg.image( uiLeft, r.x, et, left, eh );\n       pg.image( uiRight, er, et, right, eh );\n        \n       pg.image( uiCenter, el, et, ew, eh );\n   }\n    \n   void draw( Rect r ) {\n        \n       int et = r.y + top,\n           er = r.x + r.w - right,\n           eb = r.y + r.h - bottom,\n           el = r.x + left,\n           ew = r.w - left - right,\n           eh = r.h - top - bottom;\n        \n       image( uiTopLeft, r.x, r.y );\n       image( uiTopRight, er, r.y );\n       image( uiBottomLeft, r.x, eb );\n       image( uiBottomRight, er, eb );\n        \n       image( uiTop, el, r.y, ew, top );\n       image( uiBottom, el, eb, ew, bottom );\n       image( uiLeft, r.x, et, left, eh );\n       image( uiRight, er, et, right, eh );\n        \n       image( uiCenter, el, et, ew, eh );\n        \n   }\n}\n\nPImage decomposeToUIPart( PImage img, int x, int y, int w, int h ) {\n   PImage part = createImage( w, h, RGB );\n    \n   part.copy( img, x, y, w, h, 0, 0, w, h );\n    \n   return part;\n}\n\n\nclass UIRect extends Rect {\n    \n   UI ui;\n\n   UIRect( UI ui, Rect r ) {\n        \n       super( r.x, r.y, r.w, r.h );\n       this.ui = ui;\n   }\n    \n   void draw() {\n        \n       ui.draw( this );\n   }\n\n}"
  },
  {
    "path": "p5/shiki/uiConverter.pde",
    "content": "import java.util.Collections;\nimport java.util.Comparator;  \n\nArrayList< UI > uiList = new ArrayList< UI >();\nString partsDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist-galaxy/_parts\";\nString uiPartsDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/cubist/parts\";\n\n\nclass UIComparator implements Comparator< UI > {\n    \n    public int compare(UI ui1, UI ui2) {\n        return ui1.getMinArea() < ui2.getMinArea() ? -1 : 1;\n    }\n}\n\n\nvoid loadUI() {\n    \n    // green\n    //uiList.add( new UI( uiPartsDir+\"/dot.png\", 1, 1, 1, 1 ) );\n    uiList.add( new UI( uiPartsDir+\"/button.png\", 2, 2, 2, 2 ) );\n    uiList.add( new UI( uiPartsDir+\"/icon.png\", 6, 6, 24, 6 ) );\n    uiList.add( new UI( uiPartsDir+\"/menu.png\", 19, 2, 1, 19 ) );\n    uiList.add( new UI( uiPartsDir+\"/button_b.png\", 8, 8, 8, 8 ) );\n    //uiList.add( new UI( uiPartsDir+\"/window_a.png\", 31, 54, 31, 31 ) );\n    \n    uiList.add( new UI( partsDir+\"/p00.png\", 3, 3, 3, 3 ) );\n    uiList.add( new UI( partsDir+\"/p04.png\", 8, 9, 8, 8 ) );\n    uiList.add( new UI( partsDir+\"/p06.png\", 8, 9, 8, 8 ) );\n    uiList.add( new UI( partsDir+\"/p10.png\", 5, 5, 13, 5 ) );\n    uiList.add( new UI( partsDir+\"/p13.png\", 6, 6, 6, 6 ) );\n    uiList.add( new UI( partsDir+\"/p15.png\", 16, 15, 14, 10 ) );\n    \n    \n    \n    // blue\n    //uiList.add( new UI( partsDir+\"/p02.png\", 1, 1, 1, 1 ) );\n    //uiList.add( new UI( partsDir+\"/p01.png\", 2, 2, 2, 2 ) );\n    //uiList.add( new UI( partsDir+\"/p03.png\", 6, 6, 6, 6 ) );\n    //uiList.add( new UI( partsDir+\"/p07.png\", 1, 1, 1, 1 ) );\n    //uiList.add( new UI( partsDir+\"/p08.png\", 8, 2, 2, 2 ) );\n    //uiList.add( new UI( partsDir+\"/p09.png\", 8, 2, 2, 6 ) );\n    //uiList.add( new UI( partsDir+\"/p11.png\", 5, 5, 13, 5 ) );\n    //uiList.add( new UI( partsDir+\"/p12.png\", 6, 6, 6, 6 ) );\n    //uiList.add( new UI( partsDir+\"/p14.png\", 16, 15, 14, 10 ) );\n    \n}\n\nclass UIConverter {\n    \n    ArrayList< UIRect > uiRects;\n    \n    int w, h;\n    PGraphics pg;\n    \n    // var\n    boolean[][] done;\n    int[][] maxArea, maxIndex;\n    \n    ArrayList< Rect > rects, tempRects;\n    ArrayList<Boolean> isEnough;\n    \n     \n    UIConverter( int _w, int _h ) {\n        \n        w = _w;\n        h = _h;\n        \n        pg = createGraphics( w, h );\n        \n        done = new boolean[w][h];\n        maxArea = new int[w][h];\n        maxIndex = new int[w][h];\n        \n        rects = new ArrayList< Rect >();\n        tempRects = new ArrayList< Rect >();\n        isEnough = new ArrayList< Boolean >();\n    }\n    \n    PImage convert( PImage img ) {\n        \n        ArrayList< Rect > rects = searchRect( img );\n        //ArrayList< UI > supported = new ArrayList< UI >();\n        \n        \n        pg.beginDraw();\n        pg.background( 0 );\n        pg.noStroke();\n        \n        int i, j;\n        Rect r;\n        UI ui = uiList.get( 0 );\n        int minArea = 0;\n        \n        for ( i = 0; i < rects.size(); i++ ) {\n            \n            r = rects.get( i );\n            \n            ui = null;\n            \n            for ( j = 0; j < uiList.size(); j++ ) {\n                \n                if ( uiList.get(j).isSupport(r) && minArea < uiList.get(j).getMinArea() ) {\n                    ui = uiList.get(j);\n                    minArea = uiList.get(j).getMinArea();\n                }\n            }\n            \n            if ( ui == null ) {\n                ui = uiList.get(0);\n            }\n            \n            ui.drawToGraphics( pg, r );\n            \n        }\n        \n        pg.endDraw();\n        return pg.get();\n    }\n    \n    ArrayList< Rect > searchRect( PImage img ) {\n        \n        //rects.clear();\n        //isEnough.clear();\n        //tempRects.clear();\n        \n        //int iterateNum = 1;\n        \n        //int x, y, x1, y1;\n        //int curtArea;\n        //int curtIndex;\n        //int smallerIndex;\n        \n        //boolean isMax = true;\n        \n        //Rect r;\n        \n        //for ( y = 0; y < h; y++ ) {\n        //    for ( x = 0; x < w; x++ ) {\n        //        done[ x ][ y ] = img.get( x, y ) == color( 0 );\n                \n        //    }\n        //}\n        \n        //for ( int i = 0; i < iterateNum; i++ ) {\n            \n        //    tempRects.clear();\n        //    isEnough.clear();\n            \n        //    // clear\n        //    for ( y = 0; y < h; y++ ) {\n        //        for ( x = 0; x < w; x++ ) {\n        //            maxArea[x][y] = 0;\n        //            maxIndex[x][y] = -1;\n        //        }\n        //    }\n            \n        //    // search\n        //    for ( y = 0; y < h; y++ ) {\n        //        for ( x = 0; x < w; x++ ) {\n                    \n        //            if ( !done[x][y]  ) {\n                        \n        //                r = findRect(x, y);\n        //                curtArea = r.w * r.h;\n        //                curtIndex = tempRects.size();\n                        \n        //                // search\n        //                isMax = true;\n        //                for ( y1 = r.y; y1 <= r.bottom() && isMax; y1++ ) {\n        //                    for ( x1 = r.x; x1 <= r.right(); x1++ ) {\n                                \n        //                        if ( maxArea[x1][y1] < curtArea ) {\n                                    \n        //                            smallerIndex = maxIndex[x1][y1];\n        //                            maxIndex[x1][y1] = curtIndex;\n        //                            maxArea[x1][y1] = curtArea;\n        //                            //println(\"A\");\n        //                            if ( smallerIndex != -1 ) {\n        //                                isEnough.set( smallerIndex, false );\n        //                            }\n                                    \n        //                        } else {\n        //                            isMax = false;\n        //                            break;\n        //                        }\n        //                    }\n        //                }\n                        \n        //                if ( !isMax ) {\n        //                    println(\"not\");\n        //                }\n                        \n        //                tempRects.add( r );\n        //                isEnough.add( isMax );\n        //            }\n        //        }\n        //    }\n            \n            //// add rects\n            //for ( int j = 0; j < tempRects.size(); j++ ) {\n                \n            //    if ( isEnough.get(j) ) {\n                    \n            //        r = tempRects.get(j);\n            //        rects.add( r );\n                    \n            //        for ( y1 = r.y; y1 <= r.bottom(); y1++ ) {\n            //           for ( x1 = r.x; x1 <= r.right(); x1++ ) {\n            //               done[x1][y1] = true;\n            //           }\n            //       }\n            //    }\n            //}\n        //} \n        \n        \n        int x, y, x1, y1;\n        \n        rects.clear();\n        \n        for ( y = 0; y < h; y++ ) {\n           for ( x = 0; x < w; x++ ) {\n               done[ x ][ y ] = img.get( x, y ) == color( 0 );\n                \n           }\n        }\n        \n        //addRect( 16 );\n        addRect( 8 );\n        addRect( 4 );\n        addRect( 2 );\n        addRect( 1 );\n        \n        \n        \n        return rects;\n    }\n    \n    void addRect( int minWidth ) {\n        \n        int x, y, x1, y1;\n        \n        for ( y = 0; y < h; y++ ) {\n           for ( x = 0; x < w; x++ ) {\n                \n               if ( !done[x][y] ) {\n                    \n                   // start searching\n                   Rect r = findRect( x, y );\n                   \n                   if ( r.w < minWidth || r.y < minWidth ) {\n                       continue;\n                   }\n                    \n                   for ( y1 = r.y; y1 <= r.bottom(); y1++ ) {\n                       for ( x1 = r.x; x1 <= r.right(); x1++ ) {\n                           done[x1][y1] = true;\n                       }\n                   }\n                   rects.add( r );\n               }\n           }\n        }\n    }\n    \n    \n    \n    Rect findRect( int x, int y ) {\n        \n        Rect r = new Rect( x, y, 1, 1 );\n        Rect outer = new Rect();\n    \n        // expand right\n        outer.copy( r );\n        do {\n            outer.w += 1;\n            \n            if ( isEmptyRectEdge( outer ) ) {\n                r.copy( outer );\n            } else {\n                break;\n            }\n        } while ( true );\n        \n        // expand bottom\n        outer.copy( r );\n        do {\n            outer.h += 1;\n            \n            if ( isEmptyRectEdge( outer ) ) {\n                r.copy( outer );\n            } else {\n                break;\n            }\n        } while ( true );\n        \n        return r;\n    }\n    \n    boolean isEmptyRectEdge( Rect r ) {\n    \n        if ( r.x < 0 || r.y < 0 || r.right() >= w || r.bottom() >= h ) {\n            return false;\n        }\n        \n        // horizontal edge\n        for ( int x = r.x; x <= r.right(); x++ ) {\n            if ( done[x][r.y] || done[x][r.bottom()] ) {\n                return false;\n            }\n        }\n        \n        // vertical edge\n        for ( int y = r.y; y <= r.bottom(); y++ ) {\n            if( done[r.x][y] || done[r.right()][y] ) {\n                return false;\n            }\n        }\n        \n        return true;\n    }\n    \n}\n   "
  },
  {
    "path": "p5/shiki/util.pde",
    "content": "void changeWindowSize(int w, int h) {\n\n    surface.setSize( w + frame.getInsets().left + frame.getInsets().right, h + frame.getInsets().top + frame.getInsets().bottom );\n    size(w, h);\n    \n}\n\n\n//taken from http://processing.org/learning/topics/directorylist.html\nFile[] listFiles(String dir) {\n File file = new File(dir);\n if (file.isDirectory()) {\n   File[] files = file.listFiles();\n   return files;\n } else {\n   // If it's not a directory\n   return null;\n }\n}\n\nString[] getArgs( String[] defaults ) {\n    \n    String[] arguments = new String[ defaults.length ];\n    \n    try {\n        for ( int i = 0; i < args.length; i++ ) {\n            arguments[i] = args[i];\n        }\n    } catch ( Exception e ) {\n    }\n    \n    for ( int i = 0; i < defaults.length; i++ ) {\n        if ( arguments[i] == null ) {\n            arguments[i] = defaults[i];\n        }\n    }\n    \n    return arguments;\n}\n\n\nclass Rect {\n\n    int x, y, w, h;\n    \n    Rect() {\n        x = y = w = h = 0;\n    }\n    \n    Rect( int _x, int _y, int _w, int _h ) {\n        x = _x;\n        y = _y;\n        w = _w;\n        h = _h;\n    }\n    \n    void print() {\n        println( x + \"\\t\" + y + \"\\t\" + w + \"\\t\" + h );\n    }\n    \n    int right() {\n        return x + w - 1;\n    }\n    \n    int bottom() {\n        return y + h - 1;\n    }\n    \n    float aspect() {\n        return float( w ) / float( h );\n    }\n    \n    void interpolate( float t, Rect a, Rect b ) {\n        \n        x = int( a.x + ( b.x - a.x ) * t );\n        y = int( a.y + ( b.y - a.y ) * t );\n        w = int( a.w + ( b.w - a.w ) * t );\n        h = int( a.h + ( b.h - a.h ) * t );\n    }\n    \n    void draw() {\n        rect( x, y, w, h );\n    }\n    \n    void copy( Rect r ) {\n        x = r.x;\n        y = r.y;\n        w = r.w;\n        h = r.h;\n    }\n}"
  },
  {
    "path": "p5/wolfram/CA.pde",
    "content": "class CA {\n\n    int[] cells;     // An array of 0s and 1s \n    int generation;  // How many generations?\n    int scl;         // How many pixels wide/high is each cell?\n\n    int[] rules;     // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}\n\n    CA(int[] r) {\n        rules = r;\n        scl = 1;\n        cells = new int[width/scl];\n        restart();\n    }\n    \n    // Set the rules of the CA\n    void setRules(int[] r) {\n        rules = r;\n    }\n    \n    // Make a random ruleset\n    void randomize() {\n        for (int i = 0; i < 8; i++) {\n            rules[i] = int(random(2));\n        }\n    }\n    \n    // Reset to generation 0\n    void restart() {\n        for (int i = 0; i < cells.length; i++) {\n            cells[i] = 0;\n        }\n        //cells[cells.length/3] = 1;    // We arbitrarily start with just the middle cell having a state of \"1\"\n        \n        for ( int i = 0; i < 5; i++ ) {\n            cells[ int( random( cells.length ) ) ] = 1;\n        }\n        \n        generation = 0;\n    }\n\n    // The process of creating the new generation\n    void generate() {\n        \n        int[] nextgen = new int[cells.length];\n        \n        for ( int i = 1; i < cells.length-1; i++ ) {\n            int left = cells[i-1];\n            int me = cells[i];\n            int right = cells[i+1];\n            nextgen[i] = executeRules( left, me, right );\n        }\n        \n        for ( int i = 1; i < cells.length-1; i++ ) {\n            cells[i] = nextgen[i];\n        }\n        generation++;\n    }\n    \n    void render() {\n        for (int i = 0; i < cells.length; i++) {\n            if (cells[i] == 1) {\n                fill(255);\n            } else { \n                fill(0);\n            }\n            noStroke();\n            rect(i*scl,generation*scl, scl,scl);\n        }\n    }\n    \n    // Implementing the Wolfram rules\n    // Could be improved and made more concise, but here we can explicitly see what is going on for each case\n    int executeRules ( int a, int b, int c ) {\n        if (a == 1 && b == 1 && c == 1) { return rules[0]; }\n        if (a == 1 && b == 1 && c == 0) { return rules[1]; }\n        if (a == 1 && b == 0 && c == 1) { return rules[2]; }\n        if (a == 1 && b == 0 && c == 0) { return rules[3]; }\n        if (a == 0 && b == 1 && c == 1) { return rules[4]; }\n        if (a == 0 && b == 1 && c == 0) { return rules[5]; }\n        if (a == 0 && b == 0 && c == 1) { return rules[6]; }\n        if (a == 0 && b == 0 && c == 0) { return rules[7]; }\n        return 0;\n    }\n    \n    // The CA is done if it reaches the bottom of the screen\n    boolean finished() {\n        if (generation > height/scl) {\n             return true;\n        } else {\n             return false;\n        }\n    }\n}"
  },
  {
    "path": "p5/wolfram/wolfram.pde",
    "content": "// https://processing.org/examples/wolfram.html\n\n\nCA ca;   // An instance object to describe the Wolfram basic Cellular Automata\n\nboolean isFinished = false;\n\n\nvoid setup() {\n    size( 640, 640 );\n    \n    int[] ruleset = { 1, 0, 0, 1, 1, 0, 0, 1 };    // An initial rule system\n    ca = new CA( ruleset );                 // Initialize CA\n    background( 0 );\n}\n\nvoid draw() {\n    \n    if ( !isFinished ) {\n\t\tca.render();    // Draw the CA\n\t\tca.generate();  // Generate the next level\n    }\n  \n    isFinished = ca.finished();\n}\n\nvoid mousePressed() {\n    \n    ca.restart();\n}"
  },
  {
    "path": "p5js/cell-diffuse/index.html",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"UTF-8\">\n    <title>Untitled</title>\n    <script src=\"http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.9/p5.js\" type=\"text/javascript\"></script>\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js\" type=\"text/javascript\"></script>\n\n    <!--<script src=\"libraries/p5.dom.js\" type=\"text/javascript\"></script>\n    <script src=\"libraries/p5.sound.js\" type=\"text/javascript\"></script>-->\n\n    <script src=\"sketch.js\" type=\"text/javascript\"></script>\n\n    <style> body {padding: 0; margin: 0; background: white;} </style>\n  </head>\n  <body>\n  </body>\n</html>\n"
  },
  {
    "path": "p5js/cell-diffuse/save-sequence.php",
    "content": "<?\n header(\"Access-Control-Allow-Origin: *\");\n\n//canvasデータがPOSTで送信されてきた場合\n$canvas = $_POST[\"image\"];\n$path = $_POST[\"path\"];\n \n//ヘッダに「data:image/png;base64,」が付いているので、それは外す\n$canvas = preg_replace(\"/data:[^,]+,/i\",\"\",$canvas);\n \n//残りのデータはbase64エンコードされているので、デコードする\n$canvas = base64_decode($canvas);\n \n//まだ文字列の状態なので、画像リソース化\n$image = imagecreatefromstring($canvas);\n\n$dir = dirname( $path );\n\nif ( !file_exists( $dir ) ) {\n    mkdir( $dir, 0777, true);\n}\n\n \n//画像として保存（ディレクトリは任意）\n// imagesavealpha($image, false); // 透明色の有効\nimagepng($image, $path );\n\n?>"
  },
  {
    "path": "p5js/cell-diffuse/sketch-draw-maze.js",
    "content": "var N = 1 << 0,\n\tS = 1 << 1,\n\tW = 1 << 2,\n\tE = 1 << 3;\n\n\n\nfunction flood() {\n    var frontier1 = [],\n        i0,\n        n0 = frontier.length,\n        i1;\n    //    color = d3.hsl((distance += .5) % 360, 1, .5).rgb();\n\n\tvar i;\n\n    for (i = 0; i < n0; ++i) {\n\t\ti0 = frontier[i] << 2;\n\t\timg.data[i0 + 0] = 255;//color.r;\n\t\timg.data[i0 + 1] = 255;//color.g;\n\t\timg.data[i0 + 2] = 255;//color.b;\n\t\timg.data[i0 + 3] = 255;\n    }\n\n    for (i = 0; i < n0; ++i) {\n\t\ti0 = frontier[i];\n\t\tif (cells[i0] & E && !visited[i1 = i0 + 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & W && !visited[i1 = i0 - 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & S && !visited[i1 = i0 + width]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & N && !visited[i1 = i0 - width]) visited[i1] = true, frontier1.push(i1);\n    }\n\n    frontier = frontier1;\n    return !frontier1.length;\n}\n\n/////////////////////////////////////////////////////////////////\n\n\nfunction generateMaze( cellWidth, cellHeight ) {\n\t\n\tvar cells = new Array(cellWidth * cellHeight),\n\t\tfrontier = minHeap( function(a, b) { return a.weight - b.weight; } ),\n\t\tstartIndex = (cellHeight - 1) * cellWidth; // left bottom\n\t\n\tcells[startIndex] = 0; // empty?\n\tfrontier.push( {index: startIndex, direction: N, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: E, weight: Math.random()} );\n\t\n\t\n\twhile ( (edge = frontier.pop()) != null ) {\n\t\t\n\t\tvar edge,\n\t\t    i0 = edge.index, \t\t\t\t// i0\n\t\t    d0 = edge.direction, \t\t\t// d0\n\t\t    i1 = i0 + (d0 === N ? -cellWidth : d0 === S ? cellWidth : d0 === W ? -1 : +1), // neighbor cell position\n\t\t    x0 = i0 % cellWidth,\t\t\t// x0\n\t\t    y0 = i0 / cellWidth | 0,\t\t// y0\n\t\t    x1,\n\t\t    y1,\n\t\t    d1,\n\t\t    open = cells[i1] === undefined; // opposite not yet part of the maze\n\t\n\t\tif (d0 === N) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 - 1;\n\t\t\td1 = S;\n\t\t} else if (d0 === S) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 + 1;\n\t\t\td1 = N;\n\t\t} else if (d0 === W) {\n\t\t\tx1 = x0 - 1;\n\t\t\ty1 = y0;\n\t\t\td1 = E;\n\t\t} else {\n\t\t\tx1 = x0 + 1;\n\t\t\ty1 = y0;\n\t\t\td1 = W;\n\t\t}\n\t\t\n\t\tif (open) {\n\t\t\tcells[i0] |= d0;\n\t\t\tcells[i1] |= d1;\n\t\t\t\n\t\t\tif (y1 > 0 && cells[i1 - cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: N, weight: Math.random()});\n\t\t\t}\n\t\t\t\n\t\t\tif (y1 < cellHeight - 1 && cells[i1 + cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: S, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 > 0 && cells[i1 - 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: W, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 < cellWidth - 1 && cells[i1 + 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: E, weight: Math.random()});\n\t\t\t}\n\t\t}\n\t}\n\t\n\tconsole.log( cells );\n\t\n\treturn cells;\n\t\n}\n\nfunction minHeap(compare) {\n\t\n\tvar heap = {},\n\t\tarray = [],\n\t\tsize = 0;\n\t\t\n\theap.array = array;\n\t\n\theap.empty = function() {\n\t\treturn !size;\n\t};\n\t\n\theap.push = function(value) {\n\t\tup(array[size] = value, size++);\n    \treturn size;\n\t};\n\t\n\theap.pop = function() {\n\t\tif (size <= 0) return;\n\t\tvar removed = array[0], value;\n\t\tif (--size > 0) value = array[size], down(array[0] = value, 0);\n\t\treturn removed;\n\t};\n\t\n\tfunction up(value, i) {\n\t\t\n\t\twhile ( i > 0 ) {\n\t\t\tvar j = ((i + 1) >> 1) - 1,\n\t\t\tparent = array[j];\n\t\t\tif (compare(value, parent) >= 0) break;\n\t\t\tarray[i] = parent;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\tfunction down(value, i) {\n\t\twhile (true) {\n\t\t\tvar r = (i + 1) << 1,\n\t\t\t\tl = r - 1,\n\t\t\t\tj = i,\n\t\t    child = array[j];\n\t\t\tif (l < size && compare(array[l], child) < 0) child = array[j = l];\n\t\t\tif (r < size && compare(array[r], child) < 0) child = array[j = r];\n\t\t\tif (j === i) break;\n\t\t\tarray[i] = child;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\treturn heap;\n}\n\n/////////////////////////////////////////////////////////////////\n\nvar cells;\n\n\n\n/////////////////////////////////////////////////////////////////\n// create Maze\n\nfunction setup() {\n\t\n\tvar width = 100, height = 100;\n\t\n\tcreateCanvas( width * 2 + 1, height * 2 + 1 );\n\t\n\tbackground( 0 );\n\t\n\t\n\tvar cells = null,\n\t\tdistance = 0,\n\t\tvisited = new Array(width * height),\n\t\tfrontier = [(height - 1) * width],\n\t\timg = createImage( width, height );\n\t\n\tcells = generateMaze( width, height );\n\n\tstroke( 255 );\n\t\n\tvar cell, px, py;\n\t\n\tfor ( var y = 0; y < height; y++ ) {\n\t\tfor ( var x = 0; x < width; x++ ) {\n\t\t\n\t\t\tcell = cells[ y * width + x ];\n\t\t\tpx = 1 + x*2;\n\t\t\tpy = 1 + y*2;\n\t\t\t\n\t\t\t// cell\n\t\t\tpoint( px, py );\n\t\t\t\n\t\t\t// N\n\t\t\tif ( cell & N )\tpoint( px, py-1 );\n\t\t\tif ( cell & E )\tpoint( px+1, py );\n\t\t\tif ( cell & S )\tpoint( px, py+1 );\n\t\t\tif ( cell & W )\tpoint( px-1, py );\n\t\t\n\t\t\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "p5js/cell-diffuse/sketch.js",
    "content": "var N = 1 << 0,\n\tS = 1 << 1,\n\tW = 1 << 2,\n\tE = 1 << 3;\n\t\nvar MAP_W = 101;\n\nvar filename = \"cell-diffuse\";\n\t\nvar exportDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/prizm\";\n\nvar isSave = false;\n\nvar d = new Date();\n\nvar ox = Math.floor( MAP_W / 2 ),\n\toy = Math.floor( MAP_W / 2 );\n\t\n// var ox = 0,\n// \toy = 1;\n\nfilename += \"_\" + (\"00\"+d.getDate()).substr(-2) + \"-\" + (\"00\"+d.getHours()).substr(-2) + \"-\"\n\t+ (\"00\"+d.getMinutes()).substr(-2) + \"-\" + (\"00\"+d.getSeconds()).substr(-2);\n/////////////////////////////////////////////////////////////////\n\n\nfunction generateMaze( cellWidth, cellHeight ) {\n\t\n\tvar cells = new Array(cellWidth * cellHeight),\n\t\tfrontier = minHeap( function(a, b) { return a.weight - b.weight; } ),\n\t\tstartIndex = getIndex( width/2, height/2 ); // left bottom\n\t\n\tcells[startIndex] = 0; // empty?\n\tfrontier.push( {index: startIndex, direction: N, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: E, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: S, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: W, weight: Math.random()} );\n\t\n\t\n\twhile ( (edge = frontier.pop()) != null ) {\n\t\t\n\t\tvar edge,\n\t\t    i0 = edge.index, \t\t\t\t// i0\n\t\t    d0 = edge.direction, \t\t\t// d0\n\t\t    i1 = i0 + (d0 === N ? -cellWidth : d0 === S ? cellWidth : d0 === W ? -1 : +1), // neighbor cell position\n\t\t    x0 = i0 % cellWidth,\t\t\t// x0\n\t\t    y0 = i0 / cellWidth | 0,\t\t// y0\n\t\t    x1,\n\t\t    y1,\n\t\t    d1,\n\t\t    open = cells[i1] === undefined; // opposite not yet part of the maze\n\t\n\t\tif (d0 === N) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 - 1;\n\t\t\td1 = S;\n\t\t} else if (d0 === S) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 + 1;\n\t\t\td1 = N;\n\t\t} else if (d0 === W) {\n\t\t\tx1 = x0 - 1;\n\t\t\ty1 = y0;\n\t\t\td1 = E;\n\t\t} else {\n\t\t\tx1 = x0 + 1;\n\t\t\ty1 = y0;\n\t\t\td1 = W;\n\t\t}\n\t\t\n\t\tif (open) {\n\t\t\tcells[i0] |= d0;\n\t\t\tcells[i1] |= d1;\n\t\t\t\n\t\t\tif (y1 > 0 && cells[i1 - cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: N, weight: Math.random()});\n\t\t\t}\n\t\t\t\n\t\t\tif (y1 < cellHeight - 1 && cells[i1 + cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: S, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 > 0 && cells[i1 - 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: W, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 < cellWidth - 1 && cells[i1 + 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: E, weight: Math.random()});\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn cells;\n\t\n}\n\nfunction minHeap(compare) {\n\t\n\tvar heap = {},\n\t\tarray = [],\n\t\tsize = 0;\n\t\t\n\theap.array = array;\n\t\n\theap.empty = function() {\n\t\treturn !size;\n\t};\n\t\n\theap.push = function(value) {\n\t\tup(array[size] = value, size++);\n    \treturn size;\n\t};\n\t\n\theap.pop = function() {\n\t\tif (size <= 0) return;\n\t\tvar removed = array[0], value;\n\t\tif (--size > 0) value = array[size], down(array[0] = value, 0);\n\t\treturn removed;\n\t};\n\t\n\tfunction up(value, i) {\n\t\t\n\t\twhile ( i > 0 ) {\n\t\t\tvar j = ((i + 1) >> 1) - 1,\n\t\t\tparent = array[j];\n\t\t\tif (compare(value, parent) >= 0) break;\n\t\t\tarray[i] = parent;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\tfunction down(value, i) {\n\t\twhile (true) {\n\t\t\tvar r = (i + 1) << 1,\n\t\t\t\tl = r - 1,\n\t\t\t\tj = i,\n\t\t    child = array[j];\n\t\t\tif (l < size && compare(array[l], child) < 0) child = array[j = l];\n\t\t\tif (r < size && compare(array[r], child) < 0) child = array[j = r];\n\t\t\tif (j === i) break;\n\t\t\tarray[i] = child;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\treturn heap;\n}\n\n/////////////////////////////////////////////////////////////////\n\nvar canvas;\n\nvar cells;\n\nvar width = MAP_W,\n\theight = MAP_W;\n\nvar distance = 0,\n\tvisited = new Array( width * height ),\n\tfrontier = [ getIndex( ox, oy ) ];\n\nfunction getIndex( x, y ) {\n\treturn Math.floor(y) * width +  Math.floor(x);\n}\n\nfunction getPos( index ) {\n\treturn {\n\t\tx: index % width,\n\t\ty: Math.floor( index / width )\n\t}\n}\n\nfunction flood() {\n    var frontier1 = [],\n        i0,\n        n0 = frontier.length,\n        i1;\n\n\tvar i;\n\n\t// all frontier\n    var pos;\n    for (i = 0; i < n0; ++i) {\n    \tpos = getPos( frontier[i] );\n    \tpoint( pos.x, pos.y );\n    }\n\n    for (i = 0; i < n0; ++i) {\n\t\ti0 = frontier[i];\n\t\tif (cells[i0] & E && !visited[i1 = i0 + 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & W && !visited[i1 = i0 - 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & S && !visited[i1 = i0 + width]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & N && !visited[i1 = i0 - width]) visited[i1] = true, frontier1.push(i1);\n    }\n\n    frontier = frontier1;\n    return !frontier1.length;\n}\n\t\nfunction setup() {\n\t\n\twidth = MAP_W;\n\theight = MAP_W;\n\n\tcells = generateMaze( width, height );\n\t\n\tvar cx = Math.floor( width/2 ),\n\t\tcy = Math.floor( height/2 );\n\t\n\tcells[ getIndex( cx, cy ) ] = N | E | S | W;\n\t\n\tfor ( var i = 0; i < 4; i++ ) {\n\t\t\n\t\tcells[ getIndex( cx, cy-i ) ] |= N | S;\n\t\tcells[ getIndex( cx+i, cy ) ] |= E | W;\n\t\tcells[ getIndex( cx, cy+i ) ] |= N | S;\n\t\tcells[ getIndex( cx-i, cy ) ] |= E | W;\n\t\t\n\t\t// remove\n\t\tif ( i > 0 ) {\n\t\t\tremovePath( cx, cy-i, E );\n\t\t\tremovePath( cx, cy-i, W );\n\t\t\t\n\t\t\t// removePath( cx+i, cy, N );\n\t\t\t// removePath( cx+i, cy, S );\n\t\t\t\n\t\t\tremovePath( cx, cy+i, E );\n\t\t\tremovePath( cx, cy+i, W );\n\t\t\t\n\t\t\t// removePath( cx-i, cy, N );\n\t\t\t// removePath( cx-i, cy, S );\n\t\t}\n\t\t\n\t}\n\t\n\tfunction removePath( x, y, dir ) {\n\t\tvar other;\n\t\t\n\t\tif ( dir == N ) other = E | S | W;\n\t\telse if ( dir == E ) other = N | S | W;\n\t\telse if ( dir == S ) otehr = N | E | W;\n\t\telse if ( dir == W ) other = N | E | S; \n\t\t\n\t\tcells[ getIndex( x, y ) ] &= other;\n\t}\n\t\n\tcanvas = createCanvas( width, height );\n\tbackground( 0 );\n\t\n\twidth = MAP_W;\n\theight = MAP_W;\n\t\n\tdrawFrame();\n}\n\nvar frame = 0;\n\nfunction drawFrame() {\n\t\n\tstroke( 255, frame % 255, Math.floor( frame / 255 ) );\n\t\n\tif ( flood() ) {\n\t\treturn;\n\t}\n\t\n\tvar frameStr = ( \"000000\" + frame ).substr( -6 );\n\tvar path = exportDir + \"/\" + filename + \"/\" + filename + \"_\" + frameStr + \".png\";\n\t\n\t\n\tdata = {\n\t\timage: canvas.canvas.toDataURL(),\n\t\tpath: path\n\t};\n\t\n\tif ( isSave ) {\n\t\n\t\t$.post( \"http://localhost:8080/save-sequence.php\", data, function(data) {\n\t\t\t\n\t\t\tsetTimeout( drawFrame, 5 );\n\t\t\t\n\t\t} );\n\t\n\t} else {\n\t\n\t\tsetTimeout( drawFrame, 500 );\n\t\t\n\t}\n\t\n\tframe++;\n}"
  },
  {
    "path": "p5js/randomized-prizm/index.html",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"UTF-8\">\n    <title>Untitled</title>\n    <script src=\"http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.9/p5.js\" type=\"text/javascript\"></script>\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js\" type=\"text/javascript\"></script>\n\n    <!--<script src=\"libraries/p5.dom.js\" type=\"text/javascript\"></script>\n    <script src=\"libraries/p5.sound.js\" type=\"text/javascript\"></script>-->\n\n    <!--<script src=\"sketch-draw-maze.js\" type=\"text/javascript\"></script>-->\n    <script src=\"sketch.js\" type=\"text/javascript\"></script>\n\n    <style> body {padding: 0; margin: 0; background: white;} </style>\n  </head>\n  <body>\n  </body>\n</html>\n"
  },
  {
    "path": "p5js/randomized-prizm/save-sequence.php",
    "content": "<?\n header(\"Access-Control-Allow-Origin: *\");\n\n//canvasデータがPOSTで送信されてきた場合\n$canvas = $_POST[\"image\"];\n$path = $_POST[\"path\"];\n \n//ヘッダに「data:image/png;base64,」が付いているので、それは外す\n$canvas = preg_replace(\"/data:[^,]+,/i\",\"\",$canvas);\n \n//残りのデータはbase64エンコードされているので、デコードする\n$canvas = base64_decode($canvas);\n \n//まだ文字列の状態なので、画像リソース化\n$image = imagecreatefromstring($canvas);\n\n$dir = dirname( $path );\n\nif ( !file_exists( $dir ) ) {\n    mkdir( $dir, 0777, true);\n}\n\n \n//画像として保存（ディレクトリは任意）\n// imagesavealpha($image, false); // 透明色の有効\nimagepng($image, $path );\n\n?>"
  },
  {
    "path": "p5js/randomized-prizm/sketch-draw-maze.js",
    "content": "var N = 1 << 0,\n\tS = 1 << 1,\n\tW = 1 << 2,\n\tE = 1 << 3;\n\n\n\nfunction flood() {\n    var frontier1 = [],\n        i0,\n        n0 = frontier.length,\n        i1;\n    //    color = d3.hsl((distance += .5) % 360, 1, .5).rgb();\n\n\tvar i;\n\n    for (i = 0; i < n0; ++i) {\n\t\ti0 = frontier[i] << 2;\n\t\timg.data[i0 + 0] = 255;//color.r;\n\t\timg.data[i0 + 1] = 255;//color.g;\n\t\timg.data[i0 + 2] = 255;//color.b;\n\t\timg.data[i0 + 3] = 255;\n    }\n\n    for (i = 0; i < n0; ++i) {\n\t\ti0 = frontier[i];\n\t\tif (cells[i0] & E && !visited[i1 = i0 + 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & W && !visited[i1 = i0 - 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & S && !visited[i1 = i0 + width]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & N && !visited[i1 = i0 - width]) visited[i1] = true, frontier1.push(i1);\n    }\n\n    frontier = frontier1;\n    return !frontier1.length;\n}\n\n/////////////////////////////////////////////////////////////////\n\n\nfunction generateMaze( cellWidth, cellHeight ) {\n\t\n\tvar cells = new Array(cellWidth * cellHeight),\n\t\tfrontier = minHeap( function(a, b) { return a.weight - b.weight; } ),\n\t\tstartIndex = (cellHeight - 1) * cellWidth; // left bottom\n\t\n\tcells[startIndex] = 0; // empty?\n\tfrontier.push( {index: startIndex, direction: N, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: E, weight: Math.random()} );\n\t\n\t\n\twhile ( (edge = frontier.pop()) != null ) {\n\t\t\n\t\tvar edge,\n\t\t    i0 = edge.index, \t\t\t\t// i0\n\t\t    d0 = edge.direction, \t\t\t// d0\n\t\t    i1 = i0 + (d0 === N ? -cellWidth : d0 === S ? cellWidth : d0 === W ? -1 : +1), // neighbor cell position\n\t\t    x0 = i0 % cellWidth,\t\t\t// x0\n\t\t    y0 = i0 / cellWidth | 0,\t\t// y0\n\t\t    x1,\n\t\t    y1,\n\t\t    d1,\n\t\t    open = cells[i1] === undefined; // opposite not yet part of the maze\n\t\n\t\tif (d0 === N) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 - 1;\n\t\t\td1 = S;\n\t\t} else if (d0 === S) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 + 1;\n\t\t\td1 = N;\n\t\t} else if (d0 === W) {\n\t\t\tx1 = x0 - 1;\n\t\t\ty1 = y0;\n\t\t\td1 = E;\n\t\t} else {\n\t\t\tx1 = x0 + 1;\n\t\t\ty1 = y0;\n\t\t\td1 = W;\n\t\t}\n\t\t\n\t\tif (open) {\n\t\t\tcells[i0] |= d0;\n\t\t\tcells[i1] |= d1;\n\t\t\t\n\t\t\tif (y1 > 0 && cells[i1 - cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: N, weight: Math.random()});\n\t\t\t}\n\t\t\t\n\t\t\tif (y1 < cellHeight - 1 && cells[i1 + cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: S, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 > 0 && cells[i1 - 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: W, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 < cellWidth - 1 && cells[i1 + 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: E, weight: Math.random()});\n\t\t\t}\n\t\t}\n\t}\n\t\n\tconsole.log( cells );\n\t\n\treturn cells;\n\t\n}\n\nfunction minHeap(compare) {\n\t\n\tvar heap = {},\n\t\tarray = [],\n\t\tsize = 0;\n\t\t\n\theap.array = array;\n\t\n\theap.empty = function() {\n\t\treturn !size;\n\t};\n\t\n\theap.push = function(value) {\n\t\tup(array[size] = value, size++);\n    \treturn size;\n\t};\n\t\n\theap.pop = function() {\n\t\tif (size <= 0) return;\n\t\tvar removed = array[0], value;\n\t\tif (--size > 0) value = array[size], down(array[0] = value, 0);\n\t\treturn removed;\n\t};\n\t\n\tfunction up(value, i) {\n\t\t\n\t\twhile ( i > 0 ) {\n\t\t\tvar j = ((i + 1) >> 1) - 1,\n\t\t\tparent = array[j];\n\t\t\tif (compare(value, parent) >= 0) break;\n\t\t\tarray[i] = parent;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\tfunction down(value, i) {\n\t\twhile (true) {\n\t\t\tvar r = (i + 1) << 1,\n\t\t\t\tl = r - 1,\n\t\t\t\tj = i,\n\t\t    child = array[j];\n\t\t\tif (l < size && compare(array[l], child) < 0) child = array[j = l];\n\t\t\tif (r < size && compare(array[r], child) < 0) child = array[j = r];\n\t\t\tif (j === i) break;\n\t\t\tarray[i] = child;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\treturn heap;\n}\n\n/////////////////////////////////////////////////////////////////\n\nvar cells;\n\n\n\n/////////////////////////////////////////////////////////////////\n// create Maze\n\nfunction setup() {\n\t\n\tvar width = 100, height = 100;\n\t\n\tcreateCanvas( width * 2 + 1, height * 2 + 1 );\n\t\n\tbackground( 0 );\n\t\n\t\n\tvar cells = null,\n\t\tdistance = 0,\n\t\tvisited = new Array(width * height),\n\t\tfrontier = [(height - 1) * width],\n\t\timg = createImage( width, height );\n\t\n\tcells = generateMaze( width, height );\n\n\tstroke( 255 );\n\t\n\tvar cell, px, py;\n\t\n\tfor ( var y = 0; y < height; y++ ) {\n\t\tfor ( var x = 0; x < width; x++ ) {\n\t\t\n\t\t\tcell = cells[ y * width + x ];\n\t\t\tpx = 1 + x*2;\n\t\t\tpy = 1 + y*2;\n\t\t\t\n\t\t\t// cell\n\t\t\tpoint( px, py );\n\t\t\t\n\t\t\t// N\n\t\t\tif ( cell & N )\tpoint( px, py-1 );\n\t\t\tif ( cell & E )\tpoint( px+1, py );\n\t\t\tif ( cell & S )\tpoint( px, py+1 );\n\t\t\tif ( cell & W )\tpoint( px-1, py );\n\t\t\n\t\t\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "p5js/randomized-prizm/sketch.js",
    "content": "var N = 1 << 0,\n\tS = 1 << 1,\n\tW = 1 << 2,\n\tE = 1 << 3;\n\t\nvar MAP_W = 1281;\n\nvar filename = \"prizm-radial\";\n\t\nvar exportDir = \"/Volumes/MugiRAID1/Works/2015/13_0xff/ca/prizm\";\n\nvar isSave = false;\n\nvar d = new Date();\n\nvar ox = Math.floor( MAP_W / 2 ),\n\toy = Math.floor( MAP_W / 2 );\n\t\n// var ox = 0,\n// \toy = 1;\n\nfilename += \"_\" + (\"00\"+d.getDate()).substr(-2) + \"-\" + (\"00\"+d.getHours()).substr(-2) + \"-\"\n\t+ (\"00\"+d.getMinutes()).substr(-2) + \"-\" + (\"00\"+d.getSeconds()).substr(-2);\n/////////////////////////////////////////////////////////////////\n\n\nfunction generateMaze( cellWidth, cellHeight ) {\n\t\n\tvar cells = new Array(cellWidth * cellHeight),\n\t\tfrontier = minHeap( function(a, b) { return a.weight - b.weight; } ),\n\t\tstartIndex = getIndex( width/2, height/2 );//(cellHeight - 1) * cellWidth; // left bottom\n\t\n\tcells[startIndex] = 0; // empty?\n\tfrontier.push( {index: startIndex, direction: N, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: E, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: S, weight: Math.random()} );\n\tfrontier.push( {index: startIndex, direction: W, weight: Math.random()} );\n\t\n\t\n\twhile ( (edge = frontier.pop()) != null ) {\n\t\t\n\t\tvar edge,\n\t\t    i0 = edge.index, \t\t\t\t// i0\n\t\t    d0 = edge.direction, \t\t\t// d0\n\t\t    i1 = i0 + (d0 === N ? -cellWidth : d0 === S ? cellWidth : d0 === W ? -1 : +1), // neighbor cell position\n\t\t    x0 = i0 % cellWidth,\t\t\t// x0\n\t\t    y0 = i0 / cellWidth | 0,\t\t// y0\n\t\t    x1,\n\t\t    y1,\n\t\t    d1,\n\t\t    open = cells[i1] === undefined; // opposite not yet part of the maze\n\t\n\t\tif (d0 === N) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 - 1;\n\t\t\td1 = S;\n\t\t} else if (d0 === S) {\n\t\t\tx1 = x0;\n\t\t\ty1 = y0 + 1;\n\t\t\td1 = N;\n\t\t} else if (d0 === W) {\n\t\t\tx1 = x0 - 1;\n\t\t\ty1 = y0;\n\t\t\td1 = E;\n\t\t} else {\n\t\t\tx1 = x0 + 1;\n\t\t\ty1 = y0;\n\t\t\td1 = W;\n\t\t}\n\t\t\n\t\tif (open) {\n\t\t\tcells[i0] |= d0;\n\t\t\tcells[i1] |= d1;\n\t\t\t\n\t\t\tif (y1 > 0 && cells[i1 - cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: N, weight: Math.random()});\n\t\t\t}\n\t\t\t\n\t\t\tif (y1 < cellHeight - 1 && cells[i1 + cellWidth] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: S, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 > 0 && cells[i1 - 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: W, weight: Math.random()});\n\t\t\t}\n\t\t\tif (x1 < cellWidth - 1 && cells[i1 + 1] === undefined) {\n\t\t\t\tfrontier.push({index: i1, direction: E, weight: Math.random()});\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn cells;\n\t\n}\n\nfunction minHeap(compare) {\n\t\n\tvar heap = {},\n\t\tarray = [],\n\t\tsize = 0;\n\t\t\n\theap.array = array;\n\t\n\theap.empty = function() {\n\t\treturn !size;\n\t};\n\t\n\theap.push = function(value) {\n\t\tup(array[size] = value, size++);\n    \treturn size;\n\t};\n\t\n\theap.pop = function() {\n\t\tif (size <= 0) return;\n\t\tvar removed = array[0], value;\n\t\tif (--size > 0) value = array[size], down(array[0] = value, 0);\n\t\treturn removed;\n\t};\n\t\n\tfunction up(value, i) {\n\t\t\n\t\twhile ( i > 0 ) {\n\t\t\tvar j = ((i + 1) >> 1) - 1,\n\t\t\tparent = array[j];\n\t\t\tif (compare(value, parent) >= 0) break;\n\t\t\tarray[i] = parent;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\tfunction down(value, i) {\n\t\twhile (true) {\n\t\t\tvar r = (i + 1) << 1,\n\t\t\t\tl = r - 1,\n\t\t\t\tj = i,\n\t\t    child = array[j];\n\t\t\tif (l < size && compare(array[l], child) < 0) child = array[j = l];\n\t\t\tif (r < size && compare(array[r], child) < 0) child = array[j = r];\n\t\t\tif (j === i) break;\n\t\t\tarray[i] = child;\n\t\t\tarray[i = j] = value;\n\t\t}\n\t}\n\t\n\treturn heap;\n}\n\n/////////////////////////////////////////////////////////////////\n\nvar canvas;\n\nvar cells;\n\nvar width = MAP_W,\n\theight = MAP_W;\n\nvar distance = 0,\n\tvisited = new Array( width * height ),\n\tfrontier = [ getIndex( ox, oy ) ];\n\nfunction getIndex( x, y ) {\n\treturn Math.floor(y) * width +  Math.floor(x);\n}\n\nfunction getPos( index ) {\n\treturn {\n\t\tx: index % width,\n\t\ty: Math.floor( index / width )\n\t}\n}\n\nfunction flood() {\n    var frontier1 = [],\n        i0,\n        n0 = frontier.length,\n        i1;\n    \t//    color = d3.hsl((distance += .5) % 360, 1, .5).rgb();\n\n\tvar i;\n\n\t// all frontier\n    var pos;\n    for (i = 0; i < n0; ++i) {\n    \tpos = getPos( frontier[i] );\n    \tpoint( pos.x, pos.y );\n\t\t\n\t\t//i0 = frontier[i] << 2;\n\t\t//img.data[i0 + 0] = 255;//color.r;\n\t\t//img.data[i0 + 1] = 255;//color.g;\n\t\t//img.data[i0 + 2] = 255;//color.b;\n\t\t//img.data[i0 + 3] = 255;\n    }\n\n    for (i = 0; i < n0; ++i) {\n\t\ti0 = frontier[i];\n\t\tif (cells[i0] & E && !visited[i1 = i0 + 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & W && !visited[i1 = i0 - 1]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & S && !visited[i1 = i0 + width]) visited[i1] = true, frontier1.push(i1);\n\t\tif (cells[i0] & N && !visited[i1 = i0 - width]) visited[i1] = true, frontier1.push(i1);\n    }\n\n    frontier = frontier1;\n    return !frontier1.length;\n}\n\t\nfunction setup() {\n\t\n\twidth = MAP_W;\n\theight = MAP_W;\n\t\n\n\tcells = generateMaze( width, height );\n\t\n\t// make grid\n\t\t\n\topenNeumann();\n\topenDiagonal();\n\t\n\t// createCanvas( width * 2 + 1, height * 2 + 1 );\n\tcanvas = createCanvas( width, height );\n\tbackground( 0 );\n\t\n\twidth = MAP_W;\n\theight = MAP_W;\n\t\n\tdrawFrame();\n\t\n\t/*stroke( 255 );\n\t\n\tvar cell, px, py;\n\t\n\tfor ( var y = 0; y < height; y++ ) {\n\t\tfor ( var x = 0; x < width; x++ ) {\n\t\t\n\t\t\tcell = cells[ getIndex(x,y) ];\n\t\t\tpx = 1 + x*2;\n\t\t\tpy = 1 + y*2;\n\t\t\t\n\t\t\t// cell\n\t\t\tpoint( px, py );\n\t\t\t\n\t\t\t// N\n\t\t\tif ( cell & N )\tpoint( px, py-1 );\n\t\t\tif ( cell & E )\tpoint( px+1, py );\n\t\t\tif ( cell & S )\tpoint( px, py+1 );\n\t\t\tif ( cell & W )\tpoint( px-1, py );\n\t\t\n\t\t\n\t\t}\n\t}*/\n}\n\nfunction openNeumann() {\n\t\n\t// var ox = Math.floor( width / 2 ),\n\t// \toy = Math.floor( height / 2 ), // center\n\tvar\tx, y;\n\tvar i;\n\t\n\t// North\n\tx = ox, y = oy;\n\twhile( y >= 0 ) {\n\t\ti = getIndex(x, y);\n\t\tcells[ i ] |= N;\n\t\tcells[ i ] |= S;\n\t\ty--;\n\t}\n\t// South\n\tx = ox, y = oy;\n\twhile( y < height ) {\n\t\ti = getIndex(x, y);\n\t\tcells[ i ] |= N;\n\t\tcells[ i ] |= S;\n\t\ty++;\n\t}\n\t// West\n\tx = ox, y = oy;\n\twhile( x >= 0 ) {\n\t\ti = getIndex(x, y);\n\t\tcells[ i ] |= W;\n\t\tcells[ i ] |= E;\n\t\tx--;\n\t}\n\t// East\n\tx = ox, y = oy;\n\twhile( x < width ) {\n\t\ti = getIndex(x, y);\n\t\tcells[ i ] |= W;\n\t\tcells[ i ] |= E;\n\t\tx++;\n\t}\n}\n\nfunction openDiagonal() {\n\t\n\tconsole.log(\"Diagonal\");\n\t\n\t// var ox = Math.floor( width / 2 ),\n\t// \toy = Math.floor( height / 2 ), // center\n\tvar\tx, y;\n\tvar i;\n\t\n\t// SE\n\tx = ox, y = oy;\n\twhile( x < width ) {\n\t\t// x or y\n\t\tif ( Math.random() < .5) { // go x\n\t\t\tcells[ getIndex(x,y) ] |= E;\n\t\t\tcells[ getIndex(x+1,y) ] |= S;\n\t\t\tcells[ getIndex(x+1,y) ] |= W;\n\t\t\tcells[ getIndex(x+1,y+1) ] |= N;\t\n\t\t} else {\n\t\t\tcells[ getIndex(x,y) ] |= S;\n\t\t\tcells[ getIndex(x,y+1) ] |= N;\n\t\t\tcells[ getIndex(x,y+1) ] |= E;\n\t\t\tcells[ getIndex(x+1,y+1) ] |= W;\n\t\t}\n\t\tx++, y++;\n\t}\n\t\n\t// NW\n\tx = ox, y = oy;\n\twhile( x > 0 ) {\n\t\t// x or y\n\t\tif ( Math.random() < .5) { // go x\n\t\t\tcells[ getIndex(x,y) ] |= W;\n\t\t\tcells[ getIndex(x-1,y) ] |= N;\n\t\t\tcells[ getIndex(x-1,y) ] |= E;\n\t\t\tcells[ getIndex(x-1,y-1) ] |= S;\t\n\t\t} else {\n\t\t\tcells[ getIndex(x,y) ] |= N;\n\t\t\tcells[ getIndex(x,y-1) ] |= S;\n\t\t\tcells[ getIndex(x,y-1) ] |= W;\n\t\t\tcells[ getIndex(x-1,y-1) ] |= E;\n\t\t}\n\t\tx--, y--;\n\t}\n\t\n\t// NE\n\tx = ox, y = oy;\n\twhile( x < width ) {\n\t\t// x or y\n\t\tif ( Math.random() < .5) { // go x\n\t\t\tcells[ getIndex(x,y) ] |= E;\n\t\t\tcells[ getIndex(x+1,y) ] |= N;\n\t\t\tcells[ getIndex(x+1,y) ] |= W;\n\t\t\tcells[ getIndex(x+1,y-1) ] |= S;\t\n\t\t} else {\n\t\t\tcells[ getIndex(x,y) ] |= N;\n\t\t\tcells[ getIndex(x,y-1) ] |= S;\n\t\t\tcells[ getIndex(x,y-1) ] |= E;\n\t\t\tcells[ getIndex(x+1,y-1) ] |= W;\n\t\t}\n\t\tx++, y--;\n\t}\n\t\n\t// SW\n\tx = ox, y = oy;\n\twhile( x > 0 ) {\n\t\t// x or y\n\t\tif ( Math.random() < .5) { // go x\n\t\t\tcells[ getIndex(x,y) ] |= W;\n\t\t\tcells[ getIndex(x-1,y) ] |= S;\n\t\t\tcells[ getIndex(x-1,y) ] |= E;\n\t\t\tcells[ getIndex(x-1,y+1) ] |= N;\t\n\t\t} else {\n\t\t\tcells[ getIndex(x,y) ] |= S;\n\t\t\tcells[ getIndex(x,y+1) ] |= N;\n\t\t\tcells[ getIndex(x,y+1) ] |= W;\n\t\t\tcells[ getIndex(x-1,y+1) ] |= E;\n\t\t}\n\t\tx--, y++;\n\t}\n\t\n\n\n}\n\nvar frame = 0;\n\nfunction drawFrame() {\n\t\n\tstroke( 255, frame % 255, Math.floor( frame / 255 ) );\n\t\n\tif ( flood() ) {\n\t\treturn;\n\t}\n\t\n\tvar frameStr = ( \"000000\" + frame ).substr( -6 );\n\tvar path = exportDir + \"/\" + filename + \"/\" + filename + \"_\" + frameStr + \".png\";\n\t\n\tdata = {\n\t\timage: canvas.canvas.toDataURL(),\n\t\tpath: path\n\t};\n\t\n\tif ( isSave ) {\n\t\n\t\t$.post( \"http://localhost:8080/save-sequence.php\", data, function(data) {\n\t\t\t\n\t\t\tsetTimeout( drawFrame, 5 );\n\t\t\t\n\t\t} );\n\t\n\t} else {\n\t\n\t\tsetTimeout( drawFrame, 5 );\n\t\t\n\t}\n\t\n\tframe++;\n}\n\n/*\nvar r = 0;\n\n\nfunction draw() {\n\n\tr = (r+1) % 255;\n\t\n\tstroke( r, 255, 0 );\n\n\tflood();\n}*/"
  },
  {
    "path": "readme.md",
    "content": "# \"Subete ga F ni naru : The Perfect Insider\" Ending\n\n![](http://baku89.com/wp-content/uploads/2015/10/0xffff_ed_0013-1280x720.jpg)\n\n## About\n\nThe tools for making \"[Subete ga F ni naru(すべてがFになる)](http://f-noitamina.com)\", 2015 fall anime. Its story contains computer science so I adopted \"generative art\" approach and used p5 and Golly for simulating many kind of cellular automata.\n\nA detailed making-of articles are here: [Making of The perfect insider](https://baku89.com/making-of/ffff)\n\nNOTE: These sources are pretty tangled and it probably will not work properly on your environment.\n\n## License\n\nThis repository is published under a MIT License. See the included LICENSE file.\n"
  }
]