home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / tess / tess-1.0 / aGroup.pswm-old < prev    next >
Encoding:
Text File  |  1992-06-30  |  5.5 KB  |  275 lines

  1. #import "aGroup.h"
  2. #import "aGroup-inter.h"
  3. #import "TessSketch.h"
  4. #import "Underlay.h"
  5.  
  6. @implementation aGroup
  7.  
  8. +new 
  9. {
  10.   self = [super new];
  11.   [self setScaling: 1.0 : 1.0];
  12.   return self;
  13. }
  14.  
  15. + setup
  16. {
  17.   GroupSetup();                    // call only once
  18.   return self;
  19. }
  20.  
  21. - performTesselation: sender
  22. {
  23.   id imgview,outview,outimg;
  24.   NXPoint pt,genofft;
  25.   NXSize lsize;
  26.   NXRect outrect;
  27.   float xstart;
  28.   int xlimit,ylimit;
  29.   
  30.   outview = [sender getOutputView];
  31.   outimg = [outview getImage];
  32.   [self getLatticeUnitSize: &lsize];
  33.   [sender getImageView:&imgview withOffset: &genofft];
  34.   if(![outimg lockFocus]) fprintf(stderr,"Couldn't lock outimg focus\n");
  35.   PSgsave();
  36.   PSscale(xscaling,yscaling);
  37.   [outview getFrame: &outrect];
  38. #ifdef DEBUG
  39.   fprintf(stderr,"Output rect: %f,%f,%f,%f\n",outrect.origin.x,outrect.origin.y,
  40.       outrect.size.height,outrect.size.width);
  41. #endif
  42.   
  43.   pt.x = pt.y = 0.0;
  44.   ylimit = (int)(outrect.size.height/lsize.height) + 2;
  45.   do {
  46.     PSmoveto(0.0,0.0);
  47.     if(ylimit%2){
  48.       pt.x -= lsize.width;        /* adjust back for rhombic & poly case*/
  49.     } 
  50.     xlimit = (int)(outrect.size.width/lsize.width) + 4;
  51.     xstart = pt.x;
  52.     do{
  53. #ifdef 0
  54.       fprintf(stderr,"Current point %f,%f: xlimit %d\n",pt.x,pt.y,xlimit);
  55. #endif
  56.       PSgsave();
  57.       PStranslate(pt.x,pt.y);
  58.       [self makeLatticeUnitAt: &genofft fromImage: [imgview getImage]];
  59.       PSgrestore();
  60.       [self rightTranslatePoint: &pt];
  61.     } while (xlimit--);
  62.     pt.x = xstart;
  63.     [self upTranslatePoint: &pt];
  64.   } while (ylimit--);
  65.   PSgrestore();
  66.   [outimg unlockFocus];
  67.   return self;
  68. }
  69.  
  70. - generator: (NXCoord) x : (NXCoord) y
  71. {
  72.   [self clip: x : y];
  73.   PSstroke();
  74.   return self;
  75. }
  76.  
  77. - clip: (NXCoord) x: (NXCoord) y
  78. {
  79.   return self;
  80. }
  81. - (BOOL) isRigidLattice
  82. {
  83.   return YES;
  84. }
  85. - rightTranslatePoint: (NXPoint *) pt
  86. {
  87.   return self;
  88. }
  89.  
  90. - upTranslatePoint: (NXPoint *)pt
  91. {
  92.   return self;
  93. }
  94.  
  95. - (NXSize *)getLatticeUnitSize: (NXSize *) size
  96. {
  97.   size->width = latticesize.width;
  98.   size->height = latticesize.height;
  99.   return &latticesize;
  100. }
  101.  
  102. - setScaling: (float) xscale:(float) yscale
  103. {
  104.   xscaling = xscale;
  105.   yscaling = yscale;
  106.   return self;
  107. }
  108.  
  109. - (float) xscaling
  110.   return xscaling; 
  111. }
  112. - (float) yscaling
  113.   return yscaling; 
  114. }
  115. - drawImage
  116. {
  117.   [self sketchTemplate];
  118.   return self;
  119. }
  120. - sketchTemplate
  121. {
  122.   return self;
  123. }
  124. - makeLatticeUnitAt: (NXPoint *) point fromImage: srcimg 
  125. {
  126.   return self;
  127. }
  128. - (NXPoint *)getGeneratorOffset: (NXPoint *) pt
  129. {
  130.   pt->x = pt->y = 0.0;
  131.   return pt;
  132. }
  133.  
  134. - (NXSize *)getGeneratorSize: (NXSize *) size
  135. {
  136.   size->width = size->height = 0.0;
  137.   return size;
  138. }
  139.  
  140. @end
  141.  
  142. int genfun () {  return 1; }
  143. int clipper () { return 1; }
  144. int tesselate () { return 1;}
  145.  
  146. defineps GroupSetup()
  147.    /groupsdict 40 dict def
  148.    groupsdict begin
  149.        /equi { 3 sqrt mul 2 div } bind def
  150.        /generatorcolor {0.655171 0.102771 0.629475 setrgbcolor } bind def
  151.        /glidecolor {0.373226 0.462386 0.528733 setrgbcolor } bind def
  152.        /reflectioncolor {0.333338 0.039216 0.237907 setrgbcolor } bind def
  153.        /translationcolor {1 0.054903 0.101962 setrgbcolor       } bind def
  154.        /anglecolor { 0 0 1 setrgbcolor } bind def
  155.        /latticeunitcolor { 0.5 setgray } bind def
  156.        /scaling 1.0 def    
  157.  
  158.        /arrow { % angle x y
  159.        newpath moveto dup rotate 
  160.        -13 6 rlineto 4 -6 rlineto 
  161.        -4 -6 rlineto closepath gsave 0 
  162.        setlinejoin stroke grestore fill neg rotate
  163.        } def
  164.  
  165.        /addpoints { % x y x y
  166.           exch % x y y x
  167.           4 1 roll %  y y x x
  168.           add 3 1 roll % x y y
  169.           add % x y
  170.     } bind def
  171.  
  172.        /duptop2 { % x y -> x y x y
  173.        dup     %  x y y
  174.        3 2 roll % y y x
  175.        dup % y y x x    
  176.        4 1 roll % x y y x
  177.        exch % x y x y    
  178.        } bind def
  179.  
  180.        /even { % num
  181.        cvi 1 and 1 eq not
  182.        } bind def
  183.  
  184.        /setscaling { % scale - wrap with dictionary use !!!
  185. %       groupsdict begin       
  186. %           /scaling exch def    
  187. %           [scaling 0 0 scaling 0 0] setmatrix
  188. %       end           
  189.     pop
  190.        } bind def
  191.  
  192.        /reflect { % angle
  193.        dup rotate  
  194.        [1 0 0 -1 0 0] concat 
  195.        neg rotate     
  196.        }     bind def
  197.  
  198.        /rhombus { % x y 
  199.        groupsdict begin    
  200.            moveto
  201.            latticeunitcolor
  202.            lattice:side 0 lineto
  203.            lattice:w lattice:h rlineto
  204.            lattice:side neg 0 rlineto
  205.            closepath
  206.            stroke
  207.        end        
  208.        } bind def
  209.  
  210.        /transv0 { %x y len
  211.        groupsdict begin
  212.            gsave    
  213.            2 setlinewidth
  214.            translationcolor    
  215.            moveto dup 0 rlineto stroke    
  216.            0 exch 0 arrow
  217.            grestore    
  218.        end        
  219.        } bind def
  220.  
  221.        /transv90 { %x y len
  222.        groupsdict begin
  223.            gsave 
  224.            2 setlinewidth
  225.            translationcolor    
  226.            moveto dup 0 exch rlineto stroke    
  227.            90 exch 0 exch arrow
  228.            grestore    
  229.        } bind def
  230.  
  231.        /transv60 { %x y run rise
  232.        groupsdict begin
  233.            gsave 
  234.            2 setlinewidth
  235.            translationcolor    
  236.            moveto 
  237.            duptop2    
  238.            rlineto stroke    
  239.            60 3 1 roll % angle of arrow
  240.            arrow
  241.            grestore    
  242.        end        
  243.        } bind def
  244.  
  245.        /reflectionaxis { % x1 y1 x2 y2
  246.        groupsdict begin    
  247.            reflectioncolor
  248.            moveto rlineto stroke    
  249.        end
  250.        } bind def
  251.  
  252.        /rotation3 { % size x y
  253.        groupsdict begin    
  254.            moveto    
  255.            /r3size exch def
  256.            /r3ext r3size equi def    
  257.            anglecolor
  258.            0 r3ext 2 div rmoveto
  259.            r3size 2 div r3ext neg rlineto
  260.            r3size neg 0 rlineto
  261.            closepath 
  262.            gsave fill grestore stroke
  263.        end
  264.        } bind def
  265.    end
  266. endps
  267.  
  268. defineps reflect(float angle)
  269.      groupsdict begin
  270.          angle reflect
  271.      end 
  272. endps
  273.