-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelix.java
More file actions
174 lines (130 loc) · 3.66 KB
/
Helix.java
File metadata and controls
174 lines (130 loc) · 3.66 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
import java.awt.*;
import java.util.Scanner;
import java.util.Random;
public class Helix{
public static Color getColor() {
Random random = new Random();
int colorNum = random.nextInt(9);
switch (colorNum) {
case 0: return Color.GREEN;
case 1: return Color.GRAY;
case 2: return Color.YELLOW;
case 3: return Color.RED;
case 4: return Color.ORANGE;
case 5: return Color.PINK;
case 6: return Color.DARK_GRAY;
case 7: return Color.BLUE;
case 8: return Color.BLACK;
default: return Color.BLACK;
}
}
public static void newPos(int[] coordinates) {
int startX = coordinates[0];
int startY = coordinates[1];
int endX = coordinates[2];
int endY = coordinates[3];
if(startY <= 100){
startX += 10;
}
else if(startY >= 300){
startX -= 10;
}
if(startX >= 300){
startY += 10;
}
else if(startX <= 100){
startY -= 10;
}
if(endY >= 300){
endX -= 10;
}
else if(endY <= 100){
endX += 10;
}
if(endX <= 100){
endY -= 10;
}
else if(endX >= 300){
endY += 10;
}
if(startX > 300){
startX = 300;
}
else if(startX < 100){
startX = 100;
}
else{
startX = startX;
}
if(startY > 300){
startY = 300;
}
else if(startY < 100){
startY = 100;
}
else{
startY = startY;
}
if(endX > 300){
endX = 300;
}
else if(endX < 100){
endX = 100;
}
else{
endX = endX;
}
if(endY > 300){
endY = 300;
}
else if(endY < 100){
endY = 100;
}
else{
endY = endY;
}
coordinates[0] = startX;
coordinates[1] = startY;
coordinates[2] = endX;
coordinates[3] = endY;
}
public static void drawHelix(){
int width = 400;
int length = 400;
DrawingPanel panel = new DrawingPanel(400, 400);
panel.setBackground(Color.BLACK);
Graphics g = panel.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(100,100,200,200);
g.setColor(Color.WHITE);
g.drawString("UTSA - CS1083 Section 004 - Prj 3 - Helix - Jesus Granados", 36, 50);
Scanner scnr = new Scanner(System.in);
System.out.print("Please, input the speed (1 - 10):");
int numSpeed = scnr.nextInt();
System.out.println("");
System.out.print("Please, input the number of times the line will be shown");
int numLines = scnr.nextInt();
System.out.println("");
int[] coordinates = {100, 100, 300, 300};
for (int i = 0; i < numLines; i++) {
g.setColor(Color.WHITE);
g.fillRect(100, 100, 200, 200);
Color colorLine = getColor();
g.setColor(colorLine);
g.drawLine(coordinates[0], coordinates[1], coordinates[2], coordinates[3]);
g.setColor(Color.WHITE);
g.drawString("i: " + i, 180, 350);
g.setColor(Color.WHITE);
String coordinatesText = "(" + coordinates[0] + ", " + coordinates[1] + ") to (" + coordinates[2] + ", " + coordinates[3] + ")";
g.drawString(coordinatesText, 140, 370);
g.setColor(Color.WHITE);
g.drawString("Speed: " + numSpeed,170,80);
newPos(coordinates);
panel.sleep(100 / numSpeed);
}
}
public static void main(String[] args){
System.out.println("UTSA - Fall 2023 - CS1083 Section 004 - Prj 3 - Helix - written by Jesus Granados");
drawHelix();
}
}