{"id":47,"date":"2019-01-20T23:30:31","date_gmt":"2019-01-20T23:30:31","guid":{"rendered":"https:\/\/ryan.hattie.codes\/?p=47"},"modified":"2021-12-06T05:10:40","modified_gmt":"2021-12-06T05:10:40","slug":"writing-the-header-animation-in-under-30-lines-of-code","status":"publish","type":"post","link":"https:\/\/raelynn.hattie.codes\/blog\/2019\/01\/20\/writing-the-header-animation-in-under-30-lines-of-code\/","title":{"rendered":"Writing the Header Animation in Under 30 Lines of Code"},"content":{"rendered":"\n<p>In case you were wondering what the header animation is, it&#8217;s a quick 24-line (excluding blank lines and closing braces) Processing sketch. Here it is, in all its slapped-together-in-a-few-minutes glory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int barCount = 64;\nint barGap = 8;\n\nboolean output = true; \/\/When enabled, the sketch will output the animation as PNG images and exit\n\nint maxFrameCount = 240; \/\/How many frames it takes to perform the animation\n\nvoid setup(){\n  size(1920, 360);\n  frameRate(30);\n}\n\nvoid drawBars(){\n  noStroke();\n  fill(#17becf);\n  for(int i = 0; i &lt;= barCount; i++){\n    float barTheta = \n      ( TAU*((float)i\/barCount) ) + \/\/base angle based on position on graph (for the shape of the waveform)\n      ( TAU*(float)(frameCount%maxFrameCount)\/maxFrameCount \/\/additional angle for animation\n    );\n      \n    int barHeight = round((sin(barTheta)*(height\/4)) + (height \/ 2));\n    int barSpacing = width\/barCount;\n    int barWidth = barSpacing - barGap;\n    rect(barSpacing*i, barHeight, barWidth, height);\n  }\n}\n\nvoid draw(){\n  background(0);\n  \/\/drawTriGrid();\n  drawBars();\n  if(output){\n    if(frameCount == maxFrameCount){exit();}\n    saveFrame(\"frames\/\"+frameCount+\".png\");\n  }\n}<\/code><\/pre>\n\n\n\n<p>To convert the output frames to an MP4 video for use on WordPress, I imported it as an image sequence in Blender&#8217;s NLE and exported in H.264.<\/p>\n\n\n\n<p>Feel free to use this sketch for all your sine wave animation needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case you were wondering what the header animation is, it&#8217;s a quick 24-line (excluding blank lines and closing braces) Processing sketch. Here it is, in all its slapped-together-in-a-few-minutes glory: To convert the output frames to an MP4 video for use on WordPress, I imported it as an image sequence in Blender&#8217;s NLE and exported<\/p>\n<div class=\"blog-grid-button\"><a class href=\"https:\/\/raelynn.hattie.codes\/blog\/2019\/01\/20\/writing-the-header-animation-in-under-30-lines-of-code\/\">Read More <i class=\"fa fa-arrow-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":42,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,11],"tags":[16,15,14,12,13],"class_list":["post-47","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","category-meta","tag-animation","tag-java","tag-p3","tag-processing","tag-processing-org"],"_links":{"self":[{"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/posts\/47"}],"collection":[{"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":2,"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":49,"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/posts\/47\/revisions\/49"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/media\/42"}],"wp:attachment":[{"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raelynn.hattie.codes\/blog\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}