Skip to content

Resurrecting a fractal generator originally written in Borland C++ BGI environment to run via modern SFML lib

Notifications You must be signed in to change notification settings

gradientwolf/fractals_SFML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

World of Fractals - A Modern C++ Restoration

Introduction

This project is a complete modernization of a 20-year-old Borland C++ graphics program. The original code, written for MS-DOS using the non-standard Borland Graphics Interface (BGI), was systematically translated to modern, portable C++ using the SFML (Simple and Fast Multimedia Library).

Why

A long time ago - me and my best friend in school thought fractals were a fun thing to show for class project. We both had keen interests in math and CS, and studying fractals was a natural outcome. Computers used to be a luxury: They were incredibly slower compared to the present (P-II pr P-III 400Mhz~800Mhz with 15" CRT monitors), and we had limited availability through the school lab. Being resource constrained in time & acces we often resorted to sketching out the major steps on paper before coding it up. Fractals were hard to construct and 'get right' by hand, but one could (in essence) see them getting plotted out slowly on these machines, over hundreds of loop's steps. It was wonderful, crazy and really fulfilling to see them emerge in the MS-DOS window (right after hitting "Compile and Run"). Nothing short of adventure outside of dull school routine.

That was 2002. A lot has changed in the last 25'ish years. Our class has sailed past school, colleges, graduate schools (or MBAs) long time ago. Most are senior enough to no longer write code on a day to day basis. Interests have changed, and so have the frameworks. Borland C++ is relegated to be an artifact of the early 90s. Coding practices have evolved. C++ has materially tranformed. I don't find as much joy in code as I used to, when I was in teens, but I had largely forgotten how much joy these little projects used to give. Most of my little experiments from this age is lost to the ravages of time. Only this source file survived.

Resurrecting it is like writing a love letter to the past: feeling the fleeting joy of seeing these projects run once again, remembering childhood friendships & the math circles, and the good ol' times of being kids.

Screenshots

Splash screen Main menu
Splash Main menu
Sierpinski Carpet Sierpinski Triangle
Carpet Main menu
Menger Sponge Polygon fractal ring
Splash Main menu
Barnsley's Fern Dragon Curves
Barnsley's Fern Dragon Curves

Features

The program is a multi-stage fractal explorer:

  • Main Fractals: Three classic fractals to generate:
    • Chain of Circles (via Polar coordinate inversion)
    • Sierpinski Carpet (2D)
    • Menger Sponge (3D flattened to a 2D representation)
  • Interactive "Chaos Loop": An interactive loop where you can generate a variety of polygonal fractals by entering a number from 3 to 14 (15 to exit).
  • Barnsley's Fern: A beautiful, high-resolution rendering of the classic Barnsley's Fern iterated function system (IFS).
  • Animated Dragon Curve: A dynamic, real-time animation that plots a colorful, swirling pattern reminiscent of 90s screensavers.

Building from Source on RHEL (and derivatives)

Step 1: System Registration and Repository Setup

The build process requires packages from the CodeReady Linux Builder (CRB) repository. You must enable it first.

For RHEL: Your system must be registered with a Red Hat subscription to access this repository. The free Developer Subscription is sufficient.

# Register your system
sudo subscription-manager register --username <username> \ 
                                   --password <password> \ 
                                   --auto-attach


# Find the exact name of the CRB repository
# (e.g., codeready-builder-for-rhel-9-x86_64-rpms)
sudo dnf repolist --all | grep -i builder


# Enable it using the name you found
sudo dnf config-manager --set-enabled <your-crb-repo-name>

For AlmaLinux / Rocky Linux: The equivalent repository is typically named plus or crb.

sudo dnf config-manager --set-enabled plus
# or
sudo dnf config-manager --set-enabled crb

Step 2: Install Build Dependencies

# Install the core C++ toolchain and Git
sudo dnf groupinstall "Development Tools"

# Install CMake (the build system for SFML)
sudo dnf install cmake

# Install the development libraries that SFML needs
sudo dnf install freetype-devel libXrandr-devel libXcursor-devel \
                 libXfixes-devel libXinerama-devel mesa-libGL-devel \
                 libXi-devel libudev-devel alsa-lib-devel \
                 openal-soft-devel libvorbis-devel flac-devel

Step 3: Compile and Install SFML to a Custom Directory

To avoid system clutter via untracked files, we will build SFML from source and install it into a self-contained /opt/sfml directory. This makes uninstallation as simple as deleting a folder.

# 1. Create a home for the SFML installation and take ownership
sudo mkdir /opt/sfml
sudo chown $USER:$USER /opt/sfml

# 2. Download the SFML source code
cd ~
git clone https://github.com/SFML/SFML.git
cd SFML

# 3. IMPORTANT: Check out the stable release
# The latest development branch requires a newer CMake than is available on RHEL 9.
# We must use the latest stable tag (e.g., 2.6.1) which is compatible.
git checkout 2.6.1

# 4. Configure the build with our custom install path
# This tells CMake to install everything inside target folder
cmake . -DCMAKE_INSTALL_PREFIX=/opt/sfml

# 5. Compile and install SFML
make -j$(nproc)
make install

# 6. Update the system's dynamic library cache
sudo ldconfig

Compiling and Running the Application

With SFML successfully built and installed, you can now compile and run the fractal program.

Step 1: Compile the Code

g++ fractals.cpp -o fractals \
    -I/opt/sfml/include \
    -L/opt/sfml/lib64 \
    -lsfml-graphics -lsfml-window -lsfml-system
  • -I/opt/sfml/include: Specifies the path to the SFML header files.
  • -L/opt/sfml/lib64: Specifies the path to the SFML library files (.so files).
  • Some builds may use lib instead of lib64. If error occurs, check under /opt

Step 2: Run the Executable

To run the program, you must tell the system's dynamic linker where to find the SFML libraries at runtime. This is done by setting the LD_LIBRARY_PATH environment variable.

LD_LIBRARY_PATH=/opt/sfml/lib64 ./fractals

The application should now launch!

Uninstallation

Because we installed SFML to a custom directory, cleanup is trivial and leaves no stray files on your system.

# Remove the custom SFML installation
sudo rm -rf /opt/sfml

# (Optional) Remove the downloaded source code
rm -rf ~/SFML

Acknowledgements

This project would not be possible without my very informative debugging assistant in Google Gemini 2.5 Pro

About

Resurrecting a fractal generator originally written in Borland C++ BGI environment to run via modern SFML lib

Topics

Resources

Stars

Watchers

Forks

Languages