Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
metapost [2018/05/16 10:34]
sluka [How to create metapost for new symbols]
metapost [2019/01/03 17:00] (current)
andrew.atkinson [MetaPost] - Added online previewer
Line 10: Line 10:
 [[http://​tex.loria.fr/​english/​prod-graph.html|Page with many links to Metapost documentation and examples]]\\ [[http://​tex.loria.fr/​english/​prod-graph.html|Page with many links to Metapost documentation and examples]]\\
 [[http://​staff.science.uva.nl/​~heck/​Courses/​mptut.pdf|Learning METAPOST by Doing, André Heck]] (pdf)\\ [[http://​staff.science.uva.nl/​~heck/​Courses/​mptut.pdf|Learning METAPOST by Doing, André Heck]] (pdf)\\
-[[http://​tex.loria.fr/​formats/​context/​metafun-p.pdf|Loria:​ The Metafun manual, Hans Hagen, ​2000]] (pdf)\\ +[[http://​tex.loria.fr/​formats/​context/​metafun-p.pdf|Loria:​ The Metafun manual, Hans Hagen, ​2017]] (pdf)\\ 
-or: [[http://​www.pragma-ade.com/​general/​manuals/​metafun-p.pdf|Pragma:​ The Metafun manual, Hans Hagen, ​2000]] (pdf)\\+or: [[http://​www.pragma-ade.com/​general/​manuals/​metafun-p.pdf|Pragma:​ The Metafun manual, Hans Hagen, ​2017]] (pdf)\\
 [[http://​tex.loria.fr/​prod-graph/​metafun.pdf|Puzzling graphics in METAPOST, Hans Hagen]] (pdf)\\ [[http://​tex.loria.fr/​prod-graph/​metafun.pdf|Puzzling graphics in METAPOST, Hans Hagen]] (pdf)\\
 [[http://​tex.loria.fr/​prod-graph/​zoonekynd/​metapost/​metapost.html|Many nice examples]]\\ [[http://​tex.loria.fr/​prod-graph/​zoonekynd/​metapost/​metapost.html|Many nice examples]]\\
 [[http://​http://​bbs.ctex.org/​forum.php?​mod=viewthread&​tid=16444|Many links from Michio Matsuyama]],​ but you have to copy the text and open it as html file\\ [[http://​http://​bbs.ctex.org/​forum.php?​mod=viewthread&​tid=16444|Many links from Michio Matsuyama]],​ but you have to copy the text and open it as html file\\
 +
 +==== Previewers ====
 +
 +[[http://​www.tlhiv.org/​mppreview/​|Online previewer]]
 [[http://​cseweb.ucsd.edu/​~s1pan/​MEPer/​|Java based MetaPost Editor and Previewer (MEPer)]] [[http://​cseweb.ucsd.edu/​~s1pan/​MEPer/​|Java based MetaPost Editor and Previewer (MEPer)]]
  
Line 406: Line 410:
 ---- ----
  
 +====  Line - Hand Rail ====
 +
 +
 +{{:​metapost:​rails.png|Rails}}
 +
 +  def l_u_rail (expr P) = 
 +  T:​=identity;​
 +  cas := 0;
 +  dlzka := arclength P;
 +  mojkrok:​=adjust_step(dlzka,​ 0.8u);
 +  pickup PenC;
 +  forever:
 +    t0 := arctime (cas) of P;
 +    t1 := arctime (cas + mojkrok*2/​5) of P;
 +    t  := arctime (cas + mojkrok/2) of P;
 +    t4 := arctime (cas + mojkrok*3/​5) of P;
 +    t5 := arctime (cas + mojkrok) of P;
 +    thdraw (subpath (t0,t1) of P);
 +    thdraw (subpath (t4,t5) of P);
 +    drawdot
 +       ​(point t of P);
 +    #mark_ (P,​t,​0.02u);​
 +    #mark_ (P,​t,​-0.02u);​
 +     #f := (P,t,0.2u);
 +     #draw f;
 +    cas := cas + mojkrok;
 +    exitif cas > dlzka - (2*mojkrok/​3);​ % for rounding errors
 +  endfor;
 +  enddef;
 + 
 + 
 +  initsymbol("​l_u_rail"​)
 +
 +Andrew Atkinson
 =====Cave Symbol Size and Density Examples===== =====Cave Symbol Size and Density Examples=====
 **Modification MetaPost code for NSS (Philip Schuchardt)** **Modification MetaPost code for NSS (Philip Schuchardt)**
Line 1326: Line 1364:
  
  
 +
 +----
 +----
 +====== Customisable Area Blocks with Different Number of Sides ======
 +
 +
 +{{:​metapost:​boulder.jpg?​300|Boulders shown as produced by default settings}}
 +
 +Blocks shown as produced by default settings, at about half scale.
 +
 +Various things could be improved, the drawing of the different sided boulders, and calling of thclean qq; three times to stop transparency cannot be the best way.
 +
 +**Code for blocks, Variables can be amended at the start**
 +    initsymbol("​a_blocks_BCA"​);​
 +    ​
 +    def a_blocks_BCA (expr p) =
 +  T:​=identity;​
 +  symbol_distance:​=0.7;​ % Distance between the blocks as set out in a rectangular grid
 +  block_randomisation:​=0.7;​ % Max each point of the base block can be moved. Too big and they can intersect themselves
 +  base_rotation:​= 0; % Rotation from 0 of base block, can be used to set all blocks to the same angle
 +  random_rotation:​= 360; % Rotation either side of base rotation eg 20 will be plus or minus 10 each side
 +  min_scale_factor:​=0.7;​ % Minimum multiplier used for the base shape
 +  add_scale_factor:​= 0.6; % Added to the minimum multiplier to get the maximum scale
 +  block_rectangle:​=1.5;​ % How much longer the block is than it is wide, before randomising
 +  shift_randomisation:​=0.75;​ % Max random amount block can be moved from the original grid
 +  %Now set the proportions of different sided block
 +  b_tri:=1;
 +  b_quad:=3;
 +  b_pent:=4;
 +  b_hex:=2;
 +  pickup PenC;
 + path q, regular, qq; q = bbox p;
 + pair outside;
 + outside:= ulcorner q + up;
 + picture tmp_pic; ​
 + uu := max(u, (xpart urcorner q - xpart llcorner q)/100, (ypart urcorner q - ypart     ​llcorner q)/100);
 + iu := uu * block_rectangle;​
 + blocks := b_tri+b_quad + b_pent + b_hex;
 + tmp_pic := image(
 +    for i = xpart llcorner q step symbol_distance * block_rectangle * uu until xpart urcorner q:
 +       for j = ypart llcorner q step symbol_distance*uu until ypart urcorner q:
 +         pick_sides := uniformdeviate(blocks);​
 +         if pick_sides < b_tri:
 +         sides:=3;
 +         elseif pick_sides < b_tri + b_quad:
 +         sides:=4;
 +         elseif pick_sides < b_tri + b_quad +b_pent:
 +         sides:=5;
 +         else:
 +         sides:=6
 +         fi;
 +  ​
 +           qq :=  for n:=0 upto sides-1:
 +                   ((cosd(360*n/​sides))*iu/​2,​(sind(360*n/​sides))*uu/​2) -- 
 +                             endfor cycle; %radius is 0.5 divide by 2
 +           qq := punked ((qq) 
 +           randomized (block_randomisation * uu))
 +           scaled (uniformdeviate(add_scale_factor)+min_scale_factor)
 +           rotated (base_rotation + random_rotation / 2 - uniformdeviate(random_rotation) )
 +           shifted ((i,j) randomized (shift_randomisation * uu));
 +          
 +          
 +           forever: % Repeatedly reduces the size of the image, as this is done round zero it also moves it to the zero location, until it fits in the area
 +            ​exitif xpart (p intersectiontimes qq) < 0;
 +            qq:= qq scaled (0.99 );
 +           endfor;
 +             if pointinside((i,​j),​p,​outside):​ % Cleans lines on border, assumably ones outside with jut an edge touching
 +                ​thclean qq;
 +                ​thclean qq;
 +                ​thclean qq;
 +                ​thclean qq;
 +                ​thdraw qq;
 +             fi;
 +       endfor;  ​
 +    ​endfor;​
 + );
 + clip tmp_pic to p;
 + drawoptions();​
 + draw tmp_pic;
 + enddef;
 +
 +The base_rotation is an attempt to produce bedding plane breakdown, it could do with more time but this is possible
 +
 +{{:​metapost:​bedding.jpg?​300|Bedding breakdown produced with settiing below}}
 +
 +using the settings
 +
 +  symbol_distance:​=0.5;​ % Distance between the blocks as set out in a rectangular grid
 +  block_randomisation:​=0.7;​ % Max each point of the base block can be moved. Too big and they can intersect themselves
 +  base_rotation:​= 20; % Rotation from 0 of base block, can be used to set all blocks to the same angle
 +  random_rotation:​= 5; % Rotation either side of base rotation eg 20 will be plus or minus 10 each side
 +  min_scale_factor:​=0.5;​ % Minimum multiplier used for the base shape
 +  add_scale_factor:​= 0.6; % Added to the minimum multiplier to get the maximum scale
 +  block_rectangle:​=7;​ % How much longer the block is than it is wide, before randomising
 +  shift_randomisation:​=0.75;​ % Max random amount block can be moved from the original grid
 +  %Now set the propotions of different sided block
 +  b_tri:=1;
 +  b_quad:=2;
 +  b_pent:=4;
 +  b_hex:=7;
 +
 +
 +Andrew Atkinson
  
 ---- ----
Line 1414: Line 1555:
       ​       ​
 {{:​metapost:​fault.png?​250|}} {{:​metapost:​fault.png?​250|}}
 +
 +
 +===== Shell limestone =====
 +Point symbol for shell limestone:
 +
 +  def p_u_shell (expr pos,​theta,​sc,​al)=
 +    T:=identity shifted pos;
 +    pickup PenB;
 +    numeric turns, radius;
 +    path ss, cesta;
 +    pair za, zb;
 +    turns = 1.55;
 +    radius = .3u;
 +    za = ( xpart(origin)+0,​ ypart(origin)+.1u ) rotated 370 turns;
 +    zb = ( xpart(origin)+.3u,​ ypart(origin)+0 ) rotated 360 turns;
 +    cesta := za--zb;
 +    ss := (origin for t=1 upto 360 turns: -- dir t scaled t endfor) scaled (radius/​turns/​360);​
 +    thdraw ss withcolor (0.3);
 +    thdraw (cesta cutbefore ss) withcolor (0.3);
 +  enddef;
 +      ​
 +{{:​metapost:​shell.png?​250|}}
  • metapost.1526459685.txt.gz
  • Last modified: 9 months ago
  • by sluka