davidgutierrezrubio / jmathanim

A Java library to make mathematical animations
https://davidgutierrezrubio.github.io/jmathanim/
20 stars 2 forks source link

How to animate a dynamic shape? #16

Closed rensx closed 3 months ago

rensx commented 3 months ago

Below example animate a triangle with two fixed point(P1,P2) and a dynamic Point(P) located on a circle path, is there a simple way to animate a triangle with the dynamic Point(P) locate on a more general shape such as polygon?

import com.jmathanim.jmathanim.; import com.jmathanim.mathobjects.;

public class dynamicTriangle extends Scene2D { public static void main(String[] args) { System.setProperty("prism.forceGPU", "true"); JMathAnimScene scene = new dynamicTriangle(); scene.execute(); } @Override public void setupSketch() { config.parseFile("#preview.xml"); config.parseFile("#darkCGBlue.xml"); //config.setCreateMovie(true); }

@Override
public void runSketch() {

    Shape c = Shape.circle();
    Point P = c.getPointAt(0.2).visible(false).layer(1);
    Point P1 = c.getPointAt(0).layer(1);
    Point P2 = c.getPointAt(0.5).layer(1);

    //UnitPoint P3 = new UnitPoint(P);

    Shape triangle = Shape.polygon(P, P1.copy(), P2.copy()).style("solidblue");
    add(triangle, P1, P, P2, c);

    play.rotate(5, Point.at(0, 0), 360 * DEGREES, P);

    waitSeconds(5);

}

}

davidgutierrezrubio commented 3 months ago

You can use the MoveAlongPath animation:

Shape movePath = Shape.regularInscribedPolygon(5);
playAnimation(
        MoveAlongPath.make(5, movePath, P, Anchor.Type.CENTER, false, true)
);

In the manual (chapter "Animating Objects") you can find information about this animation.

rensx commented 3 months ago

Great! thank you very much for your kindly help.

David Gutiérrez @.***> 于2024年7月25日周四 15:36写道:

You can use the MoveAlongPath animation:

Shape movePath = Shape.regularInscribedPolygon(5);playAnimation( MoveAlongPath.make(5, movePath, P, Anchor.Type.CENTER, false, true) );

In the manual (chapter "Animating Objects") you can find information about this animation.

— Reply to this email directly, view it on GitHub https://github.com/davidgutierrezrubio/jmathanim/issues/16#issuecomment-2249656810, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALBRNZL7YSQMQHP4JGM4SU3ZOCTGDAVCNFSM6AAAAABLNT3WYKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBZGY2TMOBRGA . You are receiving this because you authored the thread.Message ID: @.***>