Turning Text into Fourier Sums and Drawing

Overview

This project is an extension of the Fourier Images project. Instead of requiring an input image file, it converts any arbitrary text string into an image, extracts its contours, applies a Discrete Fourier Transform, and draws the text using rotating epicycles — a set of circles whose combined rotations trace out the original shape.

The program uses Processing's graphics API to render text with a custom font at high resolution, then feeds the generated image through the same OpenCV contour extraction and DFT pipeline used in the image version. The result is a mesmerizing animation of two sets of rotating circles that trace out the text character by character.

How It Works

Text to Image

The first stage uses Processing's createGraphics API to render the input text string using a custom font file ("parisienne.regular.ttf") at a configurable font size (default 350px). The rendered text is saved as a PNG image which serves as input for the contour extraction step.

This approach makes the system extremely flexible — any text string, font, and size can be used to generate the source image automatically, without requiring manual image preparation.

Contour & DFT

The generated PNG image is processed through the same pipeline as the image version: OpenCV converts it to grayscale, applies a binary threshold, and runs findContours to extract the outlines of each character.

Points are sampled along the contours at a configurable step size (controlling sampling density), and the x and y coordinates are separately decomposed using a Discrete Fourier Transform. Each frequency component becomes a Circle object with its own amplitude, frequency, and phase — the building blocks for the epicycle animation.

Epicycle Drawing

The drawing stage uses the same dual-epicycle system as the image version: one set of rotating circles controls the x-coordinate and another controls the y-coordinate. As time progresses, the circles rotate at their respective frequencies, and the tip of each chain traces out the reconstructed path.

The drawn path uses a distinctive yellow stroke color (RGB 255, 248, 21) instead of the cyan used in the image version, making it easy to distinguish output from the two programs.

The Pipeline

End-to-End Flow

Text String
Font Rendering
PNG Image
OpenCV Contours
Point Sampling
DFT(x), DFT(y)
Epicycles
Drawn Text

The pipeline is fully automated: given a text string and font configuration, the program generates the image, extracts contours, computes the Fourier decomposition, and renders the epicycle animation — all without manual intervention.

Comparison with Image Version

Key Differences

Text Version

  • Input: arbitrary text string
  • Automatic image generation from custom font
  • Configurable font, size, and text parameters
  • Yellow trace color (255, 248, 21)

Image Version

  • Input: image file (PNG, JPG, etc.)
  • Manual image preparation required
  • Works with any visual content
  • Cyan trace color

Both versions share the same underlying DFT algorithm and epicycle drawing engine. The text version is essentially an automated wrapper that adds text-to-image conversion before the existing Fourier drawing pipeline.

Technology Stack

Tools & Libraries

Processing (Java)

Core graphics framework and runtime

OpenCV (gab.opencv)

Contour extraction and image processing

PeasyCam

Interactive 3D camera control

Custom Fonts

TTF font rendering for text generation

DFT Algorithm

Discrete Fourier Transform decomposition

Real-time Rendering

Live epicycle animation and drawing

Nuwantha Kumara

Mechanical Engineering student passionate about software development, simulations, and creating impactful solutions.

Connect

© 2026 Nuwantha Kumara. All rights reserved.

Built withNext.js