Multiple borderless Processing windows
in
Share your Work
•
2 years ago
Here is the code I revised from this post
http://forum.processing.org/topic/switching-renderers-on-the-fly
What I like about Processing is that you can find multiple ways of doing the same thing, but cooler each time.
I also like the borderless windows but you can still drag them.
Processing rocks!!
http://forum.processing.org/topic/switching-renderers-on-the-fly
What I like about Processing is that you can find multiple ways of doing the same thing, but cooler each time.
I also like the borderless windows but you can still drag them.
Processing rocks!!
import java.awt.MouseInfo;
import java.awt.Point;
Point mouse;
//
//void draw() {
// Point mouse;
// mouse = MouseInfo.getPointerInfo().getLocation();
// println( "X=" + mouse.x + " Y=" + mouse.y );}
int maxwindows = 10;
Point [] _mouse = new Point[maxwindows];
boolean [] mouseup= new boolean [maxwindows];
Rectangle [] rm = new Rectangle[maxwindows];
int [] _offx = new int[maxwindows];
int [] _offy = new int[maxwindows];
import javax.swing.JFrame;
public PImage a;
public int mmx;
public int mmy;
public JFrame [] new_window= new JFrame[maxwindows];
MApplet sketchviewer;
public int frameWidth =0;//10
public int frameHeight =0; //25
public String rmode = "P3D";
void init()
{
frame.removeNotify();
frame.setUndecorated(true);
frame.addNotify();
super.init();
}
int w;
int h;
void setup(){
for (int i=0;i<maxwindows;i++){
mouseup[i]=true;
_offx[i]=0;
_offy[i]=0;
}
w=255;
h=255;
a=createImage(w,h,ARGB);
size(w,h,P3D);
background(233,23,23);
this.frame.setLocation(screen.width/2,screen.height/2);
r = frame.getBounds();
}
Rectangle r ;
//= frame.getBounds();
void mousePressed(){
r = frame.getBounds();
if(mup){
offx=mouseX;
offy=mouseY;
}
mup=false;
}
boolean mup=true;
void mouseReleased(){
mup=true;
}
public int windowcount=0;
void keyPressed(){
if(key=='n') loadNewWindow();
if (key=='r')setup();
if (key=='1') {
rmode = "P3D";
loadNewWindow();
}
if (key=='2') {
rmode = "P2D";
loadNewWindow();
}
if (key=='3') {
rmode = "JAVA2D";
loadNewWindow();
}
}
int offx,offy;
void draw(){
mouse = MouseInfo.getPointerInfo().getLocation();
r = frame.getBounds();
this.frame.setTitle(str(r.x)+ " - " + str(r.y));
if (pmouseX!=mouseX && pmouseY!=mouseY)
{
//this.frame.setTitle(str(mouseX)+ " - " + str(mouseY));
this.frame.setTitle(str(r.x)+ " - " + str(r.y));
}
// else
// {
// this.frame.setTitle(str(mmx)+ " - " + str(mmy));
// }
background(255,0,0);
//if (a!=null)background(a);
mmx= mouseX;
mmy=mouseY;
ellipse(mouseX,mouseY,20,20);
}
void mouseDragged(){
//to do calculate offsets and move from the point where you clicked
frame.setLocation(mouse.x-offx,mouse.y-offy);
}
public int inc=0;
void loadNewWindow()
{
windowcount++;
if (windowcount<maxwindows){
// if(new_window == null){ // omitting this allows multiple windows
new_window[windowcount] = new JFrame();
sketchviewer = new MApplet();
new_window[windowcount].getContentPane().add(sketchviewer, BorderLayout.CENTER);
//
new_window[windowcount].removeNotify();
new_window[windowcount].setUndecorated(true);
new_window[windowcount].addNotify();
new_window[windowcount].setLocation(inc, 100);
//
inc+=255;
new_window[windowcount].setVisible(true);
sketchviewer.init();
// }
new_window[windowcount].setSize(w + frameWidth, h + frameHeight);
}
}
boolean viewhead = false;
public class MApplet extends PApplet{
public PApplet pgx;
public Robot robot;
Frame framex;
void mouseDragged(){
new_window[windowcount].setLocation(mouse.x-_offx[windowcount],mouse.y-_offy[windowcount]);
// this.setLocation(mouseX, 100);
}
//<Insert sketch Code here>
// Shining Particle by harukit
// Created with Processing 68 alpha on September 11 , 2004
// http://www.harukit.com
int pNum =4;
Particle[] p = new Particle[pNum];
float rr,gg,bb,dis;
int gain = 5;
float[] cc = new float[3];
public void setup(){
framex = new Frame();
if (rmode=="P3D") size(w,h,P3D);
if (rmode=="P2D") size(w,h,P2D);
if (rmode=="JAVA2D")size(w,h,JAVA2D);
loadPixels();
noStroke();
background(0);
for(int i=0;i<3;i++){
cc[i]=random(40)+random(40)+random(40)+random(40)+random(40);
}
for(int i=0;i<pNum;i++){
p[i] = new Particle(random(width),random(height),random(0.1,0.3));
}
try
{
robot = new Robot();
}
catch (AWTException e) {
e.printStackTrace();
}
}
public void draw(){
//mouse = MouseInfo.getPointerInfo().getLocation();
rm[windowcount] = new_window[windowcount].getBounds();
this.mouseX=mmx;
this.mouseY=mmy;
// for(int i=0;i<pNum;i++){
// p[i].update();
// }
for(int y=0;y<height;y++){
for(int x=0;x<width;x++){
int pos=y*width+x;
color col = pixels[pos];
rr = col >> 16 & 0xff;
gg = col >> 8 & 0xff;
bb = col & 0xff;
// for(int i=0;i<pNum;i++){
//dis =dist(p[i].xpos,p[i].ypos,x,y)/2;
//dis = dist2(mouseX,mouseY,x,y,24);
dis = dist(mouseX,mouseY,x,y)/2;
rr += cc[0]/dis-gain;
gg += cc[1]/dis-gain;
bb += cc[2]/dis-gain;
// }
pixels[pos]=color(rr,gg,bb);
a.pixels[pos]=color(rr,gg,bb);
}
}
if (rmode=="JAVA2D"){
updatePixels();
}
if (this.keyPressed){
robot.keyPress(18);
robot.keyPress(154);
robot.keyRelease(18); // <<Important
robot.keyRelease(154);// <<Important
if (key=='v')viewhead =!viewhead ;
}
//this.setLocation(mouse.x,mouse.y);
// this.frame.setLocation(mouse.x+55,mouse.y);
}
public void mousePressed(){
// background(0);
Particle[] p = new Particle[pNum];
rm[windowcount] = new_window[windowcount].getBounds();
if(mouseup[windowcount]){
_offx[windowcount]=this.mouseX;
_offy[windowcount]=this.mouseY;
}
mouseup[windowcount]=false;
}
public void mouseReleased(){
for(int i=0;i<3;i++){
cc[i]=random(40)+random(40)+random(40)+random(40)+random(40);
}
// background(0);
for(int i=0;i<pNum;i++){
p[i] = new Particle(random(width),random(height),random(0.1,0.3));
}
mouseup[windowcount]=true;
}
class Particle{
float xpos,ypos,del;
Particle(float x,float y,float d){
xpos=x;
ypos=y;
del = d;
}
void update(){
xpos += (mouseX-xpos)*del;
ypos += (mouseY-ypos)*del;
}
}
}
float fastDist( float x1, float y1, float z1, float x2, float y2, float z2 )
{
float fdist = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);
return fdist;
}
float dist2( float x1, float y1, float x2, float y2,float val)
{
float fdist = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
fdist = fdist / val;
return fdist;
}