Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Particle{
- int x;
- int y;
- int xv;
- int yv;
- int angle;
- int velocity = (int)(Math.random()*5);
- int energy;
- boolean dead = false;
- public void update(){
- xv = (int)(velocity * (Math.sin(angle)));
- yv = (int)(velocity * (Math.cos(angle)));
- x += xv;
- y += yv;
- energy -= 10;
- if(energy <= 0)
- dead = true;
- }
- public void draw(Graphics2D g){
- Ellipse2D particle = new Ellipse2D.Float(x,y,5,5);
- g.setColor(Color.black);
- g.fill(particle);
- }
- }
- public class ParticleSystem{
- Particle[] particle = new Particle[1500];//Particle array
- int x;//X coordinate of particle origin
- int y;//Y coordinate of particle origin
- ParticleSystem(int mousePx, int mousePy){
- x = mousePx;
- y = mousePy;
- }
- public void init(){
- for(int i = 0; i <= particle.length - 1; i++){
- particle[i] = new Particle();
- particle[i].x = x;
- particle[i].y = y;
- particle[i].energy = 255;
- particle[i].angle = (int)(Math.toRadians(Math.random()*i));
- }
- }
- public void update(){
- for(int i = 0; i <= particle.length - 1; i++){
- particle[i].update();
- }
- }
- public void draw(Graphics2D g){
- for (int i = 0; i <= particle.length - 1; i++){
- particle[i].draw(g);
- }
- }
- }
Add Comment
Please, Sign In to add comment