{"id":469,"date":"2012-01-06T01:18:19","date_gmt":"2012-01-06T09:18:19","guid":{"rendered":"http:\/\/new.joyofprocessing.com\/blog\/?p=469"},"modified":"2012-01-05T17:22:36","modified_gmt":"2012-01-06T01:22:36","slug":"pairs","status":"publish","type":"post","link":"https:\/\/joyofprocessing.com\/blog\/2012\/01\/pairs\/","title":{"rendered":"Pairs"},"content":{"rendered":"<p><script type=\"application\/processing\">\/\/ Pairs - Jim Bumgardner\n\nint startTime;\nfloat durationS = 2;\nfloat durationMS = durationS*1000;\nfloat segDist = 100;\n\nPVector[] coords = new PVector[4];\nfloat d1,d2;\n\nvoid setup()\n{\n  size(500,500);\n  noStroke();\n  fill(0);\n  smooth();\n  background( #ffffff );\n  for (int i = 1; i < 4; ++i) {\n    coords[i] = new PVector(random(width),random(height));\n  }\n  for (int i = 1; i < 4; ++i) {\n    nextPoint();\n  }\n  startTime = millis();\n  frameRate(24);\n  d1 = random(10,50);\n  d2 = random(10,50);\n}\n\nvoid nextPoint()\n{\n    coords[0] = coords[3];\n    coords[1] = coords[2];\n    \/\/ reflect about coords[0]\n    coords[1].x = coords[0].x - (coords[1].x-coords[0].x);\n    coords[1].y = coords[0].y - (coords[1].y-coords[0].y);\n    do {\n      float a = random(TWO_PI);\n      coords[3] = new PVector(random(width),random(height));\n    } while (dist(coords[3].x,coords[3].y,width\/2,height\/2) > width\/3);\n    float a = random(TWO_PI);\n    coords[2] = new PVector(coords[3].x+cos(a)*segDist,coords[3].y+sin(a)*segDist);\n    d1 = d2;\n    d2 = random(10,50);\n}\n\nvoid draw()\n{\n  fill(50,100,50,20);\n  rect(0,0,width,height);\n  float r = (millis() - startTime)\/durationMS;\n  while (r > 1.0) {\n    r -= 1.0;\n    nextPoint();\n    startTime += durationMS;\n  }\n  float x = bezierPoint(coords[0].x,\n                       coords[1].x,  \n                       coords[2].x,  \n                       coords[3].x,\n                       r);  \n  float y = bezierPoint(coords[0].y,\n                       coords[1].y,  \n                       coords[2].y,  \n                       coords[3].y,\n                       r);  \n  float tx = bezierTangent(coords[0].x,\n                       coords[1].x,  \n                       coords[2].x,  \n                       coords[3].x,\n                       r);  \n  float ty = bezierTangent(coords[0].y,\n                       coords[1].y,  \n                       coords[2].y,  \n                       coords[3].y,\n                       r);  \n  float a = atan2(ty,tx);\n  noStroke();\n  \n  float d = lerp(d1,d2,r);\n  \n  if (frameCount % 2 > 0) {\n    fill( #ffaaaa );\n    ellipse(x+cos(a-PI\/2)*d,y+sin(a-PI\/2)*d,10,10);\n  } else {\n    fill( #aaaaff );\n    ellipse(x+cos(a+PI\/2)*d,y+sin(a+PI\/2)*d,10,10);\n  }\n}\n\n<\/script><\/p>\n<div class=\"ps_cap\"><a href=\"\/showexample.php?ex=pairs\">source<\/a><\/div>\n<p>My original idea was to make a sketch which drew random railroad tracks, using bezierTangent.  I liked watching the motion of the railroad tie endpoints, and made this Pas de deux instead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>source My original idea was to make a sketch which drew random railroad tracks, using bezierTangent. I liked watching the motion of the railroad tie endpoints, and made this Pas de deux instead.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[21,11],"class_list":["post-469","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-advanced","tag-animation"],"_links":{"self":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/comments?post=469"}],"version-history":[{"count":5,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/469\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/469\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/media?parent=469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/categories?post=469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/tags?post=469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}