{"id":181,"date":"2015-06-18T05:05:17","date_gmt":"2015-06-18T01:05:17","guid":{"rendered":"http:\/\/courses.haigarmen.com\/creativecoding\/?p=181"},"modified":"2015-06-18T05:05:17","modified_gmt":"2015-06-18T01:05:17","slug":"exercise-33","status":"publish","type":"post","link":"https:\/\/courses.haigarmen.com\/creativecoding\/exercise-33\/","title":{"rendered":"Exercise 33"},"content":{"rendered":"<p>Now let&#8217;s animate the circles to move independently.<\/p>\n<pre><code>\r\nint _num = 10;\r\nCircle[] _circleArr = {\r\n};\r\nvoid setup() {\r\n  size(800, 800);\r\n  background(255);\r\n  smooth();\r\n  strokeWeight(1);\r\n  fill(150, 50);\r\n  drawCircles();\r\n}\r\nvoid draw() {\r\n  background(255);\r\n  for (int i=0; i<_circleArr.length; i++) {\r\n    Circle thisCirc = _circleArr[i];\r\n    thisCirc.updateMe();\r\n  }\r\n}\r\nvoid mouseReleased() {\r\n  drawCircles();\r\n}\r\nvoid drawCircles() {\r\n  for (int i=0; i<_num; i++) {\r\n    Circle thisCirc = new Circle();\r\n    thisCirc.drawMe();\r\n    _circleArr = (Circle[])append(_circleArr, thisCirc);\r\n  }\r\n} \r\n\r\n\/\/================================= objects\r\nclass Circle {\r\n  float x, y;\r\n  float radius;\r\n  color linecol, fillcol;\r\n  float alph;\r\n  float xmove, ymove;\r\n  Circle () {\r\n    x = random(width);\r\n    y = random(height);\r\n    radius = random(100) + 10;\r\n    linecol = color(random(255), random(255), random(255));\r\n    fillcol = color(random(255), random(255), random(255));\r\n    alph = random(255);\r\n    xmove = random(10) - 5;\r\n    ymove = random(10) - 5;\r\n  }\r\n  void drawMe() {\r\n    noStroke();\r\n    fill(fillcol, alph);\r\n    ellipse(x, y, radius*2, radius*2);\r\n    stroke(linecol, 150);\r\n    noFill();\r\n    ellipse(x, y, 10, 10);\r\n  }\r\n  void updateMe() {\r\n    x += xmove;\r\n    y += ymove;\r\n    if (x > (width+radius)) { \r\n      x = 0 - radius;\r\n    }\r\n    if (x < (0-radius)) { \r\n      x = width+radius;\r\n    }\r\n    if (y > (height+radius)) { \r\n      y = 0 - radius;\r\n    }\r\n    if (y < (0-radius)) { \r\n      y = height+radius;\r\n    }\r\n    drawMe();\r\n  }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Now let&#8217;s animate the circles to move independently. int _num = 10; Circle[] _circleArr = { }; void setup() { size(800, 800); background(255); smooth(); strokeWeight(1); fill(150, 50); drawCircles(); } void draw() { background(255); for (int i=0; i (height+radius)) { y = 0 &#8211; radius; } if (y < (0-radius)) { y = height+radius; } drawMe(); [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-lessons"],"_links":{"self":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":1,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":182,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/181\/revisions\/182"}],"wp:attachment":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}