EuAndreh
EuAndreh

Reputation: 578

How to write programmatically lines with regular angle between them in PostScript?

I was trying to go a little bit beyond in my PostScript skills and tried to write 12 phrases with 30 of angle between them.

I don't really know how to name the problem, so the title is a bit weird...

Here is where I came so far:

%!
/Times-Roman findfont 20 scalefont setfont
/r 360 12 / def

306 396 translate
0 0 moveto
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

0 0 moveto
30 rotate
(text) show

showpage

But there are some problems with this code:

  1. it uses explicit steps instead of an iteration (although it works)
  2. all the text overwrites the others in the middle

Any help?

Upvotes: 1

Views: 76

Answers (2)

lhf
lhf

Reputation: 72332

As suggested by KenS, all the code between translate and showpage can be replaced by:

12 { 0 0 moveto (text) show 30 rotate } repeat

If you want to avoid overlaps, use this for instance:

12 { 50 0 moveto (text) show 30 rotate } repeat

Upvotes: 2

KenS
KenS

Reputation: 31199

You can use for or loop instead of explicitly coding each step.

Since you are starting each line of text from the same location then yes, the initial glyphs will partially overlap. Its not obvious to me what you want to happen in that case, there are two options I can immediately think of :

1) erase the underlying area to white then write the text

2) start the text at an offset so that the initial glyphs don't overlap.

You can do 1 by using charpath and pathbbox to determine the co-ordinates of the text bounding box, then convert those to a rectangle and fill it with white.

You can do 2 by determining the height of the initial glyph, again charpath pathbbox is your friend, then multiply by 'n' (where n is the number of iterations) to give you an approximation to the circumference of a circle round which all the initial glyphs will fit. Then work out the radius of that circle using simple geometry, use 0 moveto instead of 0 0 moveto before you draw the text.

Upvotes: 2

Related Questions