This is really cool if you want it for your paint.
LinkedList<MousePathPoint> mousePath = new LinkedList<MousePathPoint>();
public class MousePathPoint extends Point {
private long finishTime;
private double lastingTime;
public MousePathPoint(int x, int y, int lastingTime) {
super(x, y);
this.lastingTime = lastingTime;
finishTime = System.currentTimeMillis() + lastingTime;
}
public boolean isUp() {
return System.currentTimeMillis() > finishTime;
}
}
public void nextRGB() {
if ( r == 255 && g < 255 && b == 0 )
{
g++;
}
if ( g == 255 && r > 0 && b == 0 )
{
r--;
}
if ( g == 255 && b < 255 && r == 0 )
{
b++;
}
if ( b == 255 && g > 0 && r == 0 )
{
g--;
}
if ( b == 255 && r < 255 && g == 0 )
{
r++;
}
if ( r == 255 && b > 0 && g == 0 )
{
b--;
}
}
public Color nextColor() {
nextRGB();
return makeColor();
}
public Color makeColor()
{
return new Color(r, g, b);
}
Example:
@Override
public void onPaint(Graphics2D g) {
while (!mousePath.isEmpty() && mousePath.peek().isUp())
mousePath.remove();
Point clientCursor = mouse.getPosition();
MousePathPoint mpp = new MousePathPoint(clientCursor.x, clientCursor.y, 500);
if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
mousePath.add(mpp);
MousePathPoint lastPoint = null;
for (MousePathPoint a : mousePath) {
if (lastPoint != null) {
g.setColor(nextColor());
g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
}
lastPoint = a;
}
}