-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimation3.java
165 lines (110 loc) · 4.19 KB
/
Animation3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.example.ColorSwitchGame;
import java.util.*;
import java.io.File;
import java.io.FileInputStream;
import javafx.animation.Animation;
import javafx.animation.PathTransition;
import javafx.animation.RotateTransition;
import javafx.animation.ScaleTransition;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Animation3 extends Application {
private static final ArrayList<Group> obs = new ArrayList<>();
public Animation3() {
obs.add(InsideLine());
obs.add(OuterLine());
}
@Override
public void start(Stage primaryStage) throws Exception{
Group root = new Group();
root.getChildren().addAll(obs);
// InsideLine();
// OuterLine();
Thread animationThread = new Thread(() -> {
int updateInTime = 20; // Millisecond
double rotateSpeed = 0.05; // Degree Per Mili Sec
while (true) {
try {
// root.setRotate(root.getRotate() + rotateSpeed*updateInTime);
obs.get(0).setRotate(obs.get(0).getRotate() + rotateSpeed*updateInTime);
obs.get(1).setRotate(obs.get(1).getRotate() - rotateSpeed*updateInTime);
Thread.sleep(updateInTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
animationThread.start();
primaryStage.setTitle("Animation");
Scene firstScene = new Scene(root, 800, 800);
firstScene.setFill(Color.rgb(23,17,17));
primaryStage.setScene(firstScene);
primaryStage.show();
}
public Group OuterLine() {
Group root = new Group();
Line line2 = new Line(600, 200, 600, 600);
line2.setStroke(Color.WHITE);
line2.setStrokeWidth(15);
line2.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line2);
Line line1 = new Line(200, 600, 600, 600);
line1.setStroke(Color.BLUE);
line1.setStrokeWidth(15);
line1.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line1);
Line line3 = new Line(200, 200, 200, 600);
line3.setStroke(Color.RED);
line3.setStrokeWidth(15);
line3.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line3);
Line line4 = new Line(200, 200, 600, 200);
line4.setStroke(Color.YELLOW);
line4.setStrokeWidth(15);
line4.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line4);
return root;
}
public Group InsideLine() {
Group root = new Group();
Line line5 = new Line(220, 220, 580, 220);
line5.setStroke(Color.RED);
line5.setStrokeWidth(15);
line5.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line5);
Line line6 = new Line(220, 220, 220, 580);
line6.setStroke(Color.BLUE);
line6.setStrokeWidth(15);
line6.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line6);
Line line7 = new Line(580, 220, 580, 580);
line7.setStroke(Color.YELLOW);
line7.setStrokeWidth(15);
line7.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line7);
Line line8 = new Line(220, 580, 580, 580);
line8.setStroke(Color.WHITE);
line8.setStrokeWidth(15);
line8.setFill(Color.TRANSPARENT);
root.getChildren().addAll(line8);
return root;
}
public static void main(String[] args) {
launch(args);
}
}