Search code examples
javaprocessingwindows-11

Processing stalls when running a program


I was trying to write a program to simulate the Earth-Moon system, and it was working fine for a while, but out of the blue, Processing started stalling. Every time I hit "Run," there's an unusual delay of about 10s, and then my Windows 11 taskbar informs me that the Sketch Window has been opened, but I can't access it, and nothing displays. Other programs run fine, including ones using P3D.

Here is my code:

PShape earth,moon;
void setup()
{
  size(6000,6000,P3D);
  PImage img = loadImage("earth.jpg");
  PImage img2= loadImage("moon.jpg");
  noStroke();
  earth=createShape(SPHERE,212.6); //radius of earth is 6378, sized down to by a factor of 30
  earth.setTexture(img);
  moon=createShape(SPHERE,57.9); //radius of moon is 1737, sized down by a factor of 30
  moon.setTexture(img2);
}
float z = -300; //transversal along z-axis
float angle; // angle of rotation wrt center
float rotAngMoon=6.68; //angle of moon's rotation
float rotAngEarth=23.5; //angle of earth's rotation
float inclination=5.14; //angle between moon's orbital plane and earth's orbital plane
float orbitDistEarth=155.6666; //distance from earth's center to barycenter (4670, sized down by a factor of 30)
float orbitDistMoon=1298.9; //distance from moon's center to barycenter (389670, sized down by a factor of 300)
void draw()
{
  background(0);
  translate(width/2,height/2,2*z);
  
  pushMatrix(); // Earth
  rotateY(27.321661*angle); //Earth spins faster
  translate(orbitDistEarth,0,0); //go to the point where earth would be
  rotateZ(rotAngEarth*PI/180); //rotate the earth
  shape(earth);
  popMatrix();
  
  pushMatrix(); //moon
  rotateY(angle);
  translate(-orbitDistMoon,(tan(inclination*PI/180))*orbitDistMoon*sin(angle*PI/180),0); //go to the point where the moon would be, additionally, the moon lies on a plane of inclination

//the line above might be incorrect with respect to the simulation, but I was debugging it when the stalls started occurring. There doesn't seem to be any error with it as far as I can see, so it should run fine

  rotateZ(rotAngMoon*PI/180); //rotate the moon 
  shape(moon);
  popMatrix();
  
  
  angle+=0.01;
  
}

Any ideas on what could be going wrong?


Solution

  • Your system has stalled because of the enormous window size of 6000 wide and 6000 high. That's far more than you can see on today's screen (in the year 2021). Reduce the size of the window:

    size(6000, 6000, P3D);

    size(1920, 1280, P3D);