Drawing on the slate -- Shapes
Each picture has a reference to an object called a shape;
the shape allows pictures to be manipulated in more symbolic ways than
just using coords. Have a look at the "shape" option of a few
pictures:
puts ""
puts "\$frame has shape \"[$frame cget -shape]\""
puts "\$polygon has shape \"[$polygon cget -shape]\""
puts "\$line has shape \"[$line cget -shape]\""
puts "\$arrow has shape \"[$arrow cget -shape]\""
puts "\$image has shape \"[$image cget -shape]\""
puts "\$oval has shape \"[$oval cget -shape]\""
Notice that the simple polygon, the pseudo-3D polygon, and the line
all have the same shape. Shapes are re-usable between objects -- the
``shape'' of an object can even be dynamically changed! Notice also
that the oval has no shape -- this is because the circular
shape has not been implemented yet.
A shape gives a picture a number of aspects -- and aspect
is basically a named property of the picture. It is usually a
coordinate on the picture, although it does not have to be.
To find out what aspects a picture has, just ask it:
puts ""
puts "\$frame has aspects [$frame aspect query]"
puts "\$arrow has aspects [$arrow aspect query]"
puts "\$line has aspects [$line aspect query]"
To get the value of an aspect, pass the aspect name to the
aspect operation:
puts ""
puts "The north-east corner of \$frame is at [$frame aspect ne]"
puts "The third vertex of \$arrow is at [$arrow aspect vertex 2]"
Ok, now we've got that out of the way, let's see what we can do with
it. Firstly, aspects allow pictures to be moved to absolute
coordinates. Suppose I want the south-west corner of the frame to
coincide with the north-east corner of the image. Here is what I do:
eval $frame move absolute sw [$image aspect ne]
This works [or should -- there may be some bugs still] for all
aspects. For example, to move the start of the line to the north-east
corner of the frame:
eval $line move absolute {vertex 0} [$frame aspect ne]
Pictures can also be reshaped with the deform operation, which
takes the name of an aspect and the amount to deform it by. For
example:
$frame deform ne 20 -10
In the case of rectangular shapes, the edge aspects (n,
s, e, w) only notice the appropriate x or
y value:
$frame deform e 20 -10
Deformation can also move an aspect to absolute coordinates:
$frame deform absolute ne 200 100
Notice that the line attached to the frame did not move. We can deform
the line now, so that the start of it is on the northest corner of the
frame:
eval $line deform absolute vertex 0 [$frame aspect ne]
If the line is always supposed to stay ``attached'' to the corner of
the frame, VL Toolkit can do it for you automatically, using a
mechanism called constraints (explained later).
More to come: more on vertices, circular shapes, named points.
Next