{"id":510,"date":"2012-11-12T15:09:20","date_gmt":"2012-11-12T15:09:20","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/?p=510"},"modified":"2012-11-12T15:09:20","modified_gmt":"2012-11-12T15:09:20","slug":"naturemachine-project-1-2","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/12\/naturemachine-project-1-2\/","title":{"rendered":"Nature\/Machine Project 1"},"content":{"rendered":"<p>In my first project for this assignment, I had originally wanted to go with an animation based on rain, but I moved on from that partway through.<br \/>\nI ended up doing snow instead, adapting most of my code.<br \/>\n<script type=\"application\/processing\">\r\nstatic int arrMax = 200;\r\nFlake[] flakes = new Flake[arrMax];\r\nint index = 0;\r\nint trueDex = 0;\r\nint i;\r\n\r\nvoid setup(){\r\n  frameRate(15);\r\n  size(300,500);\r\n  smooth();\r\n  flakes[index] = new Flake();\r\n  index = 1;\r\n}\r\n\r\nvoid draw(){\r\n  background(70,90,150);\r\n  fill(70,70,70);\r\n  rect(-3,height-25,width+4,30);\r\n  if(frameCount%5==0){\r\n    flakes[index] = new Flake();\r\n    index = (index+1)%arrMax;\r\n    if(trueDex<arrMax-1)\r\n      trueDex++;\r\n  }\r\n  for(i=0;i<trueDex;i++){\r\n    flakes[i].drawFlake();\r\n    flakes[i].moveFlake();\r\n  }\r\n}\r\n\r\nclass Flake{\r\n  float x, y, xmoveAmount, ymoveAmount, seed;\r\n  int imageIndex = 0;\r\n  int imageSize;\r\n  color myColor;\r\n  PImage[] images = new PImage[4];\r\n\r\n  Flake(){\r\n    x = 2 + random(width-10);\r\n    y = -20;\r\n    xmoveAmount = 0;\r\n    imageIndex = int(random(4));\r\n    imageSize = 10 + int(random(12));\r\n    if(imageSize>=17)\r\n      ymoveAmount = 3;\r\n    else\r\n      ymoveAmount = 4;\r\n    for(int i = 0; i < 4; i++){\r\n      images[i] = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/flake\"+(i+1)+\".png\");\r\n    }\r\n    seed = random(4);\r\n  }\r\n\r\n  void drawFlake(){\r\n    image(images[imageIndex], x, y, imageSize, imageSize);\r\n  }\r\n\r\n  void moveFlake(){\r\n    x+=xmoveAmount;\r\n    y+=ymoveAmount;\r\n    xmoveAmount = sin(seed)*3;\r\n    if(y>=height-23){\r\n      xmoveAmount = 0;\r\n      ymoveAmount = 0;\r\n    }\r\n    seed+=.1;\r\n  }\r\n}\r\n<\/script><br \/>\nThe program now spawns snowflake objects that fall from the top of the screen to stick at the bottom.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my first project for this assignment, I had originally wanted to go with an animation based on rain, but I moved on from that partway through. I ended up doing snow instead, adapting most of my code. The program &hellip; <a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/12\/naturemachine-project-1-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":9,"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\/510"}],"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\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/comments?post=510"}],"version-history":[{"count":3,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/510\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/510\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}