mmj:202

Tip: The syntax for the symbol-assign with subtypes is using a colon:

symbol-assign line wall:blocks MY_SYMBOL

Exemple of code (for small cave) :

    def l_wall_blocks_XXX (expr P) = 
    %  pickup PenD;
    %  draw P withcolor red;

      T:=identity;
      cas := 0;
      dlzka := arclength P;
      if dlzka > 0:
        mojkrok:=adjust_step(dlzka, 0.75u);
        pickup PenA;
        forever:
          t1 := arctime (cas + mojkrok*1/10) of P;
          t2 := arctime (cas + mojkrok*9/10) of P;
          q := ((point t1 of P) + .3u * unitvector(thdir(P,t1) rotated -90)) --
             (subpath (t1,t2) of P) --
             ((point t2 of P) + .3u * unitvector(thdir(P,t2) rotated -90));
          thdraw q randomized (u/6);
          cas := cas + mojkrok;
          exitif cas > dlzka - (2*mojkrok/3); % for rounding errors
        endfor;
      fi;
    enddef;
    initsymbol("l_wall_blocks_XXX");
    symbol-assign line wall:blocks XXX
  endcode

Default values where :

        mojkrok:=adjust_step(dlzka, 1.5u);

          q := ((point t1 of P) + .4u * unitvector(thdir(P,t1) rotated -90)) --
             (subpath (t1,t2) of P) --
             ((point t2 of P) + .4u * unitvector(thdir(P,t2) rotated -90));

An other exemple by Georges :

def l_wall_blocks_AUT (expr P) =

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

  path block;
  path old_block;

  cur := 0;
  t:= arctime cur of P;

  % draw first block
  old_block := (
(.7u,-.35u)--(.85u,0.01u)--(.4u,.5u)--(.1u,.3u)--(-.0u,-.0u) );
  block_width := (xpart urcorner old_block - xpart ulcorner old_block);
  old_block:=old_block rotated angle( thdir(P,0) ) shifted point t of P;
  thclean (old_block--cycle);
  thdraw old_block;


  cur := cur + block_width/2;
  t:= arctime cur of P;
  forever:
    % generate random block
    block := punked ( (
(.8u,-.35u)--(.85u,0.01u)--(.6u,.4u)--(.1u,.1u)--(-.0u,-.3u) )
          randomized (0.3u) )
           scaled (uniformdeviate(0.3)+.65)
          rotated (uniformdeviate(45)-15);
    % check width of block
    block_width := (xpart urcorner block - xpart ulcorner block);

    exitif cur > (laenge- 3.5*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;
      exitif cur > (laenge- 3.5*block_width/2);
    endfor;
    exitif cur > (laenge- 3.5*block_width/2);

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


    cur := cur + block_width/2;
    t:= arctime cur of P;
  endfor;

    % generate last block
    t:= arctime laenge-eps of P;
    block := ((
(-.15u,-.35u)--(.0u,.0u)--(-.45u,.5u)--(-.75u,.3u)--(-.85u,-.0u)) );
    block_width := (xpart urcorner block - xpart ulcorner block);
    % scale last block to fit in the remaining gap
    scale_factor:=(laenge-cur)/block_width;
    forever:
      exitif xpart ( ( (block) rotated angle (direction t of P) scaled scale_factor shifted (point t of P) ) intersectiontimes old_block) < 0;
      scale_factor:=scale_factor-0.001;
    endfor;

    thclean (block--cycle) rotated angle (direction t of P) scaled scale_factor shifted (point t of P);
    thdraw (block) rotated angle (direction t of P) scaled scale_factor shifted (point t of P);

enddef;
  • mmj/202.txt
  • Last modified: 15 years ago
  • by 127.0.0.1