[G4P] Issue with new Window

edited May 2017 in Library Questions

Hello.

I have a problem with the drawHandler of a new window created with G4P. The window is created when a button is pressed, this is where the window is created and its drawHandler:

void createWindow(){
  window = GWindow.getWindow(this, "Label", 400, 400, 400, 400, JAVA2D);
  window.addDrawHandler(this, "windowDraw");
  window.setActionOnClose(G4P.CLOSE_WINDOW);
}

public void windowDraw(PApplet appc, GWinData data){

  if(frameCount%50 == 0 && frames < 15){
      appc.fill(random(x,y), random(x,y), random(x,y), random(x,y));
      appc.noStroke();
      appc.ellipse(random(0,400), random(0,400),a, a);
  }
}

(a is a mapped value, originally from a rms-analysis, frames is variable that counts up every 50 frames) So the problem is, that it doesn't draw only one circle, but a seemingly random amount of circles every 50 frames. I hope somebody can help me with this. If you need more code, for better understanding let me know.

thanks in advance raiu

Answers

  • A GWindow is effectively a second sketch with its own set of PApplet control variables so line 9 should be

    if(appc.frameCount % 50 == 0 && frames < 15){

    frames is variable that counts up every 50 frames

    I can only assume that it is counting the frames in the main sketch draw() method which I suspect is not what you need.

    You might try

    void createWindow(){
      window = GWindow.getWindow(this, "Label", 400, 400, 400, 400, JAVA2D);
      window.addDrawHandler(this, "windowDraw");
      window.setActionOnClose(G4P.CLOSE_WINDOW);
      frames = 0;
    }
    
    public void windowDraw(PApplet appc, GWinData data){
    
      if(appc.frameCount % 50 == 0 && frames < 15){
          appc.fill(random(x,y), random(x,y), random(x,y), random(x,y));
          appc.noStroke();
          appc.ellipse(random(0,400), random(0,400),a, a);
          frames++;
      }
    }
    

    and don't forget to remove the existing statements that increment the frames variable.

    Can't promise this will do what you want but it might ;)

  • heyo. thanks, but it didn't really do the trick, at least it reduced it to 2 circles every draw cicle.. any other ideas?

  • How much code is there?

    Are you using other libraries apart from G4P?

  • edited May 2017

    processing sound, arduino and id3. All in all the program is about 270 lines.

  • OK I am replying here rather than by message because it has better formatting options than messaging.

    The I managed to get the program to run without throwing any exceptions which was a good start since I don't have Arduino capabilities.

    Unfortunately I could not make sense of your program logic because I cannot predict when frames is being incremented or zeroed, it was all very confusing and I don't have a clear idea of what you hope to achieve. It is really down to you to to clarify the logic and perhaps create a simple sketch that does not use the ID3 and Arduino libraries to get what you want graphically first. Then others will be in a better position to help.

    I think one of the problems is that you can't predict when the two windows are going to be updated. For instance, in a particular time period you might have 100 frames in the main window but only 80 in the secondary window. One thing you can be sure of and that is they are not updated alternatively.

  • edited May 2017

    frames starts counting up every 50frames when the go button is pressed (sets playing to true) and the main draw cicle starts analyzing. when the 2nd window gets closed via the stop button or the song finishes it's reset to 0.

    anyway i'm planning to scrap that part of the project, because it doesn't fit in estheticly anymore. thanks for the help tho.

Sign In or Register to comment.