2 separate screens in Processing 3

edited July 2016 in Programming Questions

I want to put animations on 2 separate screens, one in Java2D, one in P3D. The available examples for that seem to function for P2 e.g. Multiple Nested PApplets (v2.0) by GoToLoop in the discussion https://forum.processing.org/two/discussion/10937/multiple-sketches

I do not know enough about Java and Processing to adapt this code to P3. Could someone link me to a functioning P3 example.

Help is much appreciated.

Answers

  • thank you very much GoToLoop for this hint!

  • edited July 2016 Answer ✓

    here is the solution to my problem which I have found on this site: https://forum.processing.org/two/discussion/13152/2-displays#latest With the void setup() method is was not possible to change the size of the PApplet window e.g. to fullScreen. So I had to change that line of code to public void settings() to make it possible. For notice I give here the slightly modified code:

    float ballX;
    float ballY;
    
    public void settings() { // this line was: public void setup() { it inhibited the risizing of the window size
      size(100, 100);
    
      String[] args = {"SecondApplet"};
      SecondApplet sa = new SecondApplet();
      PApplet.runSketch(args, sa);
    }
    
    void draw() {
      ballX = mouseX;
      ballY = mouseY;
      background(0);
      ellipse(ballX, ballY, 10, 10);
    }     
    
    public class SecondApplet extends PApplet {
    
      public void settings() {
        size(100, 100);
      }
      public void draw() {
        background(0);
        ellipse(ballX, ballY, 50, 10);
      }
    }
    
  • ... but now I have an issue with the 3D renderer if I apply a class to this sketch. I posted this here.

  • Hi, I want to create two separate screens windows, one show the text that I'm typing and the second one show an image for each letter typed. Eg. I type: "Hi." and it will appear an image for H and next to it an image for I. Can anyone help me? I'm new in Processing.

  • I modified the previous example to do what you require. You need to have in your sketch folder a folder named "data" and place in it two files, "h.jpg" and "i.jpg".

    float ballX;
    float ballY;
    int fig=-1;
    
    ArrayList<PImage> imgs;
    
    public void settings() { // this line was: public void setup() { it inhibited the risizing of the window size
      size(100, 100);
    
      imgs = new ArrayList<PImage>();
      imgs.add(loadImage("h.jpg"));
      imgs.add(loadImage("i.jpg"));
    
      String[] args = {"SecondApplet"};
      SecondApplet sa = new SecondApplet();
      PApplet.runSketch(args, sa);
    }
    
    void draw() {
      ballX = mouseX;
      ballY = mouseY;
      background(0);
      ellipse(ballX, ballY, 10, 10);
    }   
    
    void keyPressed() {
      if (key=='h' || key =='H')
        fig=0;
      else if (key=='i' || key =='I')
        fig=1;
    }
    
    public class SecondApplet extends PApplet {
    
      public void settings() {
        size(100, 100);
      }
      public void draw() {
        background(0);
        if (fig==0){
          image(imgs.get(0),0,0,width,height);
          ellipse(ballX, ballY, 50, 10);
        }
        if (fig==1){
          image(imgs.get(1),0,0,width,height);
          rect(ballX, ballY, 50, 10);      
        }
      }
    }
    

    I hope this helps,

    Kf

Sign In or Register to comment.