Ok so i started working on a new version. Made is so it recycles the array so it never has a limit.
Here is the new code
Code:int num = 500;
float[][] fire = new float [num][12];
void setup(){
size(400,400);
rectMode(CENTER);
smooth();
noStroke();
frameRate(60);
}
void draw(){
background(200);
if(mousePressed==true){
create_fire();
}
update_fire();
draw_fire();
}
void update_fire(){
for(int i=num-1; i>0; i--){
for(int fireprop=0;fireprop<11;fireprop++){
fire[i][fireprop]=fire[i-1][fireprop];
}
}
for(int flame=0 ; flame<num ; flame++){
if(fire[flame][0]==1){
fire[flame][1]=fire[flame][1]+fire[flame][5]*cos(fire[flame][3]);
fire[flame][2]=fire[flame][2]+fire[flame][5]*sin(fire[flame][3]);
}
fire[flame][7]+=1;
if(fire[flame][7]>fire[flame][6]){
fire[flame][0]=0;
}
}
}
void draw_fire(){
for(int flame=0 ; flame<num ; flame++){
if(fire[flame][0]==1){
fill(fire[flame][9],fire[flame][10],0,40);
pushMatrix();
translate(fire[flame][1],fire[flame][2]);
rotate(fire[flame][8]);
rect(0,0,fire[flame][4],fire[flame][4]);
popMatrix();
}
}
}
void create_fire(){
for(int flame=0;flame<200;flame++){
fire[flame][0]=1;
fire[flame][1]=mouseX;
fire[flame][2]=mouseY;
fire[flame][3]=random(0,PI*2);//angle
fire[flame][4]=random(5,15);//size
fire[flame][5]=random(1,2);//speed
fire[flame][6]=random(5,20);//maxlife
fire[flame][7]=0;//currentlife
fire[flame][8]=random(0,TWO_PI);
fire[flame][9]=random(200,255);//red
fire[flame][10]=random(50,150);//green
}
}
But now the problem is that alot of the flames will stay in the middle until you let go of the mouse. Does anyone have any idea why? Its probably something simple that im missing. And @PhiLho, thanks for the feedback to use classes, ive alwas wanted to get into them just never had the incentive, but i guess now i have to
Thanks everyone for your feedback =)
EDIT:
Sorry forgot to thanks Giles for the awesome tutorials,
Thanks man i appreciate it they were really useful