Helping assignments

Hi, I am trying to draw a planet that keeps spinning with a little interaction with the users. I couldn’t run the data in processing and couldn’t find the error below. The users click on the planet, it will interact with some small balls. However, while the users could restart the interaction again by taping on the keyboard.

//Arrays
ArrayList<planet> planetsa = new ArrayList<planet>();
ArrayList<planet> planetsb = new ArrayList<planet>();
ArrayList<planet> planetsc = new ArrayList<planet>();

void setup(){
size(1280,720);
planets1 = new planets();
planets1.a =0.003;
planets1.d=40;
planets.add(planets1);
}

inti i;
float x = 500;
float y=100;
float dSun =250;

void draw(){
  translate(width/2,height/2);
  rotate(radians(-25));
  background(233);
  planetsb = new ArrayList<planet>();
  planetsc = new ArrayList<planet>();
  for(Planet planet :planets){
    planet.setCoords(millis(),x,y);
    if(planet.overLapping()){
      planetsb.add(planet);
    } else{
      planetsc.add(planet);
      
      //functions
      void mousePressed(){
        planets1 = new planets();
       planets1.a =0.003,0.006;
       planets1.d=40,60;
       planets.add(planet1);
}
void keyPressed(){
  planets =new ArrayList<Planet>();
}

Hello,

Please go edit and format your post:
https://discourse.processing.org/faq#format-your-code

Resources < Click here to expand !

I encourage you to review the resources available here:

:)

1 Like

As you have written it, the code seems very sloppy. I commented some of the more glaring errors but maybe just in general rethink and format your code to then ask a specific question :slight_smile:

//Arrays
ArrayList planetsa = new ArrayList();
ArrayList planetsb = new ArrayList();
ArrayList planetsc = new ArrayList();

void setup() {
  size(1280, 720);
  planets1 = new planets(); // whats the class planets? You did not write one
  planets1.a =0.003;        // you define planetsa,b,c but use planets1,2,3!
  planets1.d=40;
  planets.add(planets1);    // again, where is planets defined?
}

inti i; // int, not inti
float x = 500;
float y=100;
float dSun =250;

void draw() {
  translate(width/2, height/2);
  rotate(radians(-25));
  background(233);
  planetsb = new ArrayList();  // you already initlaiized that. Why do it again everytime in draw() ?
  planetsc = new ArrayList();
  for (Planet planet : planets) {
    planet.setCoords(millis(), x, y);    
    if (planet.overLapping()) {
      planetsb.add(planet);
    } else {
      planetsc.add(planet);
      }
  }
}

  //functions
  void mousePressed() {
    planets1 = new planets();
    planets1.a =0.003, 0.006;
    planets1.d=40, 60;
    planets.add(planet1);
  }
  void keyPressed() {
    planets =new ArrayList();
  }

1 Like