|
Author |
Topic: simply getting relative values from a slider (Read 375 times) |
|
kantaria
|
simply getting relative values from a slider
« on: Aug 7th, 2004, 1:59pm » |
|
hi there, i wonder how to calculate the relative values of a slider no matter how it is placed on the screen. for example: i want to get values between 0 and 1 no matter where on the screen it is placed. anybody done that lready? cheers k
|
|
|
|
st33d
|
Re: simply getting relative values from a slider
« Reply #1 on: Aug 8th, 2004, 12:39am » |
|
What's a slider? Code: String coord; float x; float y; void setup(){ background(0); size (400,400); } void loop(){ x=(1.0/width)*mouseX; y=(1.0/height)*mouseY; String coord=("x:"+x+"y:"+y); println (coord); //while (!mousePressed){} } |
| This code returns values between zero and one depending on the location of the mouse on screen. The remindered out code halts the print out to clicks but crashes my computer. If you have to put the slider on screen then you already have values to divide 1.0 by. Gives a relative value between 0 and 1 at least, unless you wanted something else that is. Hope I haven't told you something you already know.
|
I could murder a pint.
|
|
|
narain
|
Re: simply getting relative values from a slider
« Reply #2 on: Aug 8th, 2004, 5:51am » |
|
//while (!mousePressed){} I'm willing to bet mousePressed only gets updated between loop()s, so p5 will effectively get stuck here and never get out. You should put your calculation and printout in the mousePressed() function instead.
|
|
|
|
kantaria
|
Re: simply getting relative values from a slider
« Reply #3 on: Aug 8th, 2004, 1:08pm » |
|
sorry, i thought thatd be clear. a slider is an interface element that can be moved in one direction and that movement is limited by a left/top side and and a right/bottom side. looks a bit like this: (left side) ----------|---------- (right side) it is used to steer certain values, and i want some to return me values from o to one. the values have to be calculated out of the bars lenght and the absolute position on the screen, i think.
|
|
|
|
fjen
|
Re: simply getting relative values from a slider
« Reply #4 on: Aug 8th, 2004, 2:34pm » |
|
|-------|-------| x1 xs x2 slider_start = x1 slider_end = x2 slider_length = x2 - x1 slider_handle = xs - x1 value = slider_handle / slider_length
|
|
|
|
kantaria
|
Re: simply getting relative values from a slider
« Reply #5 on: Aug 8th, 2004, 8:15pm » |
|
vielen dank. hab manchmal einen matheknoten im kopf...
|
|
|
|
fjen
|
Re: simply getting relative values from a slider
« Reply #6 on: Aug 9th, 2004, 8:33am » |
|
hihi ... geht mir genauso.
|
|
|
|
Igorius
|
Re: simply getting relative values from a slider
« Reply #7 on: Oct 20th, 2004, 2:40pm » |
|
Hi kantaria, here is the code for a slider that I made a few days ago (I started with processing about 1 month ago). I had the same problem as you did so I decided to write a class in which, amongst others, you set the min and max values to be returned by the slider, regardless of its position or size. You can find the full code here: http://perso.wanadoo.fr/s-e-b/Java/Applets/slider/scrollbar.html Hope this helps.
|
|
|
|
|