{"id":606,"date":"2012-11-12T17:11:22","date_gmt":"2012-11-12T17:11:22","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/?p=606"},"modified":"2012-11-12T17:16:04","modified_gmt":"2012-11-12T17:16:04","slug":"crystals","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/12\/crystals\/","title":{"rendered":"Crystals"},"content":{"rendered":"<p>In this one, you can click and drag to create crystals on the screen. each crystal&#8217;s color is determined by the point at which you start clicking, so crystals which grow from the same point will all be the same color. Press &#8220;R&#8221; to reset.<br \/>\n<script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\nboolean locked;\r\nfloat newx;\r\nfloat newy;\r\nfloat tempx;\r\nfloat tempy;\r\nint i;\r\nnLine[] lineBank = new nLine[1];\r\nPImage crystal;\r\nPImage crystal2;\r\nPImage rockBG;\r\n\r\nvoid setup()\r\n{\r\n  size(600,370);\r\n  locked = false;\r\n  i = 0;\r\n  crystal = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/crystal.png\");\r\n  crystal2 = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/crystalreverse.png\");\r\n  rockBG = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/rockBG.png\");\r\n}\r\n\r\nvoid draw()\r\n{\r\n  translate(newx,newy);\r\n  imageMode(CORNER);\r\n  tint(255);\r\n  image(rockBG,0,0,width,height);\r\n  \r\n  if (lineBank[0]!=null)\r\n  {\r\n  for(int n=0;n<lineBank.length;n++)\r\n  {\r\n    float[] inst = lineBank[n].instruct();\r\n    float midX = inst[0];\r\n    float midY = inst[1];\r\n    float cWidth = inst[2];\r\n    float cHeight = inst[3];\r\n    float theta = inst[4];\r\n    float x1 = inst[5];\r\n    float x2 = inst[6];\r\n    float y1 = inst[7];\r\n    tint(x1*255\/width, y1*255\/height, 255);\r\n    imageMode(CENTER);\r\n    \r\n    translate(midX,midY);\r\n    if(x1 < x2)\r\n    {\r\n    rotate (theta-PI\/2);\r\n    image(crystal2,0,0,cWidth,cHeight);\r\n    rotate(PI\/2-theta);\r\n    }\r\n    else\r\n    {\r\n    rotate (theta-PI\/2);\r\n   \r\n    image(crystal,0,0,cWidth,cHeight);\r\n    rotate(PI\/2-theta);\r\n    }\r\n    \r\n    translate(-midX,-midY);\r\n   \/\/ lineBank[n].drawNLine();\r\n    \r\n  }\r\n  }\r\n  \r\n  \r\n  if(mousePressed == true)\r\n  {\r\n    if(locked == false)\r\n    {\r\n     tempx = mouseX;\r\n     tempy = mouseY;\r\n    }\r\n    locked = true;\r\n    stroke(0);\r\n    line(tempx,tempy,mouseX,mouseY);\r\n  }\r\n}\r\n\r\n\r\nvoid mouseReleased()\r\n{\r\n  locked = false;\r\n  nLine NL = new nLine(tempx,tempy,mouseX,mouseY);\r\n  if (i==0)\r\n  {\r\n    lineBank[0]= NL;\r\n  }\r\n  else\r\n  {\r\n    lineBank = (nLine[])append(lineBank, NL);\r\n  }\r\n  i++;\r\n}\r\n\r\nvoid keyReleased()\r\n{\r\n  if(key == 'r')\r\n  {\r\n    lineBank = new nLine[1];\r\n    i = 0;\r\n  }\r\n}\r\n\r\nclass nLine\r\n{\r\n  float x1;\r\n  float y1;\r\n  float x2;\r\n  float y2;\r\n  \r\n  nLine(float x1a, float y1a, float x2a, float y2a)\r\n  {\r\n    x1 = x1a;\r\n    x2 = x2a;\r\n    y1 = y1a;\r\n    y2 = y2a;\r\n  }\r\n  \r\n  float[] instruct()\r\n  {\r\n    float midX = (x1+x2)\/2;\r\n    float midY = (y1+y2)\/2;\r\n    float d = dist (x1,y1,x2,y2);\r\n    float deltaX = x1-x2;\r\n    float deltaY = y1-y2;\r\n    \r\n    float theta = atan(deltaY\/deltaX);\r\n    \r\n    float []instructions = {midX,midY,35,d,theta,x1,x2,y1};\r\n    return instructions;\r\n  }\r\n  \r\n  void drawNLine()\r\n  {\r\n    stroke(0);\r\n    line(x1,y1,x2,y2);\r\n  }\r\n}\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this one, you can click and drag to create crystals on the screen. each crystal&#8217;s color is determined by the point at which you start clicking, so crystals which grow from the same point will all be the same &hellip; <a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/12\/crystals\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":18,"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\/606"}],"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\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/comments?post=606"}],"version-history":[{"count":6,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/606\/revisions"}],"predecessor-version":[{"id":618,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/606\/revisions\/618"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/media?parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/categories?post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/tags?post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}