int function for a line

edited October 2015 in Library Questions

Hello I would like to define one line (for example as a X) and then just use X when needed. I would like to have something like this:

int x = in.right.get(i)*30; vertex(207+x,227+x);

is there some way please?

Answers

  • you can write a function and use this function from draw()

    lineMyOwn (int x) {
        line(207+x, 222, 
               227+x, 290); 
    }
    
  • Or you can use translate beforehand.

    pushMatrix();
    translate(x,0);
    line(207,222,227,290);
    popMatrix();
    
  • when you use minim :

    void LineForMinim(int i) {
     int x = in.right.get(i)*30;
     vertex(207+x,227+x);
     line (207+x, 120, 227+x, 120);
    
    
    }
    
  • The last one you sent (Chrisir) seems nice, but actualy it's not working for me :/ it says unexpecting void.. but i would love solution like this

  • Sounds like a missing } somewhere

    Could you post your entire code please ...?

  • edited October 2015
    import ddf.minim.*;
    
    void setup;{
    size (900,900)
    
    void LineForMinim(int i) {
     int x = in.right.get(i)*30;
     vertex(207+x,227+x);
     line (207+x, 120, 227+x, 120);
    }
    }
    
  • There are several issues:

    • You have a ; instead of () after setup.

    • functions have to be outside of other functions.

    • You do not initialize minim and do not define in.

    The following example shows only the structure, i am not sure if i understood what exactly you wanted to do.

    // imports
    import ddf.minim.*;
    
    // variables
    Minim minim;
    AudioInput in;
    
    void setup(){
      size(200, 200);
      // initialize minim
      minim = new Minim(this);
      // initialize input-channel
      in = minim.getLineIn();
    }
    
    void draw(){
      // draw background
      background(200);
      // use a custom function
      ellipse(width/2, height/2, scaledInputLevel(), scaledInputLevel() );
    }
    
    // own functions have to be outside of setup() or draw()
    float scaledInputLevel() {
      return in.mix.level()*200;
    }
    
  • edited October 2015

    I want to simplify this:

    bezierVertex(1202,90,1285,186,1285+in.left.get(i)*50,430+in.right.get(i)*50);

    because sometimes I would like to give this dynamic value to every number. It uses Minim

  • honzojd

    you HAVE to learn to post code correctly. nobody can make sense of that mangled garbage.

    paste the text
    highlight the text
    press ctrl-o
    

    that's all it takes.

  • oof! rejected answer. i'm trying to help.

    look at how your code appears up there. does it match what you pasted? no. what's there is just a syntax error. this is because you haven't marked it as code.

Sign In or Register to comment.