{"id":409,"date":"2011-12-15T01:00:34","date_gmt":"2011-12-15T09:00:34","guid":{"rendered":"http:\/\/new.joyofprocessing.com\/blog\/?p=409"},"modified":"2011-12-12T17:18:43","modified_gmt":"2011-12-13T01:18:43","slug":"buffered-starburst","status":"publish","type":"post","link":"https:\/\/joyofprocessing.com\/blog\/2011\/12\/buffered-starburst\/","title":{"rendered":"Buffered Starburst"},"content":{"rendered":"<p><script type=\"application\/processing\">float cx,cy;\nint[] screenBuf;\nPImage[] frames;\n\nint cycleLength = 48;\n\nvoid setup()\n{\n  size(500,500);\n  loadPixels();\n\n  cx = width\/2;\n  cy = height\/2;\n  frames = new PImage[cycleLength];\n  frameRate(24);\n}\n\nvoid draw() \n{\n  if (frameCount <= cycleLength) {\n    \/\/ Do slow computation, and save frame\n    float t = frameCount*TWO_PI\/cycleLength;\n    int n = 0;\n    for (int y = 0; y < height; ++y) {\n      for (int x = 0; x < width; ++x) {\n        float d = log(dist(x,y,cx,cy));\n        float a = atan2(y-cy, x-cx);\n        float r = sin(d*8+a) * sin(a*3);\n        float g = sin(d*8+a-HALF_PI-t ) * sin(a*5);\n        float b = sin(d*8+a+HALF_PI+t ) * sin(a*7);\n        r = r*128+128;\n        g = g*128+128;\n        b = b*128+128;\n  \n        pixels[n] = color(r,g,b);\n        n++;\n      }\n    }\n    updatePixels();\n    frames[frameCount % cycleLength] = get();\n  }\n  else {\n    \/\/ Play back saved frame\n    image(frames[frameCount % cycleLength],0,0);\n  }  \n}\n\n\n\n<\/script><\/p>\n<div class=\"ps_cap\"><a href=\"\/showexample.php?ex=starburst\">source<\/a><\/div>\n<p>The code to produce this image in Processing.js is quite CPU intensive. In this sketch, I create an array of 48 images, and for the first 48 frames of the animation, I use the labor-intensive method to generate it.  Subsequenty, I play the saved frames back, and the sketch speeds up quite a bit.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>source The code to produce this image in Processing.js is quite CPU intensive. In this sketch, I create an array of 48 images, and for the first 48 frames of the animation, I use the labor-intensive method to generate it. Subsequenty, I play the saved frames back, and the sketch speeds up quite a bit.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[21,11,10,15],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-advanced","tag-animation","tag-spirals","tag-symmetry"],"_links":{"self":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/comments?post=409"}],"version-history":[{"count":6,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/tags?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}