Is there big differences between Repl.it and the Processing IDE?

For class, I use the website repl.it and code fully in processing on it. It’s not meant to use processing but my professor uses some sort of plugin that makes it work. Anyways, for any complex projects, usually, one with multiple classes, code that works perfectly on repl.it will either not work at all or the output will be completely bugged. An example is a ball project I am doing with 100 balls called in using an array that all move. On repl.it, it works. On the IDE, all the balls are stuck in the top left corner using the exact same code. I can reply to anyone with the code but it is over 100 lines.

1 Like

The code:

class ball
{ 
  float x;
  float y;
  float r1 = random(0,255);
  float b1 = random(0,255);
  float g1 = random(0,255);
  float d = random(10,30);
  float xSpeed = random(-4,4);
  float ySpeed = random(-4,4);

  ball(float x,float y)
  {
    
  }
  void render()
  {
    fill(r1,g1,b1);
    ellipse(x,y,d,d);
  }
  void move()
  {
    x = x + xSpeed;
    y = y + ySpeed;
  }
  void bounce()
  {
    if(x > width - d/2)
    {
      xSpeed = -xSpeed;
    }

    if(x < 0 + d/2)
    {
      xSpeed = -xSpeed;
    }

    if(y > height - d/2)
    {
      ySpeed = -ySpeed;
    }

    if(y < 0 + d/2)
    {
      ySpeed = -ySpeed;
    }
  }
}

ball[] balls = new ball[100];
float x;
float y;
void setup()
{
  size(600, 400);
  x = random(0,width);
  y = random(0,height);
  for(int i=0; i < 100; i++)
  {
    balls[i] = new ball(x,y);
  }
}

void draw()
{
  background(50);
  for(int i = 0; i < 100; i++)
  {
    balls[i].render();
    balls[i].move();
    balls[i].bounce();
    
  }
}

Hey,

you’re passing to your ball constructor x and y values, but you don’t use them to set the value of ball.x and ball.y, so you just have to do it, and it will works perfectly :

// inside your ball class
ball(float _x,float _y)
  {
    x = _x;
    y = _y;
  }

I don’t know why it works without it on repl.it, but it should not actually :slight_smile:

2 Likes

Also you should be using an uppercase name for a class because the in the line above, can you really tell where’s the class?

It’s more readable like this :wink: :

class Ball {
}

Ball[] balls = new Ball[100];

See : Code Conventions for the Java Programming Language: 9. Naming Conventions

Naming conventions can be annoying when you start programming but it’s really worth it !!

2 Likes

@spamelim Do you happen to know if your professor has your class using Processing or Processing.js on repl.it? Do your projects come with an index.html file?

1 Like

I think processing.js. They come with a main.java and index.html, to add a new file for a class I have to edit the HTML as well so it will work.

2 Likes