{"id":364,"date":"2012-11-07T19:25:20","date_gmt":"2012-11-07T19:25:20","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/?p=364"},"modified":"2012-11-11T21:44:01","modified_gmt":"2012-11-11T21:44:01","slug":"nature-sketches-iterations","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/07\/nature-sketches-iterations\/","title":{"rendered":"&#8220;Nature&#8221; Sketches &#038; Iterations"},"content":{"rendered":"<p>I&#8217;ve been working on the &#8220;Nature vs Machine&#8221; project due next week, and one of the natural phenomenons I really love are fireflies, or lightning bugs, and the effects of photographing them with low shutter speeds. It can be very beautiful! So, for one of the sketches, I knew I wanted to play with the idea of fireflies and light &#8220;paths&#8221; left by their movement.<\/p>\n<p>I&#8217;ll be updating this post with the iterations I make. Because of the way I&#8217;ve set up the &#8220;jar&#8221; these fireflies are in, I want to make sure it looks correct when posted on the blog!<\/p>\n<p>&nbsp;<\/p>\n<p><script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\n\r\n\/\/initializing\r\nint aSize = 30;\r\nfloat movem = 5;\r\nint centerX = width\/2;\r\nint centerY = height\/2;\r\n\r\n\/\/array setup\r\nFirefly myFirefly;\r\nFirefly[] Fireflys = new Firefly[aSize];\r\n\r\n\/\/main setup \r\nvoid setup() {\r\n  size(400, 600);\r\n  background(15,15,15);\r\n frameRate(24);\r\n  smooth();\r\n\r\n\/\/for loop obj init\r\n  for (int i=0;i<Fireflys.length;i++) { \r\n    Fireflys[i]=new Firefly();\r\n  }\r\n}\r\n\r\n\/\/main\r\nvoid draw() {\r\n  for (int z=0;z<Fireflys.length;z++) { \r\n    Fireflys[z].moveFirefly();\r\n    Fireflys[z].drawFirefly();\r\n  }\r\n  \/\/background fill with alpha\r\n  fill(0,8);\r\n  rect(0,0,width,height);\r\n\r\n}\r\n\r\n\/\/Fireflies\r\nclass Firefly {\r\n  float x;\r\n  float y;\r\n  float xmoveAmount;\r\n  float ymoveAmount;\r\n  color fireColor; \r\n\r\n  Firefly() {\r\n    fireColor = color(240,255,95,random(20,200));\r\n    x = random(width); \r\n    y = random(height);\r\n\r\n    \/\/xmoveAmount = 1 - random(-5,5); \r\n    \/\/ymoveAmount = 1 - random(-5,5);\r\n  }\r\n\r\n  void drawFirefly() {\r\n    strokeWeight(0);\r\n    stroke(fireColor);\r\n    fill(fireColor);\r\n    ellipse(x+random(-5,5),y+random(-5,5),3,3);\r\n\r\n    \/\/jar\r\n    strokeWeight(2);\r\n    stroke(255);\r\n    noFill();\r\n    rect(0,0,width,height);\r\n  }\r\n\r\n  void moveFirefly() {\r\n    x += random((-2-movem), (2+movem));\r\n    y += random((-2-movem), (2+movem));\r\n    x = constrain (x,0,width);\r\n    y = constrain (y,0,height);\r\n  }\r\n}\r\n<\/script><\/p>\n<p>In the first iteration, the fireflies are more scattered when the ellipses are drawn (due to use of the random fuction) so they look more sparkly. In the second iteration, I played with the variables and lowered them so that the paths left by the fireflies are more linear, but still randomized. I also added noise to their movements to make them more realistic.<\/p>\n<p><script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\n\/\/initializing\r\nint aSize = 2;\r\nfloat movem = 5;\r\nint centerX = width\/2;\r\nint centerY = height\/2;\r\n\r\n\/\/array setup\r\nFirefly myFirefly;\r\nFirefly[] Fireflys = new Firefly[aSize];\r\n\r\n\/\/main setup \r\nvoid setup() {\r\n  size(400, 600);\r\n  background(15);\r\n  frameRate(24);\r\n  smooth();\r\n  addFire();\r\n\r\n\/\/for loop obj init\r\n  for (int i=0;i<Fireflys.length;i++) { \r\n    Fireflys[i]=new Firefly();\r\n  }\r\n}\r\n\r\n\/\/main\r\nvoid draw() {\r\n  for (int z=0;z<Fireflys.length;z++) { \r\n    Fireflys[z].moveFirefly();\r\n    Fireflys[z].drawFirefly();\r\n    Firefly thisFire = Fireflys[z];\r\n  }\r\n  \/\/background fill with alpha\r\n  fill(0,5);\r\n  rect(0,0,width,height);\r\n\r\n   if (keyPressed == true && key == 's'){\r\n    save (\"fireflies.jpg\");\r\n    print (\"saved\");\r\n  }\r\n}\r\n\r\nvoid mouseReleased(){\r\n  addFire();\r\n}\r\n\r\nvoid addFire(){\r\n  for (int i=0;i<aSize;i++){\r\n    Firefly thisFire = new Firefly();\r\n    thisFire.drawFirefly();\r\n    Fireflys = (Firefly[])append(Fireflys,thisFire);\r\n  }\r\n}\r\n\r\n\/\/Fireflies\r\nclass Firefly {\r\n  float x;\r\n  float y;\r\n  float xmoveAmount;\r\n  float ymoveAmount;\r\n  color fireColor; \r\n  color fireAura;\r\n\r\n  float a;\r\n  float b;\r\n\r\n  Firefly() {\r\n    x = random(width); \r\n    y = random(height);\r\n\r\n    a = noise(x);\r\n    b = noise(y);\r\n\r\n    fireColor = color(217,255,50,a+b+random(100,150));\r\n    fireAura = color(217,255,50,100);\r\n    \/\/xmoveAmount = 1 - random(-5,5); \r\n    \/\/ymoveAmount = 1 - random(-5,5);\r\n  }\r\n\r\n  void drawFirefly() {\r\n    noStroke();\r\n    stroke(fireColor);\r\n    fill(fireColor);\r\n    ellipse(x+random(-2,2),y+random(-2,2),3,3);\r\n    fill(fireAura);\r\n    ellipse(x+random(-2,2),y+random(-2,2),9,9);\r\n\r\n    \/\/jar\r\n    strokeWeight(2);\r\n    stroke(255);\r\n    noFill();\r\n    rect(0,0,width,height);\r\n  }\r\n\r\n  void moveFirefly() {\r\n    x += random((-2-movem), (2+movem));\r\n    y += random((-2-movem), (2+movem));\r\n    x = constrain (x,0,width);\r\n    y = constrain (y,0,height);\r\n  }\r\n}\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working on the &#8220;Nature vs Machine&#8221; project due next week, and one of the natural phenomenons I really love are fireflies, or lightning bugs, and the effects of photographing them with low shutter speeds. It can be very &hellip; <a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/07\/nature-sketches-iterations\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/364"}],"collection":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/comments?post=364"}],"version-history":[{"count":10,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/364\/revisions\/441"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/media?parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/categories?post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/tags?post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}