Willem
YaBB Newbies
Offline
Posts: 3
calculating in a class
Jan 12th , 2010, 7:56am
Hello, I am a beginner at programming and I am trying to build a class for multiple graphic bars that visualize values. I have written the following code: Graphbar Graphbar1; void setup() { size(500,500); PFont font; font=loadFont("Tahoma-12.vlw"); textFont(font); Graphbar1= new Graphbar(60,60,"Stroom:","A",180,200); } void draw() { background(150); Graphbar1.DisplayPhysScale(); Graphbar1.DisplayBar(); Graphbar1.DisplayUnit(); } class Graphbar{ int Xpos; int Ypos; String PhysScale; String Unit; int Value; int Range; Graphbar(int tempXpos, int tempYpos,String tempPhysScale, String tempUnit, int tempValue, int tempRange ){ Xpos=tempXpos; Ypos=tempYpos; PhysScale=tempPhysScale; Unit=tempUnit; Value=tempValue; Range=tempRange; } void DisplayPhysScale(){ fill(97,118,219); stroke(97,118,150); rect(Xpos,Ypos,50,20); fill(0,18,106); text("Stroom:",Xpos+2,Ypos+15); } void DisplayBar(){ fill(97,118,219); stroke(97,118,150); rect(Xpos+52,Ypos,210,20); fill(188,193,219); stroke(0); rect(Xpos+57,Ypos+5,200,10); fill(0,18,106); stroke(0,18,156); int x=Value/Range*200; rect(Xpos+58,Ypos+6,x,8); } void DisplayUnit(){ fill(97,118,219); stroke(97,118,150); rect(Xpos+264,Ypos,40,20); fill(0,18,106); text(Value,Xpos+267,Ypos+15); text(Unit,Xpos+290,Ypos+15); } } Variable x is declared as a integer and needs to calculate the following: Value int x= --------- x 200 Range The problem is that the outcome is always 0 while in my opinion int Value =180 and int Range=200, am I wrong? Thanks, Willem