https://github.com/oslint/ulam-spiral-java-swing
The Ulam Spiral is a graphical representation of prime numbers in a spiral pattern. This program generates the Ulam Spiral and displays it using Java's Swing library.
https://github.com/oslint/ulam-spiral-java-swing
beginer-friendly beginer-projects beginner java java-awt-swing java-swing turorial ulam-spiral ulam-spiral-generator youtube
Last synced: 4 months ago
JSON representation
The Ulam Spiral is a graphical representation of prime numbers in a spiral pattern. This program generates the Ulam Spiral and displays it using Java's Swing library.
- Host: GitHub
- URL: https://github.com/oslint/ulam-spiral-java-swing
- Owner: OsLint
- Created: 2023-06-25T11:13:46.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-26T10:52:46.000Z (almost 2 years ago)
- Last Synced: 2024-12-05T23:09:31.487Z (6 months ago)
- Topics: beginer-friendly, beginer-projects, beginner, java, java-awt-swing, java-swing, turorial, ulam-spiral, ulam-spiral-generator, youtube
- Language: Java
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ulam Spiral
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. 🌀
## Usage
1. Run the program. ▶️
2. A dialog box will prompt you to enter the size of the spiral. 🔢
3. Enter a positive integer value to determine the size of the spiral. The larger the size, the more prime numbers will be displayed.
4. The program will open a window titled "Ulam Spiral" displaying the generated spiral. 🪐
5. Each prime number in the spiral is represented by a small square filled in the graphical interface. 🟩## Prerequisites
- Java Development Kit (JDK) installed ☕
- Java Swing library## How it works
1. The program prompts the user to enter the size of the spiral using a dialog box.
2. The `Main` class extends the `JFrame` class to create a window for the spiral.
3. The window is centered on the screen and sized according to the user's input.
4. The `paint` method is overridden to draw the spiral.
5. 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.
6. The `Graphics` object is used to draw the prime numbers as small squares on the spiral.
7. The spiral is generated by moving in a clockwise direction, changing direction at each "turn" and incrementing the step size.
8. The `dx` and `dy` variables control the movement of the spiral in the x and y directions, respectively.
9. The `angle` variable keeps track of the current angle of movement in degrees.
10. The loop continues until all the cells in the spiral are processed.## Note
- 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. ✨
## Links
- [GitHub](https://github.com/oskalbarczyk)
- [YouTube](https://www.youtube.com/@codewithoskar)
- [Donations](https://tipply.pl/u/oskalbarczyk)
- [Twitter](https://twitter.com/oskalbarczyk)Don't forget to check out the GitHub repository for the source code and the YouTube video for a visual demonstration of the program! 🚀