/** * ParabolicRaytracer v1.0.1 by cdmb architects (cc) 2008
* is a simple parabolic calculator based on input variables.
*
* Use the scroll bars to adjust the variables.
*
* For further information and questions about ParabolicRaytracer please
* take a look at the documentation, the examples, or the
* website at http://barlieb.com/index.php?option=com_content&task=view&id=79&Itemid=93
*
* key combinations:
* ALT+h hide and show controllers
* ALT+k bring the key menu to the front. use the arrow keys.
* Hold the ALT key and move controllers by dragging them.
*/ import controlP5.*; ControlP5 controlP5; //Initial Variables int x = 252; //X coordinates int f = 172; //Focal Shift int m = 139; //Vertical Shift int r = 8; //Ray Spacing void setup() { //Scrollbar Settings size(500,500); background(255); frameRate(25); controlP5 = new ControlP5(this); controlP5.addSlider("x coordinates",0,800,x,1,35,400,12).setId(1); controlP5.addSlider("focal shift",0,1000,f,1,50,400,12).setId(2); controlP5.addSlider("vertical shift",0,400,m,1,65,400,12).setId(3); controlP5.addSlider("ray spacing",1,41,r,1,80,400,12).setId(4); controlP5.setColorBackground(255); controlP5.setColorForeground(0); controlP5.setColorActive(0xffff0000); controlP5.setColorLabel(0); } void controlEvent(ControlEvent theEvent) { //Controls the Scrollbar and Variables println("got a control event from controller with id "+theEvent.controller().id()); switch(theEvent.controller().id()) { case(1): x = (int)(theEvent.controller().value()); break; case(2): f = (int)(theEvent.controller().value()); break; case(3): m = (int)(theEvent.controller().value()); break; case(4): r = (int)(theEvent.controller().value()); break; } } void draw() { background(255); smooth(); for (int i = 0; i <= x; i+=r ){ //For loop float y = sq(i)/f; //Parabolic equation float p = sq(i*2)/(16*y); //Focal point stroke(225,0,0); fill(225,0,0); point((height/2)+i,y+m); //Draws the parabolic points in the positive direction point((height/2)-i,y+m); //Draws the parabolic points in the negative direction stroke(255,0,0,150); strokeWeight(0); line((height/2)+i,y+m,(height/2)+i,y+1000); //Draws the incoming rays in the positive direction line((height/2)-i,y+m,(height/2)-i,y+1000); //Draws the incoming rays in the negative direction stroke(0); strokeWeight(0); point((height/2),p+m); //Focal point line((height/2),p+m,(height/2)+i,y+m); //Rays from focal point to parabolic curve in the positive direction line((height/2),p+m,(height/2)-i,y+m); //Rays from focal point to parabolic curve in the negative direction stroke(200); strokeWeight(0); line((height/2)+i,y+m,(height/2)+i,m-p); //Rays from parabolic curve to directrix in the positive direction line((height/2)-i,y+m,(height/2)-i,m-p); //Rays from parabolic curve to directrix in the negative direction stroke(255,120,0,150); strokeWeight(0); noFill(); ellipse((height/2)+i,y+m,sqrt(sq(i)+sq(y-p))*2,sqrt(sq(i)+sq(y-p))*2); //Parabolic Circles Positive ellipse((height/2)-i,y+m,sqrt(sq(i)+sq(y-p))*2,sqrt(sq(i)+sq(y-p))*2); //PArabolic Circles Negative } PFont font; //Prints all the Info to the window. font=loadFont("CourierNewPSMT-12.vlw"); textFont(font); fill(0); text("ParabolicRaytracer v1.0.1 ",0,12); text("cdmb architects (cc) 2008 ",0,24); }