{"id":336,"date":"2012-11-06T07:16:41","date_gmt":"2012-11-06T07:16:41","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/?p=336"},"modified":"2012-11-06T07:26:44","modified_gmt":"2012-11-06T07:26:44","slug":"mover-edit-time-bugs","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/06\/mover-edit-time-bugs\/","title":{"rendered":"Mover Edit &#8211; Time bugs"},"content":{"rendered":"<p>In this variation of the mover script whether the background resets or not  is determined by a set of rules I  gave the program. There is some randomness involved as you can tell but I tried to have it maintain a reasonable amount of time in each state in general. The bugs also get larger every time they hit a wall until they reach a max height and go back to their start height. The min height, max height, and change in height of each bug is random. Also every time they hit the edge the bug changes colors. Later in the animation the number of large bugs on screen is much greater than earlier on, and the stages where the background does not reset almost looks like an aurora against a dark sky.  It also kind of looks like it is switching between night and day but the duration of night and day is not consistent. This along with the facts that it&#8217;s sometimes tracking their movement over times, and that the bugs tend to grow over time, is why I titled it Time bugs. I just thought this looked cool. This is not for any assignment in particular. It starts out less interesting but give it time and see how it changes after the start.<\/p>\n<p><script type=\"application\/processing\">\r\nPImage myPicture;\r\nSprite [] sprites = new Sprite[100];\r\nint inChange = 0;\r\n\r\nvoid setup() {\r\n   size(700, 500);\r\n    background(200);\r\n    myPicture = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/gnat2.png\");\r\n    imageMode(CENTER);\r\n    for (int i = 0; i < sprites.length; i++){\r\n      sprites[i] = new Sprite();\r\n    }\r\n}\r\n\r\nvoid draw() {\r\n  int change = int(random(100));\r\n  if( change == 99){\r\n    background(200);\r\n    inChange = 0;\r\n  }\r\n  else if(inChange <= 50){\r\n    background(200);\r\n    inChange++;\r\n  }\r\n  for(int z = 0; z < sprites.length; z++){\r\n    sprites[z].moveSprite();\r\n    sprites[z].drawSprite();\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; \/\/variable for storing colors\r\n  float maxS;\r\n  float baseS;\r\n  float changeS;\r\n  \r\n   Sprite(){ \r\n      myColor = color(random(255), random(255), random(255), random(50,255));\r\n      x = random(width);\r\n      y = random(height);\r\n      xmoveAmount = 5 - random(10);\r\n      ymoveAmount = 5 - random(10);\r\n      imageSize = 10 + random(40);\r\n      baseS = imageSize;\r\n      maxS = random(150,300);\r\n      changeS = random(5,15);\r\n   }\r\n   \r\n  void drawSprite(){\r\n    tint(myColor);\r\n    image(myPicture,x,y,imageSize,imageSize);\r\n  }\r\n\r\n  void moveSprite(){\r\n    x += xmoveAmount; \/\/move the shapes\r\n    y += ymoveAmount;\r\n\r\n    boolean changed = false;\r\n    if (x>=width) { \/\/this section checks to see if we're out of bounds\r\n      xmoveAmount = 0-xmoveAmount; \/\/reverses direction\r\n      changed = true;\r\n    }\r\n    else if (x<=0) {\r\n      xmoveAmount = 0-xmoveAmount;\r\n      changed = true;\r\n    }\r\n    \/\/don't have it get stuck on the edge.s\r\n    if (y>= height) {\r\n      ymoveAmount= 0-ymoveAmount;\r\n      changed = true;\r\n    }\r\n    else if (y<=0) {\r\n      ymoveAmount=0-ymoveAmount;\r\n      changed = true;\r\n    }\r\n    if(changed) {\r\n       myColor = color(random(255), random(255), random(255), random(50,255));\r\n       if(imageSize < maxS){\r\n         imageSize+=changeS;\r\n       }\r\n       else{\r\n         imageSize = baseS;\r\n       }\r\n    }\r\n  }\r\n}\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this variation of the mover script whether the background resets or not is determined by a set of rules I gave the program. There is some randomness involved as you can tell but I tried to have it maintain &hellip; <a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/06\/mover-edit-time-bugs\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":12,"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\/336"}],"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\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/comments?post=336"}],"version-history":[{"count":3,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/336\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/336\/revisions\/338"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/media?parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/categories?post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/tags?post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}