controlP5 console output outside of draw()?

Hi All--

I'm trying to send system.out data to a console in a controlP5 GUI. I'm sending the data to a textarea using the following:

import controlP5.*;

ControlP5 controlP5;

Textarea Output;
Println console;

void setup()
{
controlP5 = new ControlP5(this);
  size(700, 600);

    Output=controlP5.addTextarea("Output")
    .setPosition(360, 110)
      .setSize(330, 430)
        .setLineHeight(14)
          .setColorBackground(color(255,100))
            .setColorForeground(color(255,100))
              .scroll(1)
                .hideScrollbar();
   controlP5.addButton("Start", 0, 360, 550, 160, 40);
   console = controlP5.addConsole(Output);
 } 

void draw()
{
  background(0);
  stroke(255);
}

void Start()
{
  for (int i = 0; i < 1000; i++) {
    println(str(i));
    delay(4);
  }
  for (int i = 0; i < 500; i++) {
    println(str(i));
    delay(4);
  }
}

It works but the data doesn't show up in the console until all the code in my "Start" function is finished. I would like this info to show after each "println(str(I));" is executed. I tried adding "redraw()" in my for loops but it doesn't help. Any one have any ideas?

Tagged:

Answers

  • Answer ✓
    • Function redraw() only sets internal variable redraw to true.
    • It doesn't cause draw() to run immediately: https://processing.org/reference/redraw_.html
    • And since delay() pauses current Thread, the canvas will be slowed down waiting for it!
    • Since the canvas is only refreshed after draw() finishes, the canvas gonna stay static waiting for your loops & delays!
  • Thanks GoToLoop...I guess the only way to do it is to use a different structure. The following works:

    import controlP5.*;
    
    ControlP5 controlP5;
    
    Textarea Output;
    Println console;
    boolean start = false;
    int i = 0;
    
    void setup()
    {
    controlP5 = new ControlP5(this);
      size(700, 600);
    
        Output=controlP5.addTextarea("Output")
        .setPosition(360, 110)
          .setSize(330, 430)
            .setLineHeight(14)
              .setColorBackground(color(255,100))
                .setColorForeground(color(255,100))
                  .scroll(1)
                    .hideScrollbar();
       controlP5.addButton("Start", 0, 360, 550, 160, 40);
       console = controlP5.addConsole(Output);
     } 
    
    void draw()
    {
      background(0);
      stroke(255);
      if (start && i < 1000) {
        println(str(i));
        delay(4);
        if (i == 999) {
          start = false;
          i = 0;
        }
        else {
        i++;
        }
    
    }
    }
    
    void Start()
    {
      start = true;
    }
    
Sign In or Register to comment.