Page 1 sur 1

le module patterns

Posté : sam. 30 mars 2019, 18:41
par malaka
Bonjour, je cherche une documentation sur ce module. Je trouve peu d'exemples de son utilisation sur le net et la doc officiel :
8.8 patterns
This package implements Postscript tiling patterns and includes several convenient pattern
generation routines.
n'est pas très parlante.

Même en cherchant avec les mots clés Postscript tiling patterns je ne trouve rien de très éclairant.
Si quelqu'un a une piste de doc qui permettrait de dépasser l'adaptation des hachures je suis preneur.
Merci d'avance.

Re: le module patterns

Posté : sam. 30 mars 2019, 22:49
par GM
Bonsoir,

le contenu du fichiers patterns.asy est le suivant :

Code : Tout sélectionner

// Create a tiling named name from picture pic
// with optional left-bottom margin lb and right-top margin rt.
frame tiling(string name, picture pic, pair lb=0, pair rt=0)
{
  frame tiling;
  frame f=pic.fit(identity());
  pair pmin=min(f)-lb;
  pair pmax=max(f)+rt;
  string s="%.6f";
  postscript(tiling,"<< /PaintType 1 /PatternType 1 /TilingType 1 
/BBox ["+format(s,pmin.x,"C")+" "+format(s,pmin.y,"C")+" "+
             format(s,pmax.x,"C")+" "+format(s,pmax.y,"C")+"]
/XStep "+format(s,pmax.x-pmin.x,"C")+"
/YStep "+format(s,pmax.y-pmin.y,"C")+"
/PaintProc {pop");
  add(tiling,f);
  postscript(tiling,"} >>
 matrix makepattern
/"+name+" exch def");
  return tiling;
}

// Add to frame preamble a tiling name constructed from picture pic
// with optional left-bottom margin lb and right-top margin rt.
void add(string name, picture pic, pair lb=0, pair rt=0)
{
  add(currentpatterns,tiling(name,pic,lb,rt));
}

picture tile(real Hx=5mm, real Hy=0, pen p=currentpen,
             filltype filltype=NoFill)
{
  picture tiling;
  if(Hy == 0) Hy=Hx;
  path tile=box((0,0),(Hx,Hy));
  tiling.add(new void (frame f, transform t) {
      filltype.fill(f,t*tile,p);
    });
  clip(tiling,tile);
  return tiling;
}

picture checker(real Hx=5mm, real Hy=0, pen p=currentpen)
{
  picture tiling;
  if(Hy == 0) Hy=Hx;
  path tile=box((0,0),(Hx,Hy));
  fill(tiling,tile,p);
  fill(tiling,shift(Hx,Hy)*tile,p);
  clip(tiling,box((0,0),(2Hx,2Hy)));
  return tiling;
}

picture brick(real Hx=5mm, real Hy=0, pen p=currentpen)
{
  picture tiling;
  if(Hy == 0) Hy=Hx/2;
  path tile=box((0,0),(Hx,Hy));
  draw(tiling,tile,p);
  draw(tiling,(Hx/2,Hy)--(Hx/2,2Hy),p);
  draw(tiling,(0,2Hy)--(Hx,2Hy),p);
  clip(tiling,box((0,0),(Hx,2Hy)));
  return tiling;
}

real hatchepsilon=1e-4;
picture hatch(real H=5mm, pair dir=NE, pen p=currentpen) 
{
  picture tiling;
  real theta=angle(dir);
  real s=sin(theta);
  real c=cos(theta);
  if(abs(s) <= hatchepsilon) {
    path g=(0,0)--(H,0);
    draw(tiling,g,p);
    draw(tiling,shift(0,H)*g,p);
    clip(tiling,scale(H)*unitsquare);
  } else if(abs(c) <= hatchepsilon) {
    path g=(0,0)--(0,H);
    draw(tiling,g,p);
    draw(tiling,shift(H,0)*g,p);
    clip(tiling,scale(H)*unitsquare);
  } else {
    real h=H/s;
    real y=H/c;
    path g=(0,0)--(h,y);
    draw(tiling,g,p);
    draw(tiling,shift(-h/2,y/2)*g,p);
    draw(tiling,shift(h/2,-y/2)*g,p);
    clip(tiling,box((0,0),(h,y)));
  }
  return tiling;
}

picture crosshatch(real H=5mm, pen p=currentpen)
{
  picture tiling;
  add(tiling,hatch(H,p));
  add(tiling,shift(H*sqrt(2))*rotate(90)*hatch(H,p));
  return tiling;
}

Donc on y trouve :
  • Code : Tout sélectionner

    // Create a tiling named name from picture pic
    // with optional left-bottom margin lb and right-top margin rt.
    frame tiling(string name, picture pic, pair lb=0, pair rt=0)
  • Code : Tout sélectionner

    // Add to frame preamble a tiling name constructed from picture pic
    // with optional left-bottom margin lb and right-top margin rt.
    void add(string name, picture pic, pair lb=0, pair rt=0)
    Dans sa définition, on y voit l'ajout de la frame produite par tiling() (un tuilage nommé) à la frame currentpatterns qui est définie dans plain_shipout.asy.
  • Code : Tout sélectionner

    picture tile(real Hx=5mm, real Hy=0, pen p=currentpen,
                 filltype filltype=NoFill)
  • Code : Tout sélectionner

    picture checker(real Hx=5mm, real Hy=0, pen p=currentpen)
  • Code : Tout sélectionner

    picture brick(real Hx=5mm, real Hy=0, pen p=currentpen)
  • Code : Tout sélectionner

    picture hatch(real H=5mm, pair dir=NE, pen p=currentpen) 
  • Code : Tout sélectionner

    picture crosshatch(real H=5mm, pen p=currentpen)
et la doc dit cela :
Image


Que veut dire "Dépasser l'adaptation des hachures" ?

Re: le module patterns

Posté : dim. 31 mars 2019, 10:18
par GM
GM a écrit :
sam. 30 mars 2019, 22:49
Que veut dire "Dépasser l'adaptation des hachures" ?
Si c'était une façon indirecte de demander comment on peut créer d'autres motifs, il faut regarder comment sont définis les différents motifs existants.

J'en rajoute deux nouveaux :

Figure asymptote fa62ab00d4e427ed23edf7fde7975f25
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1. unitsize(1cm);
  2.  
  3. import patterns;
  4.  
  5. picture triangles(real Hx=5mm, real Hy=0, pen p=currentpen)
  6. {
  7. picture tiling;
  8. if(Hy == 0) Hy=Hx;
  9. draw(tiling,(3Hx/4,0)--(0,Hy/2)--(Hx/2,Hy/2)--cycle,p);
  10. return tiling;
  11. }
  12.  
  13. picture flocons(real Hx=2mm, real Hy=0, pen p=currentpen)
  14. {
  15. picture tiling;
  16. if(Hy == 0) Hy=Hx;
  17. fill(tiling,box((0,0),(2Hx,2Hy)),white);
  18. draw(tiling,shift(Hx/2,Hx/2)*scale(Hx/2)*cross(8,round=true,r=0.3),p);
  19. clip(tiling,box((0,0),(2Hx,2Hy)));
  20. return tiling;
  21. }
  22.  
  23. add("PapierTriangles",triangles(red));
  24. add("PapierFlocons",flocons(blue+linewidth(.3)));
  25.  
  26. filldraw((0,0)--(5,2)--(1,4)--cycle,pattern("PapierTriangles"));
  27. filldraw(shift(5,0)*((0,0)--(5,2)--(1,4)--cycle),pattern("PapierFlocons"));

Re: le module patterns

Posté : dim. 31 mars 2019, 10:31
par malaka
Merci beaucoup c'est exactement ça que je cherchais. J'avais trouvé cette page de doc mais pas le fichier patterns.asy. :oops:
Quant à ma question indirecte, c'est bien comme tu l'as compris. Il ne reste plus qu'à me plonger dedans. :geek:
Encore merci.

Re: le module patterns

Posté : dim. 31 mars 2019, 11:23
par GM
NB : j'ai ajouté des "flocons".

Je retourne à mes copies.