Duration
60s
Square Size
20px
0.0%
0:00

About Square Fill

Square Fill is a minimalist procedural art generator that visualizes a simple stochastic process. The tool presents a uniform grid of cells, initially rendered in white (typically sRGB[16] #FFFFFF), which are then incrementally and randomly filled with black (sRGB #000000). This process continues until the entire grid is filled, providing a stark visual representation of entropy increasing within a closed system. It serves as a fundamental example of procedural generation[11], where complex-seeming patterns emerge from a simple set of rules and random inputs, creating a unique sequence for every session.

The core of the tool's behavior is its random selection mechanism, which almost certainly relies on a pseudorandom number generator[12] (PRNG). Most web browsers implement `Math.random()` using algorithms like xorshift128+ or the Mersenne Twister[9], which produce sequences that are statistically random but ultimately deterministic. For applications requiring higher-quality unpredictability, browsers provide the Web Cryptography API[20], which can access more robust entropy sources than a simple PRNG seed. This contrasts with true randomness derived from physical phenomena, as captured by a hardware random number generator[7].

The display area is a regular grid[14], a discrete Cartesian space that is a foundational structure in computer graphics and scientific modeling. While the tool's operation is a simple stochastic process[18], the grid structure is shared with the more complex domain of the cellular automaton[2] (CA). CAs, pioneered by figures like John von Neumann[8] and Stanisław Ulam[17], evolve based on deterministic rules applied to a cell's neighbors. Square Fill, by contrast, has no concept of neighborhood or state evolution; each cell's change is an independent random event, making it distinct from famous CAs like Conway's Game of Life[3].

From a technical standpoint, rendering such a display is most efficiently handled using the HTML Canvas[6] element and its 2D rendering context[21]. This imperative, bitmap-based API is optimized for drawing a large number of simple shapes and pixels without the overhead of a scene graph. Alternative implementations using Scalable Vector Graphics[15] (SVG[22]) or direct manipulation of the Document Object Model[5] (DOM[23]) are possible but would incur significant performance penalties due to the overhead of managing thousands of individual objects. The animation's timing is best controlled with `requestAnimationFrame`, which synchronizes drawing operations with the browser's repaint cycle, ensuring smooth visuals and efficient use of CPU resources.

Conceptually, the filling process is a direct visualization of a discrete uniform distribution[19], where each cell has an equal probability of being selected at any given step. It can also be viewed as a cumulative Bernoulli process[1], where each trial (a cell selection) results in a permanent state change. The visual clustering that emerges is a topic studied in percolation theory[10]. As the grid fills, the rate of finding an empty cell decreases, a phenomenon mathematically described by the coupon collector's problem[4], which predicts the expected number of trials needed to collect a full set of unique items.

How to Use

  1. 1. Load the Square Fill tool in a modern web browser.
  2. 2. Observe the initial state: a clean, uniform grid of white cells.
  3. 3. Watch as the tool randomly selects individual cells and fills them with black.
  4. 4. The process continues over time, with the fill rate appearing to slow as fewer white cells remain.
  5. 5. The animation completes when every cell in the grid has been filled.
  6. 6. To begin a new, unique sequence, simply refresh the page.

Frequently Asked Questions

Is the sequence of squares truly random?

No. It uses a pseudorandom number generator (PRNG), likely the browser's built-in `Math.random()` function. This creates a sequence that appears random for most purposes but is deterministic. For cryptographically secure randomness, an application would use the Web Cryptography API[20] and its `crypto.getRandomValues()` method.

Why does the filling process seem to slow down over time?

This is an expected outcome predictable by probability theory, specifically the coupon collector's problem[4]. As the grid fills, the random coordinate generator is increasingly likely to select a cell that is already black. The tool must perform more random selections on average to find one of the few remaining white cells, thus the visible rate of change decreases.

What web technology is used to draw the grid?

The most efficient method is the HTML Canvas[6] element's 2D API. It is a low-level, bitmap-based drawing surface ideal for rendering a large number of simple primitives with high performance. Using SVG[15] or DOM[5] elements would be much slower for a large grid.

How does this relate to Conway's Game of Life?

It shares the visual element of a grid of cells, but its mechanism is fundamentally different. Conway's Game of Life[3] is a deterministic cellular automaton[2] where each cell's state in the next generation is determined by the state of its neighbors. Square Fill is a stochastic process[18] where cell changes are random, independent events with no rules or neighborhood influence.

What algorithm determines the next square to fill?

The algorithm is a form of random sampling. In a loop, it generates a random integer `x` (from 0 to grid width minus 1) and a random integer `y` (from 0 to grid height minus 1). It then checks if the cell at `(x,y)` is already filled. If it is not, the cell is filled, and the display is updated. This process repeats.

What color space and colors are used?

The colors are rendered within the standard web color space, which is typically sRGB[16]. The tool uses pure white, represented by the hexadecimal code #FFFFFF or RGB(255, 255, 255), and pure black, represented by #000000 or RGB(0, 0, 0).

How is the animation timed so smoothly?

Modern, efficient web animations use the `requestAnimationFrame` browser API. This method tells the browser that you wish to perform an animation and requests that the browser call a specified function to update an animation before the next repaint. This ensures the animation is smooth and power-efficient, unlike older methods like `setInterval`.

Sources (23)
  1. Wikipedia: Bernoulli process
  2. Wikipedia: Cellular automaton
  3. Wikipedia: Conway's Game of Life
  4. Wikipedia: Coupon collector's problem
  5. Wikipedia: Document Object Model
  6. Wikipedia: HTML Canvas
  7. Wikipedia: Hardware random number generator
  8. Wikipedia: John von Neumann
  9. Wikipedia: Mersenne Twister
  10. Wikipedia: Percolation theory
  11. Wikipedia: Procedural generation
  12. Wikipedia: Pseudorandom number generator
  13. Wikipedia: RGB color model
  14. Wikipedia: Regular grid
  15. Wikipedia: Scalable Vector Graphics
  16. Wikipedia: sRGB
  17. Wikipedia: Stanisław Ulam
  18. Wikipedia: Stochastic process
  19. Wikipedia: Uniform distribution (discrete)
  20. Wikipedia: Web Cryptography API
  21. W3C: Canvas 2D Context
  22. W3C: Scalable Vector Graphics (SVG) 2
  23. WHATWG: DOM Standard

About Matt George

I'm Matt George, a software engineer in the startup space. I run my own shop building software for early-stage founders, and I love making free tools and experiences that people actually use. Enjoy using Square Fill!

More Free Tools