How can I make a basic geometrical shape change size from a text box

edited August 2014 in How To...

Hello everybody, I really need your help! I am really new to these program and only know the basics but i have to use it to make a project, so i really need help here. So the problem is that I need to make, for example, a triangle that will appear on the left side of the screen and on the right 3 text boxes in which I can add/write the length of the 3 sides of the triangle and after that the triangle modifies its shape according to the dimensions. Can someone please make these example, and I can reverse engineer/modify from there (this is the fastest way I can learn things). Thank you very much.

Answers

  • edited August 2014

    hello,

    can you post your code with the text fields first?

    Which libraries do you use?

    Is this homework?

    In general you read the values from the textfield and store them and use it in your triangle.

    But I think if we change the length of one line, another line has to get longer as well, right?

    Thank you!

    Best, Chrisir ;-)

  • I have to use it to make a project ...

    So the problem is that I need to make, for example ...

    Can someone please make these example, and I can reverse engineer/modify from there

    Mmmm sounds like coursework to me. ;)

    It is most unlikely someone really new to these to these program would be able to reverse engineer a significant example as the one you ask for.

    Why don't you have a go yourself and if you get stuck post the your code . :)

  • String[] s = {"1","10","20","125","350"};
    int on = 0;
    void setup(){
      size(400,400);
      stroke(255);
    }
    
    void draw(){
      background(0);
      for(int i=0; i<s.length; i++){
        fill(255,255,i==on?255:0);
        text(s[i], 20, 20 + 40 * i);
        line(0, 30 + 40 * i, int(s[i]), 30 + 40 * i);
      }
    }
    
    void keyTyped(){
      if(key==ENTER||key==RETURN){
        on++;
        on%=s.length;
      }
      if(key==DELETE||key==BACKSPACE){
        s[on]=s[on].substring(0,s[on].length()-1);
      }
      if(key>='0'&&key<='9'){
        s[on]=s[on]+char(key);
      }
    }
    
  • very nice...

    I would probably use a GUI library, see GUI

    http://processing.org/reference/libraries/

    e.g. G4P

    ;-)

  • @Chrisir G4P - excellent choice ;))

  • I know!! ;-)

Sign In or Register to comment.