Jump to content

mouse trail


Recommended Posts

Posted
private final LinkedList<MousePathPoint> mousePath = new LinkedList<>();
public void onPaint(final Graphics2D g) {
    while (!mousePath.isEmpty() && mousePath.peek().isUp())
        mousePath.remove();

    Point clientCursor = getMouse().getPosition();
    MousePathPoint mpp = new MousePathPoint(clientCursor.x, clientCursor.y,
            300); //1000 = lasting time/MS
    if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
        mousePath.add(mpp);
    MousePathPoint lastPoint = null;
    for (MousePathPoint a : mousePath) {
        if (lastPoint != null) {
            g.setColor(Color.WHITE);
            g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
        }
        lastPoint = a;
    }
}
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...