Fake Invisible Screen

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.Toolkit;
Robot robot;
PImage img;
Planets[]p;
import java.awt.MouseInfo;
import java.awt.Point;
Screen s;


void setup() {
  makeImage();
  fullScreen();
  s=new Screen();
  p=new Planets[20];
  for(int i=0;i<p.length;i++){
    p[i]=new Planets(i);
    
  }
  // screen location: 400,100
  // screen size: 500,500
  
}

void draw(){
  //background(0);
  //makeImage();
  image(img,0,0);
  someCode();
  s.screen();
  println(s.gmX()-s.mX,s.gmY()-s.mY);
  //makeImage();
}
void someCode(){
  //  put your code here
  textSize(27);
  text(frameCount,100,100);
  for(int i=0;i<p.length;i++){
    p[i].planets();
  }
  
}
void keyPressed(){
  s.kP();
}
void mousePressed(){
  s.mP();
}
void mouseReleased(){
  s.mR();
}
class Planets{
  float x,y,theta,thetaInc,rad;
  
Planets(int i){
  if(i!=0){
    rad=p[i-1].rad+10;
    thetaInc=p[i-1].thetaInc+.01;
  }
  println(thetaInc);
  //x=250;y=250;
 
  
}  
  
void planets(){  
  orbit();
  display();
}  
  
void orbit(){
  x=cos(theta)*rad+250;
  y=sin(theta)*rad+250;
  theta+=thetaInc;
}
  
void display(){
  noFill();
  stroke(0xffff00ff);
  ellipse(x,y,10,10);
}
  
  
}//class planets
class Screen{
  int mX,mY,fsX,fsY,nsX,nsY;
  int exitColor=0xffc75050;//,exitBright=0xffe04343;
  int sizeColor=0xff979797;//sizeBright=0xff3665b3;
  int minColor=0xff979797;
  boolean pressed,size;
  
  Screen(){
    fsX=width;fsY=width;
    nsX=500;nsY=500;
    surface.setResizable(true);
    setNormScreen();
    background(0);
  }
  
  void screen(){
    if(pressed||mouseY<25){header();}
    
  }
  
  void header(){
    drawHeader();
    if(pressed){moveScreen();}
    //  exit
    if(mouseX>width-44){exitColor=0xffe04343;}
    else{exitColor=0xffc75050;}
    //  size;
    if(mouseX>width-70&mouseX<width-44){sizeColor=0xff3665b3;}
    else{sizeColor=0xff979797;}
    //  minimize
    if(mouseX>width-85&mouseX<width-70){minColor=0xff3665b3;}
    else{minColor=0xff979797;}
  }// header()
  
  void moveScreen(){
    //  println("mouseMoved");
    getSurface().setLocation(gmX()-mX,gmY()-mY);
    makeImage();
  }
  void setFullScreen(){
    getSurface().setLocation(0,0);
    surface.setSize(fsX,fsY);
  }
  void setNormScreen(){
    getSurface().setLocation(0,0);
    surface.setSize(nsX,nsY);
  }
  void hideScreen(){
    getSurface().setLocation(displayWidth,0);
    surface.setSize(10,10);
  }
  int gmX(){//  global mouseX
    Point mouse;
    mouse=MouseInfo.getPointerInfo().getLocation();
    return mouse.x;
  }//  gmX()
  int gmY(){//  global mouseX
    Point mouse;
    mouse=MouseInfo.getPointerInfo().getLocation();
    return mouse.y;
  }//  gmY()
  
  void drawHeader(){
    //  bar
    fill(0xff9c9c9c);noStroke();
    rect(0,0,width,25);
    
  //  //minimize
    fill(minColor);noStroke();
    rect(width-98,0,width-70,17);
    //  dash line
    stroke(0xff3c3c3c);fill(0xff3c3c3c);
    rect(width-88,7,7,1);
    
    //  size
    fill(sizeColor);noStroke();
    rect(width-70,0,width-45,17);
    //  inner rect
    stroke(0xff3c3c3c);noFill();
    rect(width-62,5,9,6);
      
    fill(exitColor);//  dull
    noStroke();
    rect(width-44,0,width,17);
    strokeWeight(2);
    stroke(0xffffffff);fill(0xffffffff);// slashes
    line(width-25,5,width-18,11);// backslash
    line(width-18,5,width-25,11);// 
    strokeWeight(1);
  
  }//  drawHeader() 
  
  void mP(){//  mousePressed
  //println("mousePressed");
    if((mouseY<25)&(mouseX<width-88)){
      mX=mouseX;mY=mouseY;pressed=true;
    }
    if(exitColor==0xffe04343){exit();}
    if(sizeColor==0xff3665b3){
      size=!size;
      if(size){setFullScreen();}else{setNormScreen();}
    }
    if(minColor==0xff3665b3){
      hideScreen();
    }
  }
  void kP(){
    pressed=false;
    if(!size){setNormScreen();}
    //set mouseY greater than header height so header doesn't trigger
    else{mouseY=100;setFullScreen();}
  }
  void mR(){//  mouseReleased
    pressed=false;
  }
  
  
}//  class Screen 
void makeImage(){
  try{
    //Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    //println(size);
    robot=new Robot();
  } 
  catch(AWTException e){e.printStackTrace();}
 
  img=new PImage(robot.createScreenCapture(
          //            x,y,width,height
          new Rectangle(0,0,500,500)));
}
2 Likes

Please, edit your previous post, select your code and click on the </> icon in order to format your code. If you don’t do that, your code will not be displayed properly and some symbols are processed as part of the markdown interpretation.
Finally, please add a description about this code. Are you having an issue or is it a demonstration? What does it do? Share your enthusiasm in your description and it is very likely you will get feedback from the community.

Kf

Are there instructions for posting/editing somewhere ?

Please see faq

https://discourse.processing.org/faq#format-your-code

1 Like

@HoboGreed – thanks for sharing this. What does this code do?

Makes it appear an animation is drawn on the desktop

Interesting demo. Thank you for formatting your code and for sharing it.

Kf

1 Like

Actually it was @jeremydouglass who edited & formatted his code. :wink:

1 Like