{"componentChunkName":"component---src-templates-blog-post-js","path":"/sketches/day040","result":{"data":{"site":{"id":"Site","siteMetadata":{"title":"Creative code daily"}},"src":{"id":"3c897201-8cd6-58b1-80b4-298ad5096d53","publicURL":"/static/day040-ffb69cc95c84fb7a28909db1bead689b.pde","childRawCode":{"id":"3c897201-8cd6-58b1-80b4-298ad5096d53 >>> RawCode","content":"/**\n Name: Day 40 << reborn\n */\n\nimport com.hamoid.*;\n\nboolean isReadyForExport = true;\n\nVideoExport export;\n\nint maxFrameNumber = 320; // The number of frame to record\n\nvoid setup() {\n  size(500, 500, P2D);\n  smooth(0);\n  pixelDensity(displayDensity()); // HiDPI, comment if too slow\n\n  if (isReadyForExport) {\n    export = new VideoExport(this, \"out.mp4\");\n    export.setFrameRate(60);\n    export.startMovie();\n  }\n  \n  rectMode(CENTER);\n}\n\nvoid reset() {\n  noStroke();\n  background(0);\n}\n\nint W = 500;\nint H = 500;\nfloat[][] getGrid(PVector[] centers) {\n  float[][] grid = new float[W][H];\n  for (int i = 0; i < W; i++) {\n    for (int j = 0; j < H; j++) {\n      grid[i][j] = 0;\n      for (PVector center : centers) {\n        grid[i][j] += 1 / (1 + dist(center.x, center.y, i, j));\n      }\n    }\n  }\n  return grid;\n}\n\n\ncolor[] purpleDark = {\n  #400082, \n  #7e0cf5, \n  #cd4dcc, \n  #f7beff\n};\n\ncolor[] fire = {\n  #9d0b0b, \n  #da2d2d, \n  #eb8242, \n  #f6da63\n};\n\ncolor[] blues = {\n  #142850,\n  #27496d,\n  #0c7b93,\n  #00a8cc,\n};\n\ncolor[] colors = blues;\n\nfloat scale = 0.2;\nvoid drawGrid(float[][] grid, float n) {\n  float wSize = width / float(W);\n  float hSize = height / float(H);\n  float t = pow(n, 10);\n\n  for (int i = 0; i < W; i++) {\n    for (int j = 0; j < H; j++) {\n      float v = grid[i][j];\n      color fill = colors[0];\n      \n      if(v >= (0.1 * scale) && v < (0.13 * scale)) fill = colors[0];\n      if(v >= (0.13 * scale) && v < (0.2 * scale)) fill = colors[1];\n      if(v >= (0.2 * scale) && v < (0.3 * scale)) fill = colors[2];\n      if(v >= (0.3 * scale)) fill = colors[3];\n      \n      if(t > 0.6) fill = lerpColor(fill, #ffffff, t);\n\n      fill(fill);\n      rect(\n        i * wSize + wSize * 0.5,\n        j * hSize + hSize * 0.5,\n        wSize,\n        hSize\n      );\n    }\n  }\n}\n\nfloat speed = 3.0;\nvoid animation() {\n  float n = (frameCount % 160.0) / 160.0;\n  float radius = .30 * (1 - pow(n, 5));\n  float direction = ((frameCount / 160) % 2) * 2 - 1;\n  float s = pow(n, 2) * 1080 * direction;\n  \n  PVector[] centers = new PVector[3];\n  for(int i = 0; i < centers.length; i++) {\n    centers[i] = new PVector(\n      W * .5 + W * radius * cos(radians(s + 120 * i)),\n      H * .5 + W * radius * sin(radians(s + 120 * i))\n    );\n  }\n  \n  float[][] grid = getGrid(centers);\n  drawGrid(grid, n);\n}\n\nvoid draw() {\n  reset();\n  animation();\n\n  if (isReadyForExport && frameCount > 1) {\n    export.saveFrame();\n    if (frameCount == 1) saveFrame(\"screenshot-1.png\");\n    if (frameCount == Math.floor(maxFrameNumber / 3)) saveFrame(\"screenshot-2.png\");\n    if (frameCount == 2 * Math.floor(maxFrameNumber / 3)) saveFrame(\"screenshot-3.png\");\n  }\n\n  if (frameCount >= maxFrameNumber) {\n    if (isReadyForExport) {\n      export.endMovie();\n    }\n    exit();\n  }\n}\n"}},"video":{"id":"3441e319-fe83-5c30-9802-9c8a2d645543","publicURL":"/static/out-3fa7c65ea5e5775bc22965cdf0a889c2.mp4"},"screenshot":{"id":"f1c835ae-743a-5562-a8f2-afb4d1f1c5d3","publicURL":"/static/screenshot-2-7f846e9552241bfc02f9fa6a96b6ba04.png"}},"pageContext":{"nameRegex":"/day040/","name":"day040"}}}