We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › display a mirror sketch in second window
Page Index Toggle Pages: 1
display a mirror sketch in second window (Read 503 times)
display a mirror sketch in second window
Dec 25th, 2009, 6:47pm
 
Hi:

My goal is to have animation running on one screen, and have onscreen controls (sliders, buttons) composited on top of the same animation on the second screen.

I found this sketch where you can have two processing windows open at the same time through a single sketch. I'm wondering how I can copy the animation from the first window and display it in the second, essentially running a mirror without actually running the same code twice. I tried to do it with PImage with no luck.

here is what i found, thanks for the help:

private static secondCanvas sCanvas;
private static secondApplet sApplet;

import java.awt.*;
import java.awt.event.*;
import processing.core.*;

int xPos = 0;
int yPos = 0;

void setup() {
size(400, 400);
smooth();
background(0);
noStroke();

sApplet = new secondApplet();
sCanvas = new secondCanvas("follower", sApplet, screen.width/2, screen.height/2);
}

void draw() {
background(0);
// fill(200, 100, 0);
// rect(xPos++,0, 100, 100);
// if(xPos >= width) xPos = 0;
  fill(200, 100, 0);
  rect(0, yPos++, 100, 100);
  if(yPos >= height) yPos = 0;
}

public class secondApplet extends PApplet {

public void setup() {
  size(400, 400);
  background(255, 0, 0);
//   frameRate(10);
}

//---------this draws the second window--------------
public void draw() {
  background(0);

  fill(200, 100, 0);
  rect(0, yPos++, 100, 100);
  if(yPos >= height) yPos = 0;
}
}


public class secondCanvas extends Frame {
public secondCanvas(String name, PApplet embed, int x, int y) {
  super(name);

  // add the PApplet to the Frame
  setLayout(new BorderLayout());
  add(embed, BorderLayout.CENTER);

  // ensures that the animation thread is started and
  // that other internal variables are properly set.
  embed.init();

  // add an exit on close listener
  addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent evt) {
      // exit the application
      System.exit(0);
    }
  }
  );

  setSize(400, 400);
  setLocation(x, y);
  setVisible(true);

}
}
Page Index Toggle Pages: 1