1212
1313public class SortingAlgorithm extends JPanel {
1414 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
1616 private final float BAR_WIDTH = (float )WIDTH / SIZE ; // bar width
1717 private float [] bar_height = new float [SIZE ]; // height of bars
1818 private SwingWorker <Void , Void > shuffler , sorter ;
@@ -34,15 +34,16 @@ public void paintComponent(Graphics g) {
3434
3535 // Drawing the rectangles
3636 Graphics2D g2d = (Graphics2D )g ;
37+ g2d .setColor (Color .CYAN );
3738 Rectangle2D .Float bar ;
3839
3940 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
4344
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 ]);
4647 g2d .fill (bar ); // g2d.draw(bar);
4748 }
4849
@@ -68,7 +69,7 @@ public Void doInBackground() throws InterruptedException {
6869 swap (traversing_index , traversing_index - 1 );
6970 traversing_index --;
7071
71- Thread .sleep (1 );
72+ Thread .sleep (10 );
7273 repaint ();
7374 }
7475 }
0 commit comments