Created
November 12, 2013 20:11
-
-
Save benfarahmand/7437804 to your computer and use it in GitHub Desktop.
architecture for multiple monitors, applets, and frames running from the same processing sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This simple architecture lets you span two monitors with a single processing sketch | |
import java.awt.Frame; | |
import processing.opengl.*; | |
firstApplet firstApp; | |
secondApplet secondApp; | |
SecondFrame secondFrame; | |
FirstFrame firstFrame; | |
int secondFrameWidth = 640, secondFrameHeight = 480; // width and height of secondary monitor | |
int firstFrameWidth = 640, firstFrameHeight = 480; // width and height of first monitor | |
int secondFrameX = firstFrameWidth, secondFrameY = 0; // position the frame for the secondary monitor where the first monitor ends | |
int firstFrameX = 0, firstFrameY = 0; //the position for the first monitor | |
void setup() { | |
size(100, 100, OPENGL); | |
secondFrame = new SecondFrame(secondApp, secondFrameX, secondFrameY, secondFrameWidth, secondFrameHeight); | |
firstFrame = new FirstFrame(firstApp, firstFrameX, firstFrameY, firstFrameWidth, firstFrameHeight); | |
textAlign(CENTER); | |
noLoop(); | |
} | |
void draw() { | |
background(255); | |
fill(0); | |
textSize(24); | |
text("hide me", width/2, height/2); | |
} | |
public class firstApplet extends PApplet { | |
int counter = 0; | |
public void setup() { | |
size(firstFrameWidth, firstFrameHeight); | |
frameRate(10); | |
} | |
public void draw() { | |
//draw thread for first applet | |
background(255); | |
fill(0); | |
textSize(24); | |
text(counter, firstFrameWidth/2, firstFrameHeight/2); | |
counter=counter-1; | |
} | |
} | |
public class secondApplet extends PApplet { | |
int counter = 0; | |
public void setup() { | |
size(secondFrameWidth, secondFrameHeight); | |
frameRate(10); | |
} | |
public void draw() { | |
//draw thread for second applet | |
background(255); | |
fill(0); | |
textSize(24); | |
text(counter, secondFrameWidth/2, secondFrameHeight/2); | |
counter++; | |
} | |
} | |
public class FirstFrame extends Frame { | |
public FirstFrame(PApplet pa, int x, int y, int w, int h) { | |
setUndecorated(true); | |
pa = new firstApplet(); | |
setBounds(x, y, w, h); | |
add(pa); | |
pa.init(); | |
show(); | |
} | |
} | |
public class SecondFrame extends Frame { | |
public SecondFrame(PApplet pa, int x, int y, int w, int h) { | |
setUndecorated(true); | |
pa = new secondApplet(); | |
setBounds(x, y, w, h); | |
add(pa); | |
pa.init(); | |
show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment