/**
* RadCalc v1.0.2 | Radius Calculator by cdmb architects (cc) 2008
* is a simple radius calculator based on input panel dimensions and
* variable panel counts.
*
* Use the scroll bars to adjust the variables.
*
* Check the radius output.
*
* For further information and questions about RadCalc please
* take a look at the documentation, the examples, or the
* website at http://barlieb.com/index.php?option=com_content&task=view&id=75&Itemid=88
*
* 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.
*
* A future version will let you export a dxf and txt file of the points
*/
import controlP5.*;
ControlP5 controlP5;
float n = 14; // Here are the basic variables
float d = 150;
void setup() { // Scrollbar Settings
size(500,500);
frameRate(25);
controlP5 = new ControlP5(this);
controlP5.addSlider("panel size in cm",0,400,d,1,50,400,12).setId(2);
controlP5.addSlider("number of panels",2,402,n,1,65,400,12).setId(1);
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):
n = (float)(theEvent.controller().value());
break;
case(2):
d = (float)(theEvent.controller().value());
break;
}
}
void draw() {
background(255);
float t = (90 * (n-2)) / n; // These variables are the basic equation which could be written out...
float x = (tan(radians(t)))*(d/2); // however this lets us call all the information out later.
float r = sqrt(sq(x) + sq(d/2));
float g = 360 / n;
for (float deg = 0; deg <= 360; deg += 360/n) { // for Loop
float angle = radians(deg);
float a = (height/2) + (cos(angle)*r/2);
float b = (width/2) + (sin(angle)*r/2);
stroke(235); // Draws the spokes
smooth();
strokeWeight(1);
line(height/2,width/2,a,b);
stroke(255,0,0); // Draws the points
smooth();
strokeWeight(3);
beginShape(POINTS);
vertex(a,b);
endShape();
}
PFont font; // Prints all the Info to the window.
font=loadFont("CourierNewPSMT-12.vlw");
textFont(font);
fill(0);
text("RadCalc v1.0.2 | Radius Calculator",0,12);
text("cdmb architects (cc) 2008 ",0,24);
text("angle theta = " + t,0,90);
text("normal x = " + x,0,105);
text("360/n = " + g,0,120);
fill(255,0,0);
text("radius = " + r,345,485);
}