Overview of Item Types

Line Items

Items of type line appear on the display as one or more connected line segments. Lines are created with widget commands of the following form:

pathName create line x1 y1... xn yn [option value option value ...]

The arguments x1 through yn give the coordinates for a series of two or more points that describe a series of connected line segments. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. The following options are supported for lines:

[51] -arrow where

(available only for line and spline item types)


Indicates whether or not arrowheads are to be drawn at one or both ends of the line. where must have one of the values "none" (for no arrowheads), "first" (for an arrowhead at the first point of the line), "last" (for an arrowhead at the last point of the line), or "both" (for arrowheads at both ends). This option defaults to "none".


[52] -arrowshape shape

(available only for line and spline item types)


This option indicates how to draw arrowheads. The shape argument must be a list with three elements, each specifying a distance. The first element of the list gives the distance along the line from the neck of the arrowhead to its tip. The second element gives the distance along the line from the trailing points of the arrowhead to the tip, and the third element gives the distance from the outside edge of the line to the trailing points. If this option isn't specified then Pad++ picks a "reasonable" shape.



[53] -capstyle cap

(available only for line and spline item types)

Specifies how the ends of the line are drawn. cap may be one of:

[54] -joinstyle join

(available only for line, polygon, rectangle and spline item types)

Specifies how the joints at vertices are drawn. join may be one of:

[55] -noisedata noisedata

(available only for line item types)

Specifies the noise parameters used to make rough-looking lines. noisedata is a four element list of numbers of the form:

"Pos Freq Amp Steps"

Rough lines are generated using the Perlin noise function. The Perlin noise function is like a sin function with a very irregular amplitude - like sin, noise has a constant period (one), but no two segments of the noise curve are alike. Noisy lines are generated by adding noise to the tangent direction of a line.

In the current implementation, there are four noise parameters: Pos, Freq, Amp, and Steps. Pos determines what part of the noise curve is sampled for that object. Freq determines the rate of sampling, Amp indicates the level, and Steps indicates how many samples to introduce per line segment. The drawing algorithm is straightforward. For each line segment, coordinates are generated as follows:

	DrawRoughLine(x1, y1, x2, y2, Pos, Freq, Amp, Steps) :
		step  = 1.0/Steps;
		mag   = length(x1,y1,x2,y2);
		theta = direction(x1,y1,x2,y2);

		xmag = Amp * sin(theta) * mag;
		ymag = Amp * cos(theta) * mag;

		vertex(x1, y1);

		for (a = step; a < steps; a += step) {
			n = noise(Pos);
			vertex(lerp(a,x1,x2) + n*xamp, lerp(a,y1,y2) + n*yamp);
			Pos += Freq;
		}
		vertex(x2, y2);

Note that we multiply Amp by mag, the length of the line. This is necessary in Pad++ since the zooming functionality means that lines can be of nearly any size. Making the level of noise proportional to the length of the line keeps the informality uniform at all sizes. (We should probably also modulate the number of points generated by the thickness of the line, so small thin lines are cheap).

Values of 0.3 for Freq, 0.1 for Amp, 10 for Steps produces pleasant-looking lines. Pos can be an arbitrary floating point number - giving different objects unique values for Pos ensures that each object has a different appearance.


[56] -pen color

(available only for handle, line, polygon, portal, rectangle, spline, text and textfile item types)

Color specifies a color to use for drawing the line; it may have any of the forms acceptable to Tk_GetColor. It may also be "none", in which case the line will not be drawn. This option defaults to black.

[57] -penwidth width

(available only for line, polygon, rectangle and spline item types)

Width specifies the width of the pen in current units to be drawn around the item. Wide lines will be drawn centered on the path specified by the points. If width is 0.0, then the pen will always be drawn one pixel wide, independent of the zoom. Width defaults to 1 pixel.


July 9, 1996 - 9 JUL 1996

Generated with Harlequin WebMaker

Web Accessibility