Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rreusser/glsl-domain-coloring

A glslify module for domain coloring in the complex plane
https://github.com/rreusser/glsl-domain-coloring

Last synced: 7 days ago
JSON representation

A glslify module for domain coloring in the complex plane

Awesome Lists containing this project

README

        

# glsl-domain-coloring

> [Domain coloring](https://en.wikipedia.org/wiki/Domain_coloring) as a shader, via [glslify](http://github.com/chrisdickinson/glslify).

[![glsl-domain-coloring](https://nodei.co/npm/glsl-domain-coloring.png?mini=true)](https://nodei.co/npm/glsl-domain-coloring)

## Introduction

[Domain coloring](https://en.wikipedia.org/wiki/Domain_coloring) is an improvement over simple coloring by the complex argument and lightness by the magnitude. It makes the function easier to understand by applying the following logic:

- the complex argument determines the hue. (Red is positive real and cyan is negative real, while green-yellow is positive imaginary and blue-magenta is negative imaginary.)
- contours of the complex magnitude are lightened. The contours occur near integer values of `log2(|z|)`.
- real and imaginary grid lines are darkened. With grid spacing (1, 1), this means that the dark lines are simply the unit grid.

The result of these choices is that the behavior of the function is easier to discern than by a simple colormap. For example, the function `f(z) = z` plotted from -2 to 2 on the real and imaginary axes results in the colormap:


f(z) = z

The function `f(z) = 1 / z` in the same range results in the map:


f(z) = 1 / z

In the second example, the pole of the function is indicated by the bunching up of the grid lines as the white magnitude contours get closer and closer to the pole. In the first example though, the bunching up of the white magnitude contours without bunching up of the black grid lines indicates that it's a zero rather than a pole.

## Examples

Live demos:

- [`f(z) = z`](http://rreusser.github.io/glsl-domain-coloring/z.html)
- [`f(z) = 1 / z`](http://rreusser.github.io/glsl-domain-coloring/recip.html)
- [`f(z) = cos(z) / sin(z^4 - 1)`](http://rreusser.github.io/glsl-domain-coloring/eqn.html)

To use with glslify:

``` glsl
#pragma glslify: domainColoring = require(glsl-domain-coloring)

attribute vec3 position;

varying vec2 z;

void main () {
gl_FragColor = domainColoring(z, vec2(1.0), 0.9, 0.5, 0.7);
}
```

## API

#### `vec3 domainColoring(vec2 f, vec2 gridSpacing, float saturation, float gridStrength, float magStrength)`

Returns the rgb value given the real and imaginary components of f.

Arguments:

- `f`: A `vec2` containing the real and imaginary components of the function
- `gridSpacing`: a `vec2` containing the spacing of the grid in the x and y directions
- `saturation`: the saturation of the coloring, from zero to one
- `gridStrength`: the strength of the rectangular grid, from zero to one
- `magStrength`: the strength of the magnitude contours, from zero to one
- `linePower`: the strength of the lines, as a positive floating point number. Larger numbers result in sharper contours.

## License

© 2016 Ricky Reusser. MIT License.