Size method for intial window not working when more windows are are added.

Recently I looked into making sketches with multiple windows and found some code online that allowed me to achieve this. The code I wrote based of the code I found online is below:

Tab 1:

void setup() {
  size(500, 500);

  String[] args = {"TwoFrameTest"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);

  ThirdApplet ta = new ThirdApplet();
  PApplet.runSketch(args, ta);
}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
}    

Tab 2:

public class SecondApplet extends PApplet {

  public void settings() {
    size(300, 300);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

public class ThirdApplet extends PApplet {

  public void settings() {
    size(400, 400);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

There is an issue however; when I run the code, the original window is displayed as its default size, even if a size method with different values is called. Strangely this even seems to happen if the other windows aren't called; the code in the second tab just has to be in the sketch folder and doesn't have to be referenced in any way. Does anybody have any idea what is happening and how I might fix it?

Answers

  • edited April 2017

    Since P3, functions size(), fullScreen(), smooth(), noSmooth() can only be used inside settings(): 3:-O
    https://Processing.org/reference/settings_.html

    However the PDE's pre-processor can seek out for them in the entire ".pde" files.
    And if there's more than 1 found, pre-processor search will fail it seems. :-&

    Your sketch contains 3 size() functions. Even though 2 are inside settings(), the pre-processor is too dumb and will fail to move the only size() inside setup() to its corresponding settings(). (:|

    The fix is simply having all size() inside settings() once we use more than 1: *-:)

    /**
     * RunSketch MultiPApplets (v1.1.1)
     * GoToLoop (2016-May-06)
     *
     * forum.Processing.org/two/discussion/16457/
     * size-method-for-intial-window-not-working-
     * when-more-windows-are-are-added#Item_1
     */
    
    final SecondApplet sa = new SecondApplet();
    final ThirdApplet  ta = new ThirdApplet();
    
    void settings() {
      size(500, 500);
      smooth(3);
      noLoop();
    
      final String[] switches = { "--sketch-path=" + sketchPath(), "" };
    
      runSketch(switches, sa);
      runSketch(switches, ta);
    }
    
    void draw() {
      background((color) random(#000000));
      ellipse(width>>1, height>>1, width>>1, height>>1);
    }
    
    static class SecondApplet extends PApplet {
      void settings() {
        size(300, 300);
        smooth(3);
        noLoop();
      }
    
      void draw() {
        background(-1);
        fill(0);
        ellipse(width>>1, height>>1, width>>1, height>>1);
      }
    }
    
    static class ThirdApplet extends PApplet {
      void settings() {
        size(400, 400);
        smooth(3);
        noLoop();
    
        println(sketchPath());
      }
    
      void draw() {
        background(0);
        fill(-1);
        ellipse(width>>1, height>>1, width>>1, height>>1);
      }
    }
    
  • edited April 2017

    I've converted from Java Mode to Python Mode as well: :ar!

    """
     ' RunSketch MultiPApplets (v1.1.1)
     ' GoToLoop (2016-May-06)
     '
     ' forum.Processing.org/two/discussion/16457/
     ' size-method-for-intial-window-not-working-
     ' when-more-windows-are-are-added#Item_2
    """
    
    def settings():
        size(500, 500)
        smooth(3)
        noLoop()
    
        global sa, ta
        sa, ta = SecondApplet(), ThirdApplet()
        switches = '--sketch-path=' + sketchPath(), ''
    
        PApplet.runSketch(switches, sa)
        PApplet.runSketch(switches, ta)
    
    
    def draw():
        background(int(random(0x1000000)))
        ellipse(width>>1, height>>1, width>>1, height>>1)
    
    
    class SecondApplet(PApplet):
        def settings(p):
            p.size(300, 300)
            p.smooth(3)
            p.noLoop()
    
    
        def draw(p):
            p.background(-1)
            p.fill(0)
            p.ellipse(p.width>>1, p.height>>1, p.width>>1, p.height>>1)
    
    
    
    class ThirdApplet(PApplet):
        def settings(p):
            p.size(400, 400)
            p.smooth(3)
            p.noLoop()
    
            print sketchPath(), ENTER, p.sketchPath()
    
    
        def draw(p):
            p.background(0)
            p.fill(-1)
            p.ellipse(p.width>>1, p.height>>1, p.width>>1, p.height>>1)
    
Sign In or Register to comment.