On Mon, 24 Aug 2009 20:14:52 +1000 (EST)
"damien dunlop" <[email protected]> wrote:

| Thanks to Anthony for the original response to
| `Arrow Heads'. I found the SVG method not entirely
| satisfactory and then other issues became more important.
| 
| # A specific arrow can always be drawn on an image
| # by calculation of the coordinates of a rotated triangle
| # of an appropriate size and then using the -draw option
| # to draw it. To have to do this every time is a nuisance.
| 
| # It would be somewhat better if one could draw a standard
| # arrow then use the the -rotate and -scale options to
| # create the arrow required for any specific application.
| 
| # The following illustrates an incomplete approach.
| # When an arrow is not drawn directly on an image, but
| # is drawn as a standard arrow on its own canvas and then
| # rotated and scaled before being pasted onto an image, the
| # arrow canvas needs to be transparent so as not to obscure
| # those parts of the image under the arrow canvas.
| # The example below does not obscure the background colour,
| # but it does obscure the horizontal lines drawn on the
| # background.
| 
| # In addition to problems relating to transparency, the
| # following also illustrates one or two other anomalies.
| # One such is the region of the -region option does not
| # seem to rotate around its NW corner.
| 
| # Can the following be fixed or some other method be
| # used to create and work with a standard arrow?
| 
| convert -size 300x300 xc:skyblue \
|         -fill yellow \
|         -draw 'line 10,50 290,50' \
|         -draw 'line 10,150 290,150' \
|         -draw 'line 10,250 290,250' \
|         -fill red -draw 'rectangle 100,100 182,250' \
|         -channel A -transparent red \
|      \( -region 82x150+100+100 \
|         -fill black \
|         -draw 'polyline 41,150 41,100 82,100 41,0 0,100 41,100' \
|         -rotate 30 -scale 50x50 \) \
|         -flatten arrow.gif
| 

As I mentioned in the previous email, their is no need for a separate
canvas, regions, etc.

First an arrow definition...
   arrow="l -5,+15  +5,-5  +5,+5  -5,-15 z"

Now to draw an arrow...

   convert -size 100x100 xc:  -draw 'line 50,90 50,20' \
        -draw "stroke blue fill skyblue path 'M 50,20  $arrow' " \
        show:

The arrow definition is to draw an arrow starting at the end of the just
draw line  (the 0,0 point is the tip of the arrow) straight downward.

Now if you want to rotate the arrow, simple, add some canvas warping...

  arrow="l -5,+15  +5,-5  +5,+5  -5,-15 z"

  convert -size 100x100 xc:  -draw 'line 10,90 80,20' \
          -draw "translate 80,20 rotate 45
                 stroke blue fill skyblue
                 path 'M 0,0  $arrow' 
                " \
          show:

If you like to change the size of the arrow,  add a "scale" draw option.
after the rotate.

  convert -size 100x100 xc:  -draw 'line 10,90 80,20' \
          -draw "translate 80,20 rotate 45 scale 2,2
                 stroke blue fill skyblue
                 path 'M 0,0  $arrow' 
                " \
          show:

You can even scale the width separately to the arrows length!


Now as you are warping the canvas for individual arrows, and doing many
other draws, you may like to do the draws all in one -draw operation.  Say
draw the line and add arrows at BOTH ends, requiring different translation
rotation and scale.

That means we need to limit the scope of the canvas warp to each individual
arrow.  defining that arrows  location and rotation...

This limiting is done with a graphic context...

  arrow="l -5,+15  +5,-5  +5,+5  -5,-15 z"

  convert -size 100x100 xc: \
          -draw "stroke black   fill none   line 20,80 80,20
                 push graphic-context
                   translate 80,20 rotate 45
                   stroke blue fill skyblue
                   path 'M 0,0  $arrow'
                 pop graphic-context
                 push graphic-context
                   translate 20,80 rotate 225 scale 2,2
                   stroke blue fill skyblue
                   path 'M 0,0  $arrow'
                 pop graphic-context 
                " \
          show:

You can even put all the draws into a MVG file and have IM just convert
the image!


See Reading MVG files
  http://www.imagemagick.org/Usage/draw/#reading

For more exampels look at the official ImageMagick draw documentation
   http://www.imagemagick.org/script/magick-vector-graphics.php


Of course the above is now being added to the  Draw Symbols section
of IM Examples  (give it a few hours)

    http://www.imagemagick.org/Usage/draw/#arrows



  Anthony Thyssen ( System Programmer )    <[email protected]>
 -----------------------------------------------------------------------------
   And then you turn the corner, as the Dungeon Master chuckles...
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to