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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxOTA2NjYsIm5iZiI6MTcxOTE5MDM2NiwicGF0aCI6Ii8xMDY0Njc0ODAvMjQ4NzcxMjQ5LThhNjZiN2EwLTQ3ZTQtNDg5MC05NTk5LTFiNzI3Y2U0NTFjNi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjI0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYyNFQwMDUyNDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lNWQ3OWVkZWE5MDIzODQ4YjJhYjg0YThjOTEwZWMyN2UxODA5MTdjZDU1MzYwOWNmZTA4ZTU5M2Q5ZDUyOGYwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.KjfKFmDkb2ehuk_8jejuTmLtTwlQiW8Yssf2kNesdPw)
- 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! ๐