Size problem on two window at the same sketch

edited June 2017 in Library Questions

Hi Everyone,

I have written a code that uses the "controlP5" library. The sketch has some sliders and textboxes. The setup function of the sketch has the information about the position of the gui elements.

So, I want to make a simulation. In fact, I did on other sketch, but I got a size problem when I implement the simulation and the code on the same sketch. Let me explain a bit more about the simulation :

I used P3D to apply the coordinates of the shape by using vertex function.

Here is a quick example of what I did so far :

          public class SecondApplet extends PApplet {
          public void settings() {
                size(1000, 600,P3D);
              }
          public void setup() {

            translate(width/2,height/3, -200);
            stroke(255);
            noFill();

            beginShape();

            vertex(-82.27,0,47.5); vertex(0,0,-23.75);
            vertex(82.27,0,47.5); vertex(-82.27,0,47.5);


            vertex(-270,0,0); vertex(-65,397.5,0);
            vertex(32.5,397.5,-56.3); vertex(32.5,397.5,56.3);

            vertex(-65,397.5,0); vertex(32.5,397.5,56.3);
            vertex(135,0,233.827); vertex(82.27,0,47.5);

            vertex(0,0,-23.75); vertex(135,0,-233.827);
            vertex(32.5,397.5,-56.3);
            endShape();
          }
        }

        void setup() {
          size(1000,800);
          frameRate(25);

          controlP5 = new ControlP5(this);
          controlP5.setAutoInitialization(false);

          /* Setups of the gui elements ...
              -----------------------*/

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

So, the situation is the size problem on the two windows that I wanted to see when I run the sketch. The main window, which is on the "void setup()" section, is smaller than the second window.

I tried to find out the solution, but I couldn't overcome this problem. What I have to do in order to solve this situation ?

( I tried to explain the problem as well as I can).

I am looking forward to your suggestions. Thanks in advanced.

Have a nice works to all..

Answers

  • Answer ✓

    Use settings() for the main sketch as well! L-)

  • Thanks a lot. It works. :)

  • Now, I have another problem about this :) Is there any way to control the coordinates within the vertex function by using the slider variables on the main window. For example :

    vertex(x_pos,y_pos,z_pos); // x_pos is the variable that includes the slider value 
                                              // and the other respectively.
    

    When I did like this, there was no change on the second window.

    Clearly, I wanted to control the simulation on the second window by using sliders on the main window. So, I thought I can do this with the code I wrote above. However, as I said that, there was no change. It keep constant.

    Thanks in advance..

  • edited June 2017
    • Dunno enough about this library in order to help you out properly, sorry. 8-|
    • Also it's still not clear to me whether field x_pos belongs to the main PApplet or to the SecondApplet. :-/
    • In order for ControlP5 to "control" some field, we also need to tell it which PApplet to look for it somehow. =;
  • edited July 2017

    Check the following demo. Notice you need to explicitly write an empty draw() function to have an interactive slider.

    Kf

    //REFERENCE: http:// www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5slider/ControlP5slider.pde
    
    
    import controlP5.*;
    int sliderX=100;
    
    
    public class SecondApplet extends PApplet {
    
      int internalX;
    
      public void settings() {
        size(1000, 600, P3D);
      }
      public void setup() {
    
    
        stroke(255);
        noFill();
      }
    
      void draw() {
        background(144);
        translate(width/2, height/3, -200);
        internalX=sliderX;
    
        if(frameCount%30==0) println("Val="+internalX);
    
        beginShape();
    
        vertex(-82.27, 0, 47.5); 
        vertex(internalX, 0, -23.75);
        vertex(82.27, 0, 47.5); 
        vertex(-82.27, 0, 47.5);
    
    
        vertex(-270, 0, 0); 
        vertex(-65, 397.5, 0);
        vertex(32.5, 397.5, -56.3); 
        vertex(32.5, 397.5, 56.3);
    
        vertex(-65, 397.5, 0); 
        vertex(32.5, 397.5, 56.3);
        vertex(135, 0, 233.827); 
        vertex(82.27, 0, 47.5);
    
        vertex(internalX, 0, -23.75); 
        vertex(135, 0, -233.827);
        vertex(32.5, 397.5, -56.3);
        endShape();
      }
    }
    
    void settings() {
      size(400, 600);
    }
    void setup() {
    
      SecondApplet  sa = new SecondApplet();
      String[] args = {"TwoFrameTest"};
      PApplet.runSketch(args, sa);
    
      //------------------
    
      ControlP5 cp5= new ControlP5(this);
      //cp5.setAutoInitialization(false);
    
      cp5.addSlider("sliderX")
        .setPosition(40, 40)
        .setSize(200, 20)
        .setRange(-sa.width/2, sa.width/2)
        .setValue(100)
        .setColorCaptionLabel(color(255));
    
    
    }
    
    void draw() {
    }
    
Sign In or Register to comment.