Images from functions

As mentioned in the introduction, images can be generated from functions; a function which returns a color and which takes as arguments a pair of coordinates, is evaluated for each position in the image to generate the pixel colors for an entire image.

As an illustrative example, consider the function which returns the following color (expressed in terms of its red, green, and blue components which each assume a value between 0 and 1)

$ red\;component = x $

$ green\;component = 0 $

$ blue\;component = 0 $

This function keeps the green and blue components of each pixel constant at zero, whilst increasing the red component with x. Evaluating this function for a 250x250 pixel image results in the following image:



In expectation with the function definition, pixel redness gradually increases across the image from left to right.

Note that the x value starts at zero on the far left, and we define it to end having value one at the far right. The value that x is increased as we move to the right, therefore depends on how big the image is, but this is easy to calculate on a computer.

As another example consider the following function

$ red\;component = 0 $

$ green\;component = \frac{1}{2} \cdot (1 + \sin x) $

$ blue\;component = 0 $

The figure below shows the generated image, and the associated function. A color bar is included next to the plotted function to illustrate the correspondance of function values with colors.