out of memory error
in
Programming Questions
•
2 years ago
i'm trying to do some tutorial and i did everything but when i try to run the sketch it gives me this error
//declare class
ArrayList ballCollection;
void setup() {
size(600, 600);
smooth();
//initialize class
ballCollection = new ArrayList();
for (int i = 0; 0 < 100; i++){
Ball myBall = new Ball(random(0,width), random(0, 200));
ballCollection.add(myBall);
}
}
void draw() {
background(0);
//call functionality of class
for (int i = 0; 0 < 100; i++){
Ball myBall = (Ball)ballCollection.get(i);
myBall.run();
}
}
class Ball {
//global variables
float x = 0;
float y = 0;
float speedX = 4;
float speedY = 0.5;
//constructor
Ball(float _x, float _y) {
x = _x;
y = _y;
}
//functions
void run() {
display();
move();
bounce();
gravity();
}
void gravity() {
speedY += 0.2;
}
void bounce() {
if (x > width) {
speedX = speedX * -1;
}
if (x < 0) {
speedX = speedX * -1;
}
if (y > height) {
speedY = speedY * -1;
}
if (y < 0) {
speedY = speedY * -1;
}
}
void move() {
x = x + speedX;
y = y + speedY;
}
void display() {
ellipse(x, y, 20, 20);
}
}
1