 ## Tutorial: Scribble Coloring

Text and Images © 2009 Kerry Mitchell

The original intent of this coloring was to replicate a scribble pattern. I didn't quite succeed in that, but I think it's still pretty cool. It takes a rose curve and smoothly changes its parameters while the curve moves along a curve.

### Background

The basic rose curve is defined in polar coordinates as r = sin(nθ), where n determines the number of lobes, or petals. Here we have three different rose curves, with n = 2, 2.5, and 3. (Click on any of the images in this tutorial to see their parameter sets.) Rose curves with n = 2, 2.5, and 3

This coloring uses a more general definition of the rose curve: r = accos(fc(θ + φc)) + assin(fs(θ + φs)), where:

• θ is the angle
• ac is the cosine amplitude
• fc is the cosine frequency
• φc is the cosine phase
• as is the sine amplitude
• fs is the sine frequency
• φs is the sine phase
and each of these quantities are allowed to vary along the course of the curve.

A time-like variable (t) is used to change the curve and move it around. Everything happens between the beginning, where t = 0, and the end, where t = 1. Each of the variables listed above is a function of t, along with the curve's center point.

Before we get into the parameters, let's see how things work.

The amplitude determines how large the curve is. Here on the left is the basic curve for fs = 1 (no cosine term), with an amplitude as = 1. On the right, the amplitude changes smoothly from 1 (on the left) to 2 (in the middle) to 0 (on the right). Varying the amplitude from 1 to 2 to 0

The frequency determines the number of lobes. Large changes in the frequency can lead to visual noise, but small changes can be very graceful. Here, the amplitude is 1 and the frequency, fs, changes from 2.98 (on the left) to 3.02 (on the right). Varying the frequency from 2.98 to 3.02

Changing the phase imparts a sense of rotation. On the left below is the basic curve for fs = 3 (no cosine term), with an amplitude as = 1. On the right, the phase, φs, varies from 0° to 180°. Note how the shape rotates half a turn from lobe pointing down to lobe pointing up. Varying the phase from 0° to 180°

The number of loops determines how many times the curve is drawn. More loops makes a smoother transition but generally requires more points (and time and memory). Both images below use a frequency fs = 2.02 (no cosine term), an amplitude as = 1, and phase, φs = 0°. The first image uses 50 loops and the second uses 100. The apparent rotation in these cases comes from the frequency being close to, but not quite, an integer. 50 loops

### Interpolation

Much of the power of this coloring comes from its interpolation routines--exactly how a variable changes from one value to another. For each variable, there are five methods. They are:
• Constant. Not really an interpolation technique, since the variable doesn't change.
• Linear. Simply specify an initial value (for t = 0) and a final value (for t = 1) and the variable changes linearly in between.
• Lagrange polynomial. Here, you must specify up to 10 values for the variable and the t points (between 0 and 1) where each occurs. A polynomial is fit exactly through the set of points, so that the variable takes on all of your input values. See Wikipedia for more information.
• Bezier polynomial. You specify two anchor values (for t = 0 and 1) and 1 to 8 control values. The variable curve goes through the anchor points and its shape is governed by the control points. Generally better behaved than a Lagrange polynomial, but only the anchor values are used exactly. See Wikipedia for more information.
• Rational Bezier polynomial. A generalization of the Bezier polynomial, where each point is weighted by a value. See Wikipedia for more information.
This image shows how the various techniques work. Each curve represents the values that one of the variables would take as t moves from 0 to 1. The black dots in the lower left and upper right corners represent the values for t = 0 and t = 1, respectively. Each of the four curves goes through both points, showing that those values will be exactly used by all of the four methods. (Of course, if the "constant" method is used, then the variable will only take on that value.) Interpolation schemes

The brown curve shows the "linear" method--a straight line between the two values. The other three curves all use three points in their defintion, the two anchor points and the third point in the upper left corner. The blue curve is a Bezier polynomial and the third point is a control point. It pulls the curve to it, but the curve doesn't necessarily go through it. Assigning weights to each point in a Bezier curve turns it into a rational Bezier curve, the red line. In this example, the anchor points have weights of 1 and the control point has a weight of 10. This causes the red line to be drawn toward the control point much more so than it was with the regular Bezier curve (which is the same as a Rational Bezier with all weights the same). A Lagrange polynomial is shown in the green curve. In this case, the curve also goes through the third point. This is good for making sure that all of your input values are used, but it can also lead to some unpredicted results.

If you're new to all of this, then stick with the "constant" and "linear" modes until you get the hang of things.

### Parameters

There is a section of general parameters and then seven sections, one for each variable. Those sections all have the same structure.

General parameters

• # points: The number of points used to draw the curve, at least 2.
• color by: How to color the curve, either as an outline (same color along the curve) or by which line (color varies along the curve).
• line width: How wide the curve is.
• threshold: The curve is drawn as a series of segments. This setting is used to check if the pixel is close to a segment before drawing it, saving some time if you have lots of points (say, more than a few thousand). If you make this value too small, you may have gaps in your curve. Too large will just make the rendering take longer than it needs to.
• print longest. Check this to have the length of the longest segment printed out. Then, set the threshold to at least this value.

Loops. These parameters allow you to specify how many loops are drawn and how they are drawn. Each loop contains 360° of angle.

