{"componentChunkName":"component---src-templates-blog-post-js","path":"/sketches/day056","result":{"data":{"site":{"id":"Site","siteMetadata":{"title":"Creative code daily"}},"src":{"id":"3edd8cd9-2003-555a-9296-da164aaad1f4","publicURL":"/static/day056-91e1d99d38aacfd4b3b37e94b4c14329.pde","childRawCode":{"id":"3edd8cd9-2003-555a-9296-da164aaad1f4 >>> RawCode","content":"/**\n Name: day 56 == than perfect\n */\n\nimport com.hamoid.*;\n\nboolean isReadyForExport = true;\n\nVideoExport export;\n\nfloat maxFrameNumber = 300; // The number of frame to record\n\nvoid setup() {\n  size(1000, 1000, P2D);\n  smooth(8);\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\n// Taken from https://gist.github.com/gre/1650294\nfloat easeOutQuint(float t) {\n  return t<.5 ? 16*pow(t, 5) : 1 + 16 * pow(t-1, 5);\n}\n\n// Constants\ncolor bg = #08d9d6;\ncolor fg = #252a34;\n\nfloat steps = 6;\nint framesPerStep = floor(maxFrameNumber / steps);\n\n// Variables of the scene\nfloat rotation = 0;\nfloat barWidth = 10;\ncolor circleColor = bg;\nPVector circlePosition = new PVector(0, 0);\nfloat radius = 190;\nfloat barLength = 0;\n\nvoid reset() {\n  noStroke();\n  background(bg);\n}\n\nvoid animation() {\n  // current step or \"scene\". Each does a different animation.\n  int step = frameCount / framesPerStep;\n  // current frame in the step, so that we can keep track\n  float frameInCurrentStep = frameCount % framesPerStep;\n  // the current frame normalized [0, framePerStep] => [0, 1]. Makes it easy to apply easings\n  float n = frameInCurrentStep / framesPerStep;\n  // time as easing(n)\n  float t = easeOutQuint(n);\n\n  // Scenes definitions\n  if (step == 0) {\n    rotation = t * PI * 0.75;\n  }\n  if (step == 1) {\n    barWidth = 10 + t * 300;\n  }\n  if (step == 2) {\n    rotation = PI * 0.75 - t * 0.25 * PI;\n  }\n  if (step == 3) {\n    circleColor = fg;\n    circlePosition.set(\n      lerp(-2 * width, 0, t), \n      0\n      );\n  }\n  if (step == 4) {\n    barWidth = 310 + sin(t * PI * 1.5) * 700;\n  }\n  if (step == 5) {\n    circleColor = bg;\n    rotation = 0;\n    barWidth = 0;\n    radius = 190 * t;\n    barLength = 2 * width * max(0, (t - 0.3) / 0.7);\n  }\n\n  float halfBar = barWidth * 0.5;\n\n  // Rendering\n  // Interestingly, everything is already in place from the start\n  // We just update all the parameters with the scene definitions above\n\n  // The center of the screen is (0, 0)\n  translate(width * 0.5, height * 0.5);\n\n  fill(fg);\n\n  rotate(rotation);\n\n  rectMode(CORNER);\n  rect(-width, -halfBar, 2* width, -2 * height);\n  rect(-width, halfBar, 2 * width, 2 * height);\n\n  fill(circleColor);\n  circle(circlePosition.x, circlePosition.y, radius);\n\n  rectMode(CENTER);\n  rect(0, 0, barLength, 10);\n}\n\nvoid draw() {\n  reset();\n  animation();\n\n  if (isReadyForExport) {\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":"5d2545d7-4d23-5991-b276-5dfd9b8c44e1","publicURL":"/static/out-b39f643d185c528ec65968e28d3d774a.mp4"},"screenshot":{"id":"56609064-e97d-5144-98da-5bedb1553d24","publicURL":"/static/screenshot-2-66d91cfad0672482a0011b1c9b80627a.png"}},"pageContext":{"nameRegex":"/day056/","name":"day056"}}}