adnil
YaBB Newbies
Offline
Posts: 28
slider value to define elements in a loop
Oct 14th , 2009, 6:17am
hi, i have got a very long text (and graphics) that I would like to draw to the screen. I would like to draw it bit by bit, so that only ever 7 words of the text are seen on the screen. I am using a slider to move the elements on and off the screen. So when I am calling my classes in draw() I would like the slider value to determine whether i am loading elements 0-6, 1-7, 2-8, 3-9... and so on. My lowest slider value is 0 and the highest 600. When the slidervalue has gone up +3.0 to the previous value or gone down -3.0 to the previous value I want to change which words are shown. Below is an outline of my sketch. I am struggling to figure out, how i can make this work for all values between 0 and 600 and how I would figure out if the value has increased or decreased. int sliderController = 0; ControlP5 controlP5; Slider s; float yPos = 0 ; Rect2Gram[] rects2Gram; void setup() { size(screen.width,screen.height-100); frameRate(25); background(backGroundCoLour); smooth(); controlP5 = new ControlP5(this); Slider s = controlP5.addSlider("mySlider", 0, 600, 20 , width - 15, marginY , 5 , height - (marginY)-80); s.setId(21); } void draw() { //how do I amend this to work for all values between 0 and 600 // to add 1 to sliderController if yPos increases by 3 // or to minus 1 off sliderController if yPos decreases by 3 if ( (yPos >=3.0) && (yPos <=6.0)) { println( "yPos: " + yPos); sliderController = 1; println( "sliderController: " + sliderController); } rects2Gram = new Rect2Gram[7]; for (int i = sliderController; i < sliderController + 6; i++) { rects2Gram[i] = new Rect2Gram (words.length, words, i, words[i], yPos,); rects2Gram[i].createTwoCombinations(); } } void controlEvent(ControlEvent theEvent) { if( theEvent.controller().id() == 21) { yPos = theEvent.controller().value(); }