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.
![Ulam Spiral](https://private-user-images.githubusercontent.com/106467480/248771249-8a66b7a0-47e4-4890-9599-1b727ce451c6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE3ODM2ODgsIm5iZiI6MTcyMTc4MzM4OCwicGF0aCI6Ii8xMDY0Njc0ODAvMjQ4NzcxMjQ5LThhNjZiN2EwLTQ3ZTQtNDg5MC05NTk5LTFiNzI3Y2U0NTFjNi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzI0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyNFQwMTA5NDhaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wZDZhNTI0MmUyYjQwYzQ0ZTQ3Nzk2YTBiMjEyYzlhYzg4MWFlNmIzODY2MmY1MTA0Yzc3MWQ2NDE4MWJiZjA0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.NXb0GtP5LNiGVf4whPElff9k6CZISef74ZECre6IsVQ)
- 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! 🚀