Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CircleAnimation;
- import javafx.animation.AnimationTimer;
- import javafx.application.Application;
- import javafx.geometry.Point2D;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.canvas.Canvas;
- import javafx.scene.canvas.GraphicsContext;
- import javafx.scene.layout.Pane;
- import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- import static java.lang.Math.*;
- /**
- *
- * @author Aamir khan
- *
- */
- public class Main extends Application {
- private GraphicsContext g;
- double t = 0.0;
- private Stage stage;
- @Override
- public void start(Stage stage) throws Exception {
- this.stage = stage;
- stage.setTitle("Parametric Equation");
- this.stage.setScene(new Scene(createContent()));
- this.stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- private Parent createContent() {
- Pane root = new Pane();
- root.setPrefSize(800, 600);
- Canvas canvas = new Canvas(800, 600);
- g = canvas.getGraphicsContext2D();
- AnimationTimer timer;
- timer = new AnimationTimer() {
- @Override
- public void handle(long now) {
- t += 0.017;
- draw();
- }
- private void draw() {
- Point2D p = curve();
- g.setStroke(Color.BLACK);
- double strokeSize = 1;
- double newX = 400 + p.getX();
- double newY = 300 + p.getY();
- g.strokeOval(newX, newY, strokeSize, strokeSize);
- }
- private Point2D curve() {
- return new Point2D(cos(t), sin(t)).multiply(50);
- }
- };
- timer.start();
- root.getChildren().add(canvas);
- return root;
- }
- }
Add Comment
Please, Sign In to add comment