Coloring Transforms
by Kerry Mitchell, 11 Feb 2000
Basic information
These transforms allow you to use Ultra
Fractal as your own personal coloring book! You can specify a region
and an index for its color. The coloring routine then reads the index
and colors the region. The motivation for this work was to use Ultra
Fractal like a paint program, outlining areas and filing them with solid
color. I wanted to do this because I knew I could identify the areas
exactly and then write the coordinates to an UF upr file. Also, if
I liked the image, I could easily scale it up for printing by increasing
the image size.
Detailed information
One fairly simple approach would be
to have a layer for each region, using a clipping transform to select that
region. However, for an image with hundreds of regions, this would
be prohibitively expensive in memory and time, as each layer would be computed
independently.
The method I came up with requires
only one layer, but that layer may have hundreds of transforms. Each
transform selects the interior of a region, but since they may overlap,
any given pixel may have had several transforms applied to it before surviving
to the formula stage.
Conceptually, the transform works
like this: one parameter is encoded into the real part of the pixel
coordinate, and another into the imaginary part. Upon entering the
transform, the parameters are read, and the actual coordinates determined.
The transform does whatever it does (in this case, determining whether
or not the pixel is inside a given region). Then, on the basis of
the results, the two parameters are set and encoded into the pixel.
The newly encoded pixel is then passed onto the formula, or the next transform.
To encode the parameters, I took
advantage of the fact that, most of the time, only a small range of coordinates
is used in fractal images. While Ultra Fractal is capable of handling
coordinates that are much larger than 100 in magnitude, (relatively) seldom
is a coordinate larger than 10 ever used. That extra "space" in the
coordinate range can be used to store the parameters. Somewhat arbitrarily,
I chose the cutoff line to be 10: the actual pixel values were allowed
to vary between -10 and +10. Anything outside of that range would
be interpreted as having a parameter encoded in it. (Actually, pixel
coordinates between -10 and +10
are interpreted as having a parameter value of 0 encoded.) So, if
the transform read a #pixel value of (11, 33), that would correspond to
an x parameter of 1, a y parameter of 2, and an actual pixel coordinate
of (-9, -7) (see the code for the details).
In my case, I took the x parameter
to be (related to) the color index that the pixel was to be colored.
Since the multiple transforms overlap, the pixel gets colored according
to the last x parameter. In the coloring algorithm ("Passthru", below),
the x parameter is scaled down into an acceptable #index range. The
x parameter is reset each time the pixel encounters another transform.
The y parameter was a counter, incrementing by one each time the pixel
was transformed. Passthru can scale this parameter into an #index,
or it can combine the x and y parameters into the #index.
Between the transform and the coloring
is the formula. I didn't need a formula, hence the "Null" entry,
below. It reads the pixel parameters and if either one is non-zero,
passes the pixel as an outside point. If both parameters are zero,
the pixel is passed as an inside point. This is a way to find pixels
that haven't been through any transform.
This technique is not general purpose,
nor is it suited for every image. However, it is a way to pass information
directly to the coloring algorithm, and can be used in many different ways.
Suggested other formulas
These transforms were designed to be
used with:
-
"null" formula: This formula does
nothing but pass index information from the transform to the coloring routine.
-
"passthru" coloring: Takes the
indices written in the transform and turns them into a color index.
Parameters and flavors
There are different flavors to the same
basic transform idea. Here are the types and their parameters.
Triangle Color
This transform colors regions inside
or outside of triangles.
-
corners 1 - 3: The corner points.
They must all be less than 10 in magnitude.
-
region: An inside/outside flag
that determines which region gets colored.
-
set color: An integer index that
corresponds to which color the region is to be colored.
-
bounding box: A checkbox to indicate
whether or not a bounding box is used. The calculation to see if
a pixel is inside or outside a general quadrilateral is fairly tedious.
The overall calculation can be speeded up by not checking pixels which
are outside of a rectangle surrounding the given quadrilateral. Enable
to use a bounding box.
-
xmin, xmax, ymin, ymax: The coordinates
of the bounding box. It is a rectangle with horizontal and vertical
sides. If you use a bounding box, make sure that the box completely
encloses the quadrilateral, but is still close to it.
Quadrilateral Color
This transform colors regions inside
or outside of convex quadrilaterals (4 sided polygons that aren't caved
in).
-
corners 1 - 4: The corner points.
They must all be less than 10 in magnitude.
-
region: An inside/outside flag
that determines which region gets colored.
-
set color: An integer index that
corresponds to which color the region is to be colored.
-
bounding box: A checkbox to indicate
whether or not a bounding box is used. The calculation to see if
a pixel is inside or outside a general quadrilateral is fairly tedious.
The overall calculation can be speeded up by not checking pixels which
are outside of a rectangle surrounding the given quadrilateral. Enable
to use a bounding box.
-
xmin, xmax, ymin, ymax: The coordinates
of the bounding box. It is a rectangle with horizontal and vertical
sides. If you use a bounding box, make sure that the box completely
encloses the quadrilateral, but is still close to it.
Rectangle Color
This is a streamlined version of "Quadrilateral
Color", when all you need is a rectangle that is not rotated.
-
rectangle center: The center of
the rectangle.
-
width: Make sure that the sides
are less than 20, to keep the points in the range from -10 to 10.
-
height: Make sure that the sides
are less than 20, to keep the points in the range from -10 to 10.
-
region: An inside/outside flag
that determines which region gets colored.
-
set color: An integer index that
corresponds to which color the region is to be colored.
Pentomino Color
Pentominoes are tiles composed of 5
squares, like dominoes, which are made up of 2 squares. There are
12 pentominoes, and this transform allows you to color any of them.
This is to allow building shapes, much like jigsaw puzzle pieces.
Consequently, only the inside of the tile can be colored.
-
tile type: The 12 pieces are labelled
according to the letter they resemble: F, I, L, N, P, T, U, V, W, X, Y,
or Z.
-
origin: Loosely corresponds to
the lower left of an unrotated, unflipped tile. Use as a way to slide
the tile.
-
scale: Change to alter the size
of the tile.
-
rotation: Rotation angle, in degrees,
positive counter-clockwise.
-
flip: Flip the tile horizontally,
vertically, or both.
-
set color: An integer index that
corresponds to which color the region is to be colored.
Circle Color
-
circle center: The center of the
circle.
-
radius: Maximum is 10, to keep
the points in the range from -10 to 10.
-
region: An inside/outside flag
that determines which region gets colored.
-
set color: An integer index that
corresponds to which color the region is to be colored.
Hints
Working with lots of transforms can
quickly get unwiedly. Be sure to have a plan if you're working on
a complex image. Be sure to use a bounding box if you're working
with many triangles or general quadrilaterals.
Sample images
The parameters can be found
in lkm2.upr
Triangle Color |
Quadrilateral Color |
Circle Color |
Pentomino Color |