12
12
13
13
public class SortingAlgorithm extends JPanel {
14
14
private final int WIDTH = 800 , HEIGHT = WIDTH * 9 / 16 ;
15
- public int SIZE = 50 ; // the number if sorting elements
15
+ public int SIZE = 100 ; // the number if sorting elements
16
16
private final float BAR_WIDTH = (float )WIDTH / SIZE ; // bar width
17
17
private float [] bar_height = new float [SIZE ]; // height of bars
18
18
private SwingWorker <Void , Void > shuffler , sorter ;
@@ -34,15 +34,16 @@ public void paintComponent(Graphics g) {
34
34
35
35
// Drawing the rectangles
36
36
Graphics2D g2d = (Graphics2D )g ;
37
+ g2d .setColor (Color .CYAN );
37
38
Rectangle2D .Float bar ;
38
39
39
40
for (int i = 0 ; i < SIZE ; i ++ ) {
40
- final float hue = random .nextFloat ();
41
- final float saturation = 0.9f ; //1.0 for brilliant, 0.0 for dull
42
- final float luminance = 1.0f ; //1.0 for brighter, 0.0 for black
41
+ // final float hue = random.nextFloat();
42
+ // final float saturation = 0.9f; //1.0 for brilliant, 0.0 for dull
43
+ // final float luminance = 1.0f; //1.0 for brighter, 0.0 for black
43
44
44
- g2d .setColor (Color .getHSBColor (hue , saturation , luminance ));
45
- bar = new Rectangle2D .Float (i * BAR_WIDTH , 0 , BAR_WIDTH , bar_height [i ]);
45
+ // g2d.setColor(Color.getHSBColor(hue, saturation, luminance));
46
+ bar = new Rectangle2D .Float (i * BAR_WIDTH , 0 , BAR_WIDTH - 1 , bar_height [i ]);
46
47
g2d .fill (bar ); // g2d.draw(bar);
47
48
}
48
49
@@ -68,7 +69,7 @@ public Void doInBackground() throws InterruptedException {
68
69
swap (traversing_index , traversing_index - 1 );
69
70
traversing_index --;
70
71
71
- Thread .sleep (1 );
72
+ Thread .sleep (10 );
72
73
repaint ();
73
74
}
74
75
}
0 commit comments