A Java Swing project that simulates a dynamic particle field where particles move, bounce off walls, and connect with nearby particles using color-blended lines. Inspired by Diogo Correia's website's background;
This project was built as a practice exercise to explore:
- OOP in Java
- Swing graphics and rendering
- Animation using javax.swing.Timer
- Color manipulation using HSB (Hue, Saturation, Brightness)
- 100 animated particles
- Directional movement using trigonometry
- Border collision detection with color changes
- Dynamic line connections betweens nearby particles
Each Particle object contains:
x,y- Positionr- Radiusdir- Direction (degrees)hue- Color value (HSB)
Movement is calculated using basic trigonometry.
double rad = Math.toRadians(dir);
x += Math.sin(rad) * step;
y -= Math.cos(rad) * step;How the blending works:
- Calculate the difference between two hues.
float dif = hue2 - hue;- Finding the shortest path around the colour wheel to ensure proper colour blending.
dif = ((dif + 180f) % 360f);
if (dif < 0) dif += 360f;
dif -= 180f;- Mixing the hues by moving halfway toward the second particle's hue.
float mixedHue = (hue + dif / 2f + 360f) % 360f;