{"id":402,"date":"2012-11-11T05:48:05","date_gmt":"2012-11-11T05:48:05","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/?p=402"},"modified":"2012-11-11T05:48:05","modified_gmt":"2012-11-11T05:48:05","slug":"project-1-electricity","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/11\/project-1-electricity\/","title":{"rendered":"Project 1 &#8211; Electricity"},"content":{"rendered":"<p>For the second sketch the Machine vs. Nature project series, my main inspiration was electricity! After seeing an example in class about how to create noise within a line, it sparked some great ideas on how to create an interactive Van der Graaf generator. The user can control the &#8220;power level&#8221; of the machine by using the up and down arrow keys. As the power level rises, random sparks of electricity in the background become more frequent. In addition, more lines of electricity form at power levels 5 and 10. Finally, the thickness of the electricity changes along with the color the more powerful the machine gets. Check out the machine below!<\/p>\n<p><script type=\"application\/processing\">\r\nfloat step = 10;\/\/try changing this\r\nfloat lastx = -999;\r\nfloat lasty = -999;\r\nfloat lastx2 = -999;\r\nfloat lasty2 = -999;\r\nfloat lastx3 = -999;\r\nfloat lasty3 = -999;\r\nfloat ynoise = random(10);\r\nfloat y;\r\nPFont power;\r\nPImage bolt;\r\nint boltX;\r\nint boltY;\r\nint counter = 0;\r\nint randomBolt;\r\nint powerLevel;\r\nvoid setup() {\r\n  bolt = loadImage(\"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-content\/uploads\/2012\/11\/bolt.png\"); \r\n  size(700, 500);\r\n  background(0);\r\n  strokeWeight(5);\r\n  smooth();\r\n  power = createFont(\"Verdana\", 16, true);\r\n  fill(0, 255, 0);\r\n  textFont(power, 36);\r\n  frameRate(35);\r\n  powerLevel = 0;\r\n  randomBolt = (int)random(120,200);\r\n}\r\nvoid draw() {\r\n  background(0);\r\n  drawGenerators();\r\n  stroke(80 - (powerLevel * 8), 20 * (powerLevel\/2), 150 - (powerLevel * 10), 100 + (powerLevel*20));\r\n  step = (int)25-((1.5*powerLevel) + 3);\r\n  lastx = -999;\r\n  lasty = -999;\r\n  lastx2 = -999;\r\n  lasty2 = -999;\r\n  lastx3 = -999;\r\n  lasty3 = -999;\r\n  \r\n  counter++;\r\n  if(counter == randomBolt){\r\n   boltX =  (int)random(130,450);\r\n   boltY =  (int)random(75,300);\r\n  }\r\n  if(counter > randomBolt){\r\n     image(bolt,boltX,boltY, 35, 105);\r\n  }\r\n  if(counter > randomBolt + 5){\r\n     counter = 0;\r\n     randomBolt = (int)random(120,200) - powerLevel * 12;\r\n  }\r\n  \r\n   \r\n  ynoise = random(10);\r\n  PFont font;\r\n  font =createFont(\"Verdana\", 16, true);\r\n  textFont(font);\r\n  String s = \"Power Level: \" + powerLevel;\r\n  text(s, 550, 20, 140, 70);\r\n  for (int x=150; x<=550; x+=step) {\r\n    strokeWeight((noise(ynoise) * 5) + (powerLevel\/2));\r\n    y = 100 + (noise(ynoise) * 80);  \/\/ between 10 and 90\r\n    if (lastx > -999) {\r\n      line(x, y, lastx, lasty);\r\n    }\r\n    lastx = x;\r\n    lasty = y;\r\n    ynoise += 0.1;\/\/can change this too\r\n  }\r\n  if (powerLevel >= 5) {\r\n    for (int j=150; j<=550; j+=step) {\r\n      stroke(80 - ((powerLevel-4) * 8), 20 * ((powerLevel-4)\/2), 150 - ((powerLevel-4) * 10), 100 + ((powerLevel-4)*20));\r\n      strokeWeight((noise(ynoise) * 5) + ((powerLevel-4)\/2));\r\n      y = 200 + (noise(ynoise) * 80);  \/\/ between 10 and 90\r\n      if (lastx2 > -999) {\r\n        line(j, y, lastx2, lasty2);\r\n      }\r\n      lastx2 = j;\r\n      lasty2 = y;\r\n      ynoise += 0.1;\/\/can change this too\r\n    }\r\n  } \r\n  if ( powerLevel == 10) {\r\n    for (int k=150; k<=550; k+=step) {\r\n      stroke(80 - ((powerLevel-9) * 8), 20 * ((powerLevel-9)\/2), 150 - ((powerLevel-9) * 10), 100 + ((powerLevel-9)*20));\r\n      strokeWeight((noise(ynoise) * 5) + ((powerLevel-9)\/2));\r\n      y = 300 + (noise(ynoise) * 80);  \/\/ between 10 and 90\r\n      if (lastx3 > -999) {\r\n        line(k, y, lastx3, lasty3);\r\n      }\r\n      lastx3 = k;\r\n      lasty3 = y;\r\n      ynoise += 0.1;\/\/can change this too\r\n    }\r\n  }\r\n}\r\n\r\nvoid drawGenerators(){\r\nfill(146,175,191);\r\nstroke(80 - ((powerLevel-4) * 8), 20 * ((powerLevel-4)\/2), 150 - ((powerLevel-4) * 10), 100 + ((powerLevel-4)*20));\r\nstrokeWeight(20);\r\nrect(45,75,100,400);\r\nrect(555,75,100,400); \r\nnoStroke();\r\nfill(90,90,90);\r\nrect(75,240,60,100);\r\nfill(0,255,0);\r\nrect(110,250,20,20);\r\nfill(255,0,0);\r\nrect(80,250,20,20);\r\nfill(0,0,255);\r\nrect(80,280,20,20);\r\nfill(220,220,150);\r\nrect(110,280,20,20);\r\nfill(220,220,220);\r\nrect(80,310,50,15);\r\nfill(0);\r\nellipse (90,317,4,4);\r\nellipse (105,317,4,4);\r\nellipse (120,317,4,4);\r\n\r\n\r\nfill(90,90,90);\r\nrect(570,240,60,100);\r\nfill(0,255,0);\r\nrect(605,250,20,20);\r\nfill(255,0,0);\r\nrect(575,250,20,20);\r\nfill(0,0,255);\r\nrect(575,280,20,20);\r\nfill(220,220,150);\r\nrect(605,280,20,20);\r\nfill(220,220,220);\r\nrect(575,310,50,15);\r\nfill(0);\r\nellipse (585,317,4,4);\r\nellipse (600,317,4,4);\r\nellipse (615,317,4,4);\r\n  \r\n}\r\n\r\nvoid keyPressed() {\r\n  if (keyCode == UP && powerLevel < 10) {\r\n    powerLevel++;\r\n  }\r\n  else if (keyCode == DOWN && powerLevel >1) {\r\n    powerLevel--;\r\n  }\r\n}\r\n\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the second sketch the Machine vs. Nature project series, my main inspiration was electricity! After seeing an example in class about how to create noise within a line, it sparked some great ideas on how to create an interactive &hellip; <a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/11\/project-1-electricity\/\">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\/402"}],"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=402"}],"version-history":[{"count":5,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/402\/revisions"}],"predecessor-version":[{"id":408,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/402\/revisions\/408"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/media?parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/categories?post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/tags?post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}