Fractals

Table of Contents

Back to BASIC applications collection

1. Fractal circles

This QBasic program generates a visually captivating spiral fractal composed of circles. It employs a recursive algorithm to create intricate patterns that can inspire those interested in fractal geometry, recursive programming, and graphical design.

fractal%20circles%20-%20Screenshot%200.png

A single finished spiral fractal. The recursion starts with the large white circle in the center; every circle then sprouts up to three child circles (the direction pointing back at the parent is skipped), placed 2.5 radii away at a steadily increasing angle, which is what curls the chains into spirals. Children shrink by a direction-dependent divisor (5, 2 or 1.4), colors alternate between white on even recursion depths and light green on odd ones, and the recursion stops once the radius drops below 0.2 pixels.

Color and Depth
The color of each circle alternates based on the recursion depth, adding visual complexity to the fractal.
Termination Condition
The recursion terminates when the size of the circles becomes too small, ensuring the program doesn't run indefinitely.

Source code

2. Fractal circles animated

This QBasic program creates an animated fractal composed of circles, demonstrating an engaging visual effect. The program uses a timer system to control the animation's progression.

The same circle-spiral recursion as the static version, but here every parameter is animated by a keyframe timer system: arrays of (time, value) pairs are linearly interpolated each frame (processTimers) and drive the spiral's position, size and twist angle, the sine-modulated branch scale factors, the two stacked ellipses in the upper left (yellow rim, green and dark cores), and the sliding "KHK" and "Infotehno-loogia" labels built from small colored squares. Each frame is drawn on an off-screen video page and flipped in with PCOPY onto a solid white background; the demo terminates by itself when its timeline runs past 26 seconds.

Source code

3. Fractal of squares

This QBasic program generates and displays a fractal pattern composed of squares.

fractal%20squares%20-%20Screenshot%200.png

The first phase of the program: a single square fractal in one light green color. Every outlined square recursively places another square at each of its four corners with the size divided by 2.3, and the recursion continues until the squares shrink below one pixel.

fractal%20squares%20-%20Screenshot%201.png

The second phase: after clearing the screen, the program overlays 26 of these square fractals on the same spot, growing the root size from 1 to 128 in steps of 5 and picking a new random color (in the 7-14 range) for each pass. The superimposed corner-recursions interfere with each other and produce the dense rainbow moiré cloud.

4. Fractal of squares animated

This QBasic program generates an animated fractal pattern composed of size-shifting squares. The animation creates a visually captivating display by continuously redrawing the fractal with varying parameters, resulting in a dynamic and ever-changing geometric pattern.

Every frame redraws the corner-recursing square fractal with filled boxes whose color encodes the current recursion depth. The four corner divisors are independent sine waves with different periods (19, 12, 17 and 22 frames), so each diagonal branch shrinks at its own slowly changing rate and the pattern keeps pulsing and leaning asymmetrically. Frames are double-buffered with PCOPY in SCREEN 7, and any key press exits the program.

Source code

5. Fractal of trees

QBasic program that generates a visually appealing fractal tree animation. The program creates a dynamic fractal pattern that resembles a tree, with branches that grow and change over time.

An animated ternary tree drawn with plain white lines on black: every node sprouts three branches (up-left, up-right and straight up) and recurses into the three tips with reduced length. Three sine-driven modifiers with different periods (19, 12 and 17 frames) control how fast each branch shrinks, while six additional sine oscillators continuously bend the two side-branch vectors, so the whole tree sways, folds and regrows like in wind. Double-buffered with PCOPY; any key press exits.

Source code

Created: 2026-10-04 su 20:41

Validate