• interpolation. How the intermediate angle values are determined. Choose from: "constant," "linear," "Lagrange," "Bezier," or "rational Bezier."
• constant: The single loop value if "constant" is chosen. The "constant" mode for Loops is not recommended.
• 0 value: If the "linear" mode is chosen, then this parameter is the number of loops for t = 0, typically 0.
• 1 value: If the "linear" mode is chosen, then this parameter is the number of loops for t = 1. Try 50 or 100.
• # points: The number of points used to define the interpolation curve, if "Lagrange," "Bezier," or "rational Bezier" is chosen. Use a whole number from 3 to 10, inclusive. Each additional point used will require more inputs.
• point 1: If the "Lagrange" method is picked, then the variable values of each point are entered.
• t1: If the "Lagrange" method is picked, this will be the t value where the loops takes on its first value (point 1). Generally, t1 should be 0 and the last t should be 1.
• anchor 0: This is like "point 1" if "Bezier" is chosen. The variable curve will begin at this value.
• control 1: If you use the "Bezier" mode, there will be two less control points than the number of points used to define the curve. So, if you set "# points" (for Loops, after the "iterpolation" setting) to be 4, you'll need to enter 2 control point values.
• anchor 1: If "Bezier" is chosen, the variable curve will end at this value.
• anchor 0 weight: For the "rational Bezier" mode, there will be a weight parameter for each of the control and anchor points.
There are six more sections of parameters, each with a structure identical to that of the Loops section:
• sine amplitude
• sine frequency
• sine phase (units of degrees)
• cosine amplitude
• cosine frequency
• cosine phase (units of degrees)
• center (Here, all of the values except for the t1, t2, etc. values are complex. For all of the other sections, all values are real.)

### Hints

You are, of course, free to use this coloring however youd like. However, these hints may help your explorations be more productive.

• This is one of those coloring formulas that does all the work. It was designed to be used as an outside coloring with the Pixel formula in lkm.ucl.
• All the interpolation stuff can be tricky to keep straight. You may wish to start with these basic ideas and then branch out as you are more comfortable:
• Use "linear" mode with Loops, setting the "0 value" to 0.
• Only use the "constant" and "linear" modes.
• Only change one or two variables at a time.
• Stick to constant, integer frequency values, or to small changes around integers.
• You can see the path of the Center curve by setting the amplitudes to 0.
• This coloring works by creating a bunch of segments and then checking the pixel coordinates against each of them. Consequently, rendering can take a very long time if you have a lot of segments (the "# points" parameter in the General section).
• If you have more than a few thousand points/segments, then use the "print longest" feature to figure out how to set the threshold parameter.
• With the "outline" mode, a simple gradient works well. Say, a black control point at position 0 to define the center of the curve and a white one at position 399, plus a white background.

### Sample Image

Click on any of the images on this page to see their parameter sets. Heres how to make the image at the top of this page.

1. Start a new fractal, with these characteristics:
• Formula: Pixel from lkm.ufm, with the default settings.
• Inside: none (default)
• Outside: Scribble from lkm3.ucl, with the default settings. Clear the Repeat Gradient box and set the Solid Color to white (255 red, 255 green, 255 blue).
• Image: set the width to 600 pixels and the height to 400 pixels.
• Gradient: remove all the control points. Insert one at position 0, color black (0 red, 0 green, 0 blue). Insert a white one (255 red, 255 green, 255 blue) at 399 and a gold (45 hue, 255 saturation, 63 luminance) at 150.
• Location: Set the Magnification to 0.95.

Your image might not look like much, but it should resemble the Step 1 image, below. If not, click on the image for the parameter set. Step 1

2. Make a group for this layer and its companion:
• Rename this layer "outline."
• On the Outside tab, change the General parameters to:
• # points: 20000
• color by: outline (default)
• line width: 0.005
• threshold: 0.1
• print longest: cleared
• In the Loops section set:
• interpolation: linear
• 0 value: 0
• 1 value: 100
• In the Sine Amplitude, Sine Frequency, and Sine Phase sections, set:
• interpolation: constant
• constant: 0
• In the Cosine Amplitude section, set:
• interpolation: linear
• 0 value: 0
• 1 value: 1
• In the Cosine Frequency section, set:
• interpolation: constant
• constant: 3.02
• In the Cosine Phase section, set:
• interpolation: linear
• 0 value: 0
• 1 value: 120
• For the Center section, set:
• interpolation: linear
• 0 value: 0/1.5
• 1 value: 0/0
• Add a new group and move this layer into it. Change the name of the group to "gold group."
• Add a duplicate of the "outline" layer and call it "which line."
• In the General section of "which line"'s Outside tab, change "color by:" to "which line."
• Change the Merge Mode of "which line" to Screen.

Hopefully, you've got something like the Step 2 image. If not, click on the image for the parameter set. Step 2

3. Make two more groups:
• Change the Merge Mode of "gold group" to Mulitply.
• Highlight the "gold group" and duplicate it twice. Name one the "green group" and the other the "blue group."
• Highlight both layers of the "green group." Change the "1 value" of the "Cosine Phase" to 240.
• Change the "Center" interpolation to "Bezier" with 3 points.
• Set "anchor 0" to -2.25/-1.5.
• Set "control 1" to -1/0.
• Set "anchor 1" to 0/0.
• For both layers, change the gradient by changing the hue of the control point at position 150 to 135, a nice green color.
• Highlight both layers of the "blue group." Change the "1 value" of the "Cosine Phase" to 360.
• Change the "Center" interpolation to "Bezier" with 3 points.
• Set "anchor 0" to 2.25/-1.5.
• Set "control 1" to -1/0.
• Set "anchor 1" to 0/0.
• For both layers, change the gradient by changing the hue of the control point at position 150 to 225, a blue color that's awfully swell.

Hopefully, you've got something like the Step 3 image, which is also the image at the top of the page. If not, click on the image for the parameter set. Step 3 Back to Tutorials page Up to my home page