[Therion] metapost help - line Blocks

Andrew Atkinson andrew at wotcc.org.uk
Mon Sep 21 09:39:45 CEST 2015


I think this started life at the AUT line symbol for Blocks. My metapost
is at the stage where I can just about edit it to get small changesm but
that is about it.

With the AUT symbol you got blocks at funny angle when going round a
tight curve, I think this was because it took it angle from the start of
the place that it was drawing the block, so I added the st variable as
well as reducing the randomness of the angle. I also increased the
length of the blocks, plus added an extra point on the block and added a
bit of space between. All well and good, but now occasionally, probably
about 1/4 of the time, the last block in a line is drawn on top of the
second last block in a line then a space the size of the last bock is
left. No idea why this should be controlled by position t which is the
same as the rest of the blocks that work fine.

If anyone could help solve this I would be most greatful, trying to
print the survey for HE in 5 days time, so printing needs to be sent off
asap

thanks Andrew

def l_wall_blocks_CHED (expr P) =

  T:=identity;
  pickup PenC;
  laenge := arclength P;

  path block;
  path old_block;

  cur := 0;


  #draw first block
  old_block := punked ((
(.65u,-.15u)--(.72u,0.05u)--(.55u,.15u)--(.23u,.17u)--(.0u,.03u)--(.05u,-.1u))randomized
(0.1u))
             scaled (uniformdeviate(0.3)+.65);
  block_width := (xpart urcorner old_block - xpart ulcorner old_block);
  t:= arctime (cur+block_width/2) of P;
  old_block:=old_block rotated angle( direction t of P) shifted point 0
of P;
  thclean (old_block--cycle);
  thdraw old_block;


  cur := cur + block_width + 0.04u;

  forever:
    # generate random block
    block := punked (
((.65u,-.15u)--(.72u,0.05u)--(.55u,.15u)--(.2u,.17u)--(.0u,.03u)--(.05u,-.1u)
)
          randomized (0.1u) )
           scaled (uniformdeviate(0.3)+.65)
          rotated (uniformdeviate(20)-10);
    # check width of block
    block_width := (xpart urcorner block - xpart ulcorner block);

    exitif cur > (laenge- 3*block_width/2);
    # find next position where the block fits in without intersecting
the previous one
    forever:
      exitif xpart ( ((block--cycle) rotated angle(direction t of P)
shifted point t of P) intersectiontimes old_block) < 0;
      cur:=cur+0.01u;
      t:= arctime cur of P;
      st:= arctime (cur+block_width/2) of P;
      exitif cur > (laenge- 3*block_width/2);
    endfor;
    exitif cur > (laenge- 3*block_width/2);

    old_block:= block rotated angle(direction st of P) shifted point t of P;
    thclean (old_block--cycle);
    thdraw old_block;

  cur := cur + block_width + 0.04u;

  endfor;

    # generate last block

    block :=
(((.65u,-.15u)--(.72u,0.05u)--(.55u,.15u)--(.2u,.17u)--(.0u,.03u)--(.05u,-.1u))
);
    block_width := (xpart urcorner block - xpart ulcorner block);

    # scale last block to fit in the remaining gap
    scale_factor:=(laenge-cur)/block_width;
      t:= arctime cur of P;
      st:= arctime (laenge+cur)/2 of P;
    forever:
	  exitif scale_factor < 0;
      exitif xpart ( ( (block) rotated angle (direction st of P) scaled
scale_factor shifted (point t of P) ) intersectiontimes old_block) < 0;
      scale_factor:=scale_factor-0.001;
    endfor;
    if scale_factor > 0:
      thclean (block--cycle) rotated angle (direction st of P) scaled
scale_factor shifted (point t of P);
      thdraw (block) rotated angle (direction st of P) scaled
scale_factor shifted (point t of P);
    fi;
enddef;

    initsymbol ("l_wall_blocks_CHED");



More information about the Therion mailing list