Coder Social home page Coder Social logo

okdotdev / ulam-spiral-java-swing Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8 KB

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.

Java 100.00%
beginer-friendly beginer-projects beginner java java-awt-swing java-swing turorial ulam-spiral ulam-spiral-generator youtube

ulam-spiral-java-swing's Introduction

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.
Ulam Spiral

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

Don't forget to check out the GitHub repository for the source code and the YouTube video for a visual demonstration of the program! ๐Ÿš€

ulam-spiral-java-swing's People

Contributors

okdotdev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.