drawing to a buffer

I am trying to draw a simple wave plot, to be sent to Csound over OSC. The problem is, I would like to save the y value to an array as I'm drawing. Something like:

void mouseDragged(){
  stroke(25,25);
    int x = mouseX;
    if (x<512 && x>=0) {      
      int y = mouseY;
      line(x, y, pmouseX, pmouseY);
      outbuf[x] = y;
    }
}

But this leaves gaps in the buffer, unless I draw really slow. How to get around this?

Richard

Tagged:

Answers

  • I think it should work. I would try doing it in draw() inside this conditional:

    if (mousePressed) {
    
  • Yes, tried it in draw() too, but the same thing. I understood I was better of using mouseDragged() or mouseMoved().. When I show the output buffer ( at the frame rate or slower), it has these gaps.

  • // forum.processing.org/one/topic/saving-mouseevent-data-in-an-array
    // forum.processing.org/two/discussion/160/exporting-data
    
    import java.util.List;
    
    final static List<PVector> coords = new ArrayList();
    
    final static color BG = -1, FG = 0300, BORDER = 0;
    final static short DIM = 20, BOLD = 2, FPS = 100;
    
    void setup() {
      size(640, 480);
      smooth();
      noLoop();
      frameRate(FPS);
    
      fill(FG);
      stroke(BORDER);
      strokeWeight(BOLD);
      background(BG);
    }
    
    void draw() {
      print(coords.size() + " - ");
    }
    
    void mouseDragged() {
      redraw();
      coords.add( new PVector(mouseX, mouseY) );
      ellipse(mouseX, mouseY, DIM, DIM);
    }
    
    void keyTyped() {
      if (key != ' ' & key != RETURN & key != ENTER)  return;
    
      final String archive = dataPath("MouseCoords.txt");
    
      final int num = coords.size();
      final String[] coordsTxt = new String[num];
    
      for (int i = 0; i != num; ++i) {
        //final PVector coord = coords.get(i);
        //coordsTxt[i] = coord.x + "," + coord.y;
    
        final int[] coord = int( coords.get(i).array() );
        coordsTxt[i] = coord[0] + "," + coord[1];
      }
    
      saveStrings(archive, coordsTxt);
      println("\n\nMOUSE COORDS SAVED!\n");
    }
    
  • Interesting approach, GotoLoop, but for a wave file I need every x coordinate to be filled. This method also skips x coordinates (leaves gaps) when I move the mouse faster...

    Richard

  • edited October 2013

    Dunno! Mebe you should create a method to analyze each collected coordinate, and then fill in the gaps between 1 to the other.
    Then save it to another structure.

  • Yes, I was thinking about that too.

Sign In or Register to comment.