This program generates an Ulam Spiral, a visualization of prime numbers in a spiral pattern. It uses Java Swing to create a graphical user interface (GUI) window for displaying the spiral. 🌀
- Run the program.
▶️ - A dialog box will prompt you to enter the size of the spiral. 🔢
- Enter a positive integer value to determine the size of the spiral. The larger the size, the more prime numbers will be displayed.
- The program will open a window titled "Ulam Spiral" displaying the generated spiral. 🪐
- Each prime number in the spiral is represented by a small square filled in the graphical interface. 🟩
- Java Development Kit (JDK) installed ☕
- Java Swing library
- The program prompts the user to enter the size of the spiral using a dialog box.
- The
Main
class extends theJFrame
class to create a window for the spiral. - The window is centered on the screen and sized according to the user's input.
- The
paint
method is overridden to draw the spiral. - The prime numbers are determined using the
isPrime
method, which checks if a number is divisible by any number from 2 up to the square root of the number. - The
Graphics
object is used to draw the prime numbers as small squares on the spiral. - The spiral is generated by moving in a clockwise direction, changing direction at each "turn" and incrementing the step size.
- The
dx
anddy
variables control the movement of the spiral in the x and y directions, respectively. - The
angle
variable keeps track of the current angle of movement in degrees. - The loop continues until all the cells in the spiral are processed.
- If the user enters an invalid input or closes the dialog box without entering a value, a default size of 100 is used for the spiral.
Feel free to customize and experiment with the program to explore different sizes and variations of the Ulam Spiral. ✨
Don't forget to check out the GitHub repository for the source code and the YouTube video for a visual demonstration of the program! 🚀