Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3e339be

Browse files
committed
set random colours
1 parent 2a9071a commit 3e339be

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

‎README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ By @Alimov-8👨🏻‍💻 and @Rustam-Z👨🏼‍💻
55
Updated: December 5, 2020
66

77
### References:
8+
- https://clementmihailescu.github.io/Sorting-Visualizer/
9+
810
- https://www.geeksforgeeks.org/java-swing-jmenubar/
911

1012
- https://stackoverflow.com/questions/31094904/jmenu-not-appearing-until-window-is-resized
1113

12-
- https://stackoverflow.com/questions/4716372/java-how-do-i-close-a-jframe-while-opening-another-one
14+
- https://stackoverflow.com/questions/4716372/java-how-do-i-close-a-jframe-while-opening-another-one
15+
16+
- https://www.youtube.com/watch?v=RxjXC1SM1A4
17+
18+
- https://stackoverflow.com/questions/4246351/creating-random-colour-in-java

‎Sorting.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ else if (e.getSource() == jbtMerge)
7575
else if (e.getSource() == jbtBubble)
7676
System.out.println("jbtBubble button clicked");
7777
else if (e.getSource() == jbtInsertion) {
78-
sortAlgo.initSorter(); // Sorting algotithm
78+
sortAlgo.insertionSort(); // Sorting algotithm
7979
sortAlgo.initShuffler();
8080
}
8181
else if (e.getSource() == jbtSelection)

‎SortingAlgorithm.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ public class SortingAlgorithm extends JPanel {
2727
public void paintComponent(Graphics g) {
2828
super.paintComponent(g);
2929

30+
Random random = new Random(); // Random
31+
3032
// Drawing the rectangles
3133
Graphics2D g2d = (Graphics2D)g;
32-
g2d.setColor(Color.CYAN);
3334
Rectangle2D.Float bar;
35+
3436
for(int i = 0; i < SIZE; i++ ) {
37+
final float hue = random.nextFloat();
38+
final float saturation = 0.9f;//1.0 for brilliant, 0.0 for dull
39+
final float luminance = 1.0f; //1.0 for brighter, 0.0 for black
40+
41+
g2d.setColor(Color.getHSBColor(hue, saturation, luminance));
3542
bar = new Rectangle2D.Float(i * BAR_WIDTH, 0, BAR_WIDTH, bar_height[i]);
3643
g2d.fill(bar); // g2d.draw(bar);
3744
}
@@ -47,7 +54,7 @@ public void paintComponent(Graphics g) {
4754
g2d.fill(bar);
4855
}
4956

50-
public void initSorter() {
57+
public void insertionSort() {
5158
/*Insertion sort algorithm*/
5259

5360
sorter = new SwingWorker<>() {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /