adnil
YaBB Newbies
Offline
Posts: 28
integrate slider positions into class of shapes
Oct 10th , 2009, 5:23pm
I am working on a program that generates graphics according to a user's text input. I am using a some ControlP5 buttons to start the conversion from text to image. At the moment I am not doing anything in the draw() method but would like to have the final shapes follow the position of a slider because i found some textinput might be so long it goes off the screen. I have put part of the code below. How do I have to amend the draw() (or any other ones) method and where to call the class of shapes to make it work. import controlP5.*; int yPos = 0; Shapes[] shapes; void setup { size(500, 500) frameRate(25); background(backGroundCoLour); smooth(); myTextfield = controlP5.addTextfield("texts",marginX,height-100,200,20); myTextfield.setFocus(true); myTextfield.setColorBackground(grey-30); myTextfield.setColorActive(colorActive); controlP5.Button ger = controlP5.addButton("GER",22,320,height-100,20,20); ger.setColorBackground(grey-30); ger.setColorActive(colorActive); ger.setId(1); controlP5.Button fre = controlP5.addButton("FRE",23,350,height-100,20,20); fre.setColorBackground(grey-30); fre.setId(2); fre.setColorActive(colorActive); Slider s = controlP5.addSlider("mySlider", 0, height-200, (height-200)/2 , width - 15, 50 , 5 , height -200); s.setColorActive(colorActive); s.setColorBackground(grey); s.setColorForeground(grey-50); s.setId(21); } void draw() { background(backGroundCoLour); } void controlEvent(ControlEvent theEvent) { //textfield if( theEvent.controller().id() == -1) { String textinput = (myTextfield.getText()); String myTargetLanguage = "ENGLISH"; textfieldhasbeenUsed = true; } //button 1 else if( theEvent.controller().id() == 1) { String textinput = (myTextfield.getText()); String target = "GERMAN"; categorizeThis(textinput, target); } //button 2 else if( theEvent.controller().id() == 2) { String textinput = (myTextfield.getText()); String target = "FRENCH"; categorizeThis(textinput, target); } //slider else if( theEvent.controller().id() == 21) { yPos = theEvent.controller().value(); } categorizeThis(String textinput, String target) { //method calls a categorization tool ans generates the String source translatethis(textinput, target, source); } translatethis(String textinput, String target,String source) { //method tanslates the text into different languages with google api drawthewords(textinput, target, source); } drawthewords(String textinput, String target,String source) { String[] splitintoWords = splitTokens(textinput," "); ArrayList allwords = new ArrayList(); for ( int i = 0; i < splitintoWords.length; i++) { String eachWord = " " + splitintoWords[i] + " "; allwords.add(eachWord); } String[] words = new String[allwords.size()]; for (int k = 0 ; k < allwords.size(); k++) { words[k] = (String)allwords.get(k); } shapes = new Shapes[words.length]; for (int i=0; i < words.length; i++) { //this class contains all the methods for the shapes I want to draw to the screen shapes[i] = new Shapes (words.length, words, i, words[i]); shapes[i].createTwoCombinations(); } }