{"id":392,"date":"2012-11-11T05:41:13","date_gmt":"2012-11-11T05:41:13","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/?p=392"},"modified":"2012-11-11T05:41:13","modified_gmt":"2012-11-11T05:41:13","slug":"project-1-snowflake","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/11\/project-1-snowflake\/","title":{"rendered":"Project 1 &#8211; Snowflake"},"content":{"rendered":"<p>In general, for the first project &#8220;Nature vs. Machine&#8221; I took a very literal approach to creating the forces of nature in each of my three sketches. The first one, titled snowflake, is sketch that features a snowy day with uniquely behaving snowflakes. Each snow flake was created by a separate sketch that is modified from one of the spiral examples shown in class. The images created are then loaded into the main sketch which features falling snowflakes on a snowy background. When the snowflakes fall, they check collisions with all of the other snowflakes around them. If two flakes collide, one of them will be deleted and the remaining snowflake will absorb the size of the disappearing snowflake. The remaining snowflake also changes hue, until it reaches the bottom of the screen. As the sketch is played, the flakes become larger and larger due to the settings of the sketch. The viewer will notice that eventually the screen will be covered in large snowflakes that simulate a growing snow storm. Although for some strange reason the version, when posted on the website, does not change the colors of the snowflakes.<\/p>\n<p><script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\nSprite mySprite;\r\nSprite[] sprites = new Sprite[25]; \/\/create new object array, initialize with 100 slots in the array\r\nPImage snowflake;\r\n\/\/http:\/\/www.whitegadget.com\/attachments\/pc-wallpapers\/85679d1320642037-snow-snow-photos.jpg\r\nPImage backgroundImg;  \r\n\r\nvoid setup() {\r\n  size(1024, 768);\r\n  backgroundImg = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/snow_background.jpg\");\r\n  snowflake = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/snowflake.png\"); \/\/load this image file (must be in same directory as sketch)\r\n  \/\/when sketch is online, put a URL for the image, which must be on same server as sketch)\r\n  \/\/imageMode(CENTER);\r\n\r\n  for (int i=0;i<sprites.length;i++) { \/\/for loop to initialize all the objects\r\n    sprites[i]=new Sprite();\r\n  }\r\n}\r\n\r\nvoid draw() {\r\n  noTint();\r\n  image(backgroundImg, 0, 0, 1024, 768);\r\n  for (int z=0;z<sprites.length;z++) { \/\/for loop to step through each object in the array and move\/draw it\r\n    sprites[z].moveSprite();\r\n    sprites[z].drawSprite();\r\n    for (int j = 0; j < sprites.length; j++) {\r\n      if (checkIfColliding(sprites[z], sprites[j])&& z!=j) {\r\n        sprites[z].resetSprite();\r\n        sprites[j].imageSize = sprites[j].imageSize * 1.05;\r\n        sprites[j].tinted = true;\r\n        sprites[j].myColor = color(random(75)+50, random(100)+50, random(255), 200 + random(55));\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nboolean inBetween(float check, float minVal, float maxVal)\r\n{ \r\n  return (check >= minVal) && (check <= maxVal);\r\n}\r\n\r\nboolean checkIfColliding(Sprite X, Sprite Y)\r\n{\r\n  boolean xCheck = inBetween(X.x, Y.x, Y.x + Y.imageSize\/2) ||\r\n    inBetween(Y.x, X.x, X.x + X.imageSize\/2);\r\n\r\n  boolean yCheck = inBetween(X.y, Y.y, Y.y + Y.imageSize\/2) ||\r\n    inBetween(Y.y, X.y, X.y + Y.imageSize\/2);\r\n\r\n  if (xCheck && yCheck) {\r\n    return true;\r\n  }\r\n  else {\r\n    return false;\r\n  }\r\n}\r\n\r\nclass Sprite {\r\n  float x;\r\n  float y;\r\n  float imageSize;\r\n  float xmoveAmount;\r\n  float ymoveAmount;\r\n  color myColor;\r\n  boolean tinted; \r\n\r\n  Sprite() {\r\n    x = random(width); \r\n    y = random(1024);\r\n    xmoveAmount = random(-2, 2); \r\n    ymoveAmount = random(3) + 1;\r\n    imageSize = 10 + random(40);\r\n    myColor = color(random(75)+50, random(100)+50, random(255), 200 + random(55));\r\n    tinted = false;\r\n  }\r\n\r\n  void drawSprite() {\r\n    if(tinted){\r\n     tint(myColor);\r\n     image(snowflake, x, y, imageSize, imageSize); \r\n    }else{\r\n      noTint();\r\n       image(snowflake, x, y, imageSize, imageSize); \r\n    }\r\n   \r\n  }\r\n\r\n  void moveSprite() {\r\n    x+=xmoveAmount; \r\n    y+=ymoveAmount;\r\n\r\n    if (y>height + 20) {\r\n      resetSprite();\r\n    }\r\n  }\r\n\r\n  void resetSprite() {\r\n    y = 0;\r\n    x = random(width);\r\n    tinted = false;\r\n    if(imageSize  > 100){\r\n      imageSize = 100;\r\n    }\r\n  }\r\n}\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In general, for the first project &#8220;Nature vs. Machine&#8221; I took a very literal approach to creating the forces of nature in each of my three sketches. The first one, titled snowflake, is sketch that features a snowy day with &hellip; <a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/11\/project-1-snowflake\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"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\/392"}],"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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":7,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/392\/revisions\/401"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}