We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Maths prob just cant get?
Page Index Toggle Pages: 1
Maths prob just cant get??? (Read 449 times)
Maths prob just cant get???
Mar 19th, 2007, 9:40pm
 
Hey guys, ive a simple question here...
ive a slider set up, i want it to return the value of 1 up to 10 as it moves along the slider bar...
Here is my code, the slider works fine, i just need to change the value of slx that is printing out to go from 1 - 10......
Thanks for any help
CODE:



public class effects extends PApplet {


int bottomToolBarHeight = 610;

int topToolBarHeight = 110;

float slx;

float sly;

boolean sliderOver = false;

boolean sliderLock = false;

int sls = 20;

int sliderLineLength;

int sliderLineStart;

int sliderLineEnd;


public void setup()

{


size(800, 700);


sliderLineLength = 200;


sliderLineStart = (width / 100) * 43;


sliderLineEnd = sliderLineStart + sliderLineLength;


slx = sliderLineStart;


sly = 43;

}



public void draw()

{



background(80);


stroke(0);


drawToolbar();


drawSlider();  
                println(""+slx);

}


public void drawToolBarLines()

{


pushMatrix();


fill(255);


rect(sliderLineStart, 56, sliderLineLength, 3);


popMatrix();





}


public void drawSlider()

{


if (mouseX > slx - sls && mouseX < slx + sls && mouseY > sly - sls




&& mouseY < sly + sls) {



sliderOver = true;


} else {



sliderOver = false;





}


pushMatrix();


rect(slx, sly, 5, 25);


popMatrix();

}

void drawToolbar()

{


drawToolBarLines();


drawSlider();

}

public void mousePressed()

{


if (sliderOver) {



sliderLock = true;



} else {



sliderLock = false;


}

}

public void mouseDragged()

{


if (sliderLock) {



if (mouseX < sliderLineStart) {




slx = sliderLineStart;



} else if (mouseX > sliderLineEnd) {




slx = sliderLineEnd;



} else {




slx = mouseX;



}


}

}

public void mouseReleased()

{


sliderLock = false;

}

}
Re: Maths prob just cant get???
Reply #1 - Mar 19th, 2007, 10:08pm
 
You just need to change one line:

Code:
//change the commented out line to the uncommented one.
// println(""+slx);
println( (float)(slx-sliderLineStart)/sliderLineLength * 10.0);
Re: Maths prob just cant get???
Reply #2 - Mar 19th, 2007, 10:14pm
 
My god, im sat here looking at it for 4 hours solid.... =) ha! Thanks so much mate
Page Index Toggle Pages: 1