forked from kdurand/space-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.java
42 lines (34 loc) · 929 Bytes
/
Particle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.awt.*;
public class Particle {
double x;
double y;
int radius;
double angle;
double speed;
double dx;
double dy;
Color innerColor;
Color outerColor;
Explosion parent;
public Particle(Explosion parent,int radius,double speed) {
this.parent = parent;
this.radius = radius;
this.speed = speed;
innerColor = new Color(1f,1f,0f,.5f);
outerColor = new Color(1f,0f,0f,.2f);
}
public void update() {
if(x<parent.bounds.x || x>parent.bounds.width || y<parent.bounds.y || y>parent.bounds.height) {
parent.initParticle(this);
}
y += dy;
x += dx;
}
public void draw(Graphics2D g) {
float[] grads = {.0f,.4f,1f};
Color[] colors = {innerColor,innerColor,outerColor};
RadialGradientPaint paint = new RadialGradientPaint((float)x+radius/2,(float)y+radius/2,(float)radius/2,grads,colors);
g.setPaint(paint);
g.fillOval((int)x,(int)y,(int)radius,(int)radius);
}
}