How to draw a point that navigates a particular shape

edited December 2015 in How To...

Is there a smart way to have a dot (point, ellipse) move in the path defined by a random shape/trajectory? I want the shape to visible, and the dot to move 1px at a time.

Tagged:

Answers

  • You need to be more specific about the shape. Is it a bitmap image or a PShape object or something else?

  • edited December 2015

    I want to draw the shape myself (PShape or even with rect/ellipse). This is pretty straightforward with a circle, e.g.:

    dotX = circleX + cos(radians(angle)) * radius; dotY = circleY + sin(radians(angle)) * radius;

    But I wonder if there's a simple way of achieving the same if the shape is different, e.g., a rotated square with rounded corners.

  • You will probably have better luck with PShape because I think it can be used to store paths.

    Someone more familiar with PShape could advise you better.

  • edited December 2015 Answer ✓

    you probably loop all vertexes / vertices in the PShape and use lerp() for the transition

    to avoid that the speed is higher for longer passages, set amt (see reference on lerp) depending on dist() of the 2 vertices

  • edited April 2016

    Hello guys! I m working on the same stuff. I created the shapes with PShape, thus I generated an ArrayList<PVector> with lerp() that is the list of the coordinates that my dot has to follow at each time.
    It works, but every time the dot has to follow a new paths or repeat the old one, it goes along it faster and faster.
    Is it possibile that is related to the graphic acceleration?

  • Solved! It was just a mistake on my code, sorry.

Sign In or Register to comment.