-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplashScreen.java
More file actions
190 lines (157 loc) · 8.75 KB
/
SplashScreen.java
File metadata and controls
190 lines (157 loc) · 8.75 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* Justin Pu
Spinnin' Tiles
January 4, 2015
Ms. Dyke
Description:
This thread creates a simultaneous animation in the splash screen.
Variable Dictionary
_______________________________________________________________________________________________________________________
| Type | Name | Description |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| Console | c | The reference to the output Console. Has a text size of 30 by 100. Also allows access to |
| | | the built-in methods. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| int | ang | The angle of orientation of the 3D drawing. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| int | x | Holds the start x coordinate of the drawing. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| String | y | Holds the start y coordinate of the drawing. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| Color | bgCol | Holds the background colour so that redrawing is smooth. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| boolean | draw | Holds the boolean to continue drawing or not. |
|___________|___________|_______________________________________________________________________________________________|
*/
import hsa.Console;
import java.awt.*;
import java.lang.*;
public class SplashScreen extends Thread
{
private Console c;
private int ang;
private int x, y;
private int prevX, prevY;
private Color bgCol;
private boolean draw;
private static final int DELAY = 40;
/* This method converts a length to how long it looks like when rotated a certain degree of angles.
Local Variable Dictionary
_______________________________________________________________________________________________________________________
| Type | Name | Description |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| int | num | The value of the length to be drawn 3D. |
|___________|___________|_______________________________________________________________________________________________|
*/
private int to2D (int num)
{
return (int) (num * Math.cos (Math.toRadians (ang)));
}
/* This method allows another program to set the x value (the x of the center of the rotating tile).
Local Variable Dictionary
_______________________________________________________________________________________________________________________
| Type | Name | Description |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| int | newX | The new value of x to be assigned. |
|___________|___________|_______________________________________________________________________________________________|
*/
public void setX (int newX)
{
x = newX;
}
/* This method allows another program to set the y value (the y of the center of the rotating tile).
Local Variable Dictionary
_______________________________________________________________________________________________________________________
| Type | Name | Description |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| int | newY | The new value of y to be assigned. |
|___________|___________|_______________________________________________________________________________________________|
*/
public void setY (int newY)
{
y = newY;
}
// This method stops the animation and ends the Thread.
public void stopDrawing ()
{
draw = false;
}
/* This constructor creates the new Thread and assigns the output console, the initial x coordinate, the initial y coordinate and the background colour.
Local Variable Dictionary
_______________________________________________________________________________________________________________________
| Type | Name | Description |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| Console | con | The output console passed to the SplashScreen Thread so that they are on the same window. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| int | iniX | The starting x center coordinate of the spinning tile. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| int | iniY | The starting y center coordinate of the spinning tile. |
|-----------|-----------|-----------------------------------------------------------------------------------------------|
| Color | col | The background colour so that erasing blends in. |
|___________|___________|_______________________________________________________________________________________________|
*/
public SplashScreen (Console con, int iniX, int iniY, Color col)
{
c = con;
x = iniX;
y = iniY;
draw = true;
bgCol = col;
}
/* This method is the Thread that rotates the tile constantly.
The while loop runs as long as the draw is true.
The for loop rotates the tile based on the angle.
The try block delays the program by a set amount of time.
An InterruptedException is caught in case the program couldn't delay the program.
Local Variable Dictionary
___________________________________________________________________________________________________________________________________
| Type | Name | Description |
|-----------------------|-----------|-----------------------------------------------------------------------------------------------|
| InterruptedException | e | Catches an InterruptedException in case the delay couldn't have been executed. |
|_______________________|___________|_______________________________________________________________________________________________|
*/
public void run ()
{
while (draw)
{
for (ang = 0 ; ang < 360 && draw ; ang += 5)
{
int[] xc = {x + to2D (45), x + to2D (50), x + to2D (50), x + to2D (45), x - to2D (25), x - to2D (30), x - to2D (30), x - to2D (25) };
int[] yc = {y + 20, y + 25, y + 135, y + 140, y + 140, y + 135, y + 25, y + 20};
c.setColour (Color.black);
c.fillPolygon (xc, yc, 8);
xc = new int[]
{
x + to2D (25), x + to2D (30), x + to2D (30), x + to2D (25), x - to2D (45), x - to2D (50), x - to2D (50), x - to2D (45)
}
;
yc = new int[]
{
y, y + 5, y + 115, y + 120, y + 120, y + 115, y + 5, y
}
;
c.setColour (Color.lightGray);
c.fillPolygon (xc, yc, 8);
c.setColour (Color.black);
c.drawPolygon (xc, yc, 8);
c.setColour (Color.red);
if (ang < 90 || ang > 270)
{
c.fillMapleLeaf (x - to2D (40), y + 30, to2D (60), 60);
}
prevX = x;
prevY = y;
// Delay
try
{
sleep (DELAY);
}
catch (InterruptedException e)
{
}
// Erase
c.setColour (bgCol);
c.fillRect (prevX - Math.abs (to2D (50)) - 5, prevY - 5, Math.abs (to2D (100)) + 10, 150);
}
}
}
}