Cube cube;
Diamond p;
ArrayList shapeList = new ArrayList();

void setup()
{
size(500,500,P3D);
for(int i=0; i<10; i++)
{
if(i%2==0)
{
cube = new Cube(new PVector(i*100+width,random(0,height),0),new PVector(i*random(2,10),i*random(2,10),i*random(2,10)),color(255,255,255),2);
shapeList.add(cube);
}
else
{
p = new Diamond(new PVector(i*100+width,random(0,height),0),new PVector(i*random(2,10),i*random(2,10),i*random(2,10)),color(0,255,0),2);
shapeList.add(p);
}
// shapeList.add(p);
}
}

void draw()
{
background(255);
// p.display();
directionalLight(225,0,0,1,0.5,-1);
directionalLight(0,0,255,0,-0.5,1);
for(int i=0; i {
Shape _shape = shapeList.get(i);
_shape.display();
_shape.move();
if(_shape.checkBorder())
{
shapeList.remove(i);
// cube = new Cube(new PVector(random(width,width*2),random(0,height),0),new PVector(random(20,100),random(20,100),random(20,100)),color(255,255,0),2);
// shapeList.add(cube);
}
}
}

class Cube extends Shape
{

Cube(PVector _position, PVector _size, color _colour, float _speed)
{
size = _size;
colour = _colour;
position = _position;
speed = _speed;
customShape=createShape();
create();
}

void create()
{
customShape.beginShape(QUAD);
//front
customShape.vertex(-size.x,-size.y,size.z);
customShape.vertex(-size.x,size.y,size.z);
customShape.vertex(size.x,size.y,size.z);
customShape.vertex(size.x,-size.y,size.z);
//right
customShape.vertex(size.x,-size.y,size.z);
customShape.vertex(size.x,-size.y,-size.z);
customShape.vertex(size.x,size.y,-size.z);
customShape.vertex(size.x,size.y,size.z);
//left
customShape.vertex(-size.x,-size.y,-size.z);
customShape.vertex(-size.x,-size.y,size.z);
customShape.vertex(-size.x,size.y,size.z);
customShape.vertex(-size.x,size.y,-size.z);
//top
customShape.vertex(-size.x,-size.y,-size.z);
customShape.vertex(size.x,-size.y,-size.z);
customShape.vertex(size.x,-size.y,size.z);
customShape.vertex(-size.x,-size.y,size.z);
//bottom
customShape.vertex(-size.x,size.y,size.z);
customShape.vertex(size.x,size.y,size.z);
customShape.vertex(size.x,size.y,-size.z);
customShape.vertex(-size.x,size.y,-size.z);
//back
customShape.vertex(-size.x,-size.y,-size.z);
customShape.vertex(-size.x,size.y,-size.z);
customShape.vertex(size.x,size.y,-size.z);
customShape.vertex(size.x,-size.y,-size.z);
customShape.endShape(CLOSE);
}
}

class Diamond extends Shape
{

Diamond(PVector _position, PVector _size, color _colour, float _speed)
{
size = _size;
colour = _colour;
position = _position;
speed = _speed;
customShape=createShape();
create();
}

void create()
{
customShape.beginShape(TRIANGLE);
//Right Front Top
customShape.vertex(0,-size.y,0);
customShape.vertex(0,0,size.z);
customShape.vertex(size.x,0,0);
//Left Front Top
customShape.vertex(0,-size.y,0);
customShape.vertex(0,0,size.z);
customShape.vertex(-size.x,0,0);
//Right Back Top
customShape.vertex(0,-size.y,0);
customShape.vertex(0,0,-size.z);
customShape.vertex(size.x,0,0);
//Left Back Top
customShape.vertex(0,-size.y,0);
customShape.vertex(0,0,-size.z);
customShape.vertex(-size.x,0,0);

//Right Front Bottom
customShape.vertex(0,size.y,0);
customShape.vertex(0,0,size.z);
customShape.vertex(size.x,0,0);
//Left Front Bottom
customShape.vertex(0,size.y,0);
customShape.vertex(0,0,size.z);
customShape.vertex(-size.x,0,0);
//Right Back Bottom
customShape.vertex(0,size.y,0);
customShape.vertex(0,0,-size.z);
customShape.vertex(size.x,0,0);
//Left Back Bottom
customShape.vertex(0,size.y,0);
customShape.vertex(0,0,-size.z);
customShape.vertex(-size.x,0,0);
customShape.endShape();
}
}

class Shape
{
PVector position, size;
color colour;
PShape customShape;
float speed,velocity,i;

void display()
{
pushMatrix();
translate(position.x,position.y,position.z);
// rotateX(HALF_PI/2);
rotateY(i+=0.02);
fill(colour);
shape(customShape,0,0);
popMatrix();
}

void move()
{
position.x-=speed;
}

boolean checkBorder()
{
if(position.x<0)
{
return true;
}
return false;
}
}