CS 220 – Software Design II class project.
This project implements a Java program that reads astronomical data from text files, renders a 2D star map using Swing graphics, draws constellations by connecting stars, and outputs computed star data in both text and binary formats.
The program visualizes stars based on real catalog data, scales their size according to brightness (magnitude), translates coordinates between astronomical and screen coordinate systems, and overlays constellation line segments using consistent coloring.
The purpose of this project is to practice:
- Object-oriented design using inheritance and composition
- File I/O (text and binary)
- Coordinate system translation
- Basic 2D graphics using Java Swing
- Managing structured data across multiple classes
project-root/
├── src/
│ ├── Line.java
│ ├── Oval.java
│ └── StarMap.java
├── data/
│ ├── stars.txt
│ └── constellations.txt
A reusable Swing component for drawing straight line segments.
- Extends
JComponent - Supports configurable thickness
- Draws a line between two absolute window coordinates
- Automatically computes bounding box based on endpoints
Used to render constellation connections between stars.
A reusable Swing component for drawing filled ovals.
- Extends
JComponent - Draws a filled oval within its bounding rectangle
- Provides simple intersection and point-intersection helpers
Used as the graphical base class for drawing stars.
The main application class.
Responsibilities:
- Creates and configures the application window (
JFrame) - Reads star catalog data from
stars.txt - Reads constellation definitions from
constellations.txt - Displays stars and constellation lines
- Writes computed star data to output files
The main method and constructor are provided and must not be modified.
Each line represents a single star. Fields are space-separated.
Format:
x y z hd magnitude hr [optional names]
x,y,z: Star catalog coordinates (range −1.0 to 1.0)hd: Henry Draper number (unique identifier)magnitude: Apparent brightnesshr: Harvard Revised numbernames(optional): Semicolon-separated star names
Only the x, y, magnitude, and identifiers are required for rendering.
Defines constellations as named groups of line segments.
- Lines beginning with
#indicate the start of a new constellation - Each following line lists two star names separated by a comma
- Each pair defines one line segment to draw between two stars
Each constellation is drawn using a single color. Different constellations use different colors.
- Origin
(0, 0)at center - X and Y range from
-1.0to1.0
- Origin
(0, 0)at top-left of drawing region - X increases to the right
- Y increases downward
Stars must be translated from catalog coordinates to window coordinates before drawing.
- Each star is drawn as a filled circle
- Star size is determined by magnitude using:
size = 1 + round(10.0 / (magnitude + 2.0))
- The computed size is used as both width and height
- The star’s window coordinate represents its center; the oval position must be offset accordingly
- Each constellation is assigned a distinct color
- Lines are drawn between stars using the
Linecomponent - All lines for a constellation share the same color
After rendering, the program writes star data to two files:
- One line per star
- Space-separated values
Written attributes (in order):
- Original x coordinate
- Original y coordinate
- Window x coordinate
- Window y coordinate
- Original magnitude
- Display size (diameter)
- Henry Draper number
The same data as the text file, written in binary form:
double: original xdouble: original yint: window xint: window ydouble: magnitudeint: display sizeint: Henry Draper number
Stars are written in the same order as they appear in stars.txt.
- The drawing region is square and configurable via command-line arguments
- The program must work with any valid star and constellation data files that follow the documented formats
- Additional helper classes and methods may be added as needed