hanleybrand
YaBB Newbies
Offline
Posts: 2
Re: toggling controlP5 toggle via keypress, function,
Reply #1 - May 13th , 2010, 10:27am
Quote: import controlP5.*; ControlP5 kp5;int [] memMouse = new int [4];int [] nowMouse = new int [4];int [] thenMouse = new int [4];int little = 5;int middle = 10;int big = 25;boolean brush0 = false ;boolean brush1 = true ;//Toggle b0; //Toggle b1; void setup () { size (580, 320); background (colorFromPalette()); stroke (colorFromPalette()); fill (colorFromPalette()); frameRate (int (random (2, 20))); // instantiate controlP5 objects kp5 = new ControlP5(this ); //b0 = kp5.controller.addToggle("brush0").linebreak(); //kp5.controller("brush0").toggle(); kp5.addToggle("brush0" ).linebreak(); //works kp5.addToggle("brush1" ); }void draw () { stroke (colorFromPalette()); fill (colorFromPalette()); updateMemMouse(); }void mouseMoved (){ brushedSqares(); brushPointist(); }void keyPressed () { if (key =='1' ) { brush0(brush0); // this toggles the brush, but not the state of the Toggle // other attempts: // kp5.controller("brush0").toggle(); // gives error: //processing.app.debug.RunnerException: The function toggle() does not exist. //kp5.brush0.toggle(); // cannot be resolved or is not a fieldd // brush0.toggle(); // can not be invoked on primitive type boolean (wasn't a surprise, but I figured I'd try) /* toggle public void toggle() switch the state of a toggle. */ } }void brushPointist(){ if (brush0 == true ){ stroke (colorFromPalette(), int (random (10,60))); fill (colorFromPalette(), int (random (20,40))); rectMode (CENTER ); rect (mouseX , mouseY , 10, 10); line (mouseX , mouseY , memMouse[0], memMouse[1]); smooth (); } }void brushedSqares(){ if (brush1 == true ){ stroke (colorFromPalette(), random (1, 10)); fill (colorFromPalette(), int (random (1,24))); ellipse (mouseX , mouseY , int (random (16,24)), int (random (16,24))); line (mouseX , mouseY , memMouse[0], memMouse[1]); smooth (); } }void updateThenMouse() { thenMouse[0] = mouseX ; thenMouse[1] =mouseY ; thenMouse[2] = pmouseX ; thenMouse[3] = pmouseY ; }void updateMemMouse() { memMouse[0] = mouseX ; memMouse[1] =mouseY ; memMouse[2] = pmouseX ; memMouse[3] = pmouseY ; }public void brush0(boolean theValue){ println ("### got an event from numberboxC : " +theValue); if (brush0 == true ){ brush0 = false ; //processing.app.debug.RunnerException: The function setState(boolean) does not exist. //kp5.controller("brush0").setState(false); } else { brush0 = true ; //kp5.controller("brush0").setState(true); } }color colorFromPalette(){ color [] thisColor = new color [5]; int pickThis = int (random (0, 4)); thisColor[0] = color (#A0B6CB); thisColor[1] = color (#FDFEEE); thisColor[2] = color (#FAEAD0); thisColor[3] = color (#FF460D); thisColor[4] = color (#00A7E1); return thisColor[pickThis]; }