%!PS-Adobe-2.0 EPSF-2.0 %%Title: Plaid patch -- (plaid.eps) %%Creator: Izumi Ohzawa, izumi@pinoko.berkeley.edu %%CreationDate: Wed Jun 11 15:09:22 PDT 1997 %%BoundingBox: 215 215 433 433 %%EndComments % README: % This EPS (Encapsulated PostScript) file allows you to incorporate % a plaid patch into your documents or graphics. % A plaid is the sum of two sinusoidal gratings of different orientations. % The EPS file may be imported directly into drawings or DTP documents % by any decent software. % If your application refuses to import this file, your application is % positively brain-dead and should be treated accordingly (like deleting it). % On systems running Display PostScript, the grating patch will appear as WYSIWYG. % On other systems, it will appear as a box probably with the header info % in the first few lines of this file. % EPS with "preview" (PICT/TIFF) is stupid, especially for computed images % like this. % This is in the public domain. Use/copy/modify freely. % ================================================================================ % Modify the following parameters to get a desired plaid patch. % Note that contrasts for the two gratings must satisfy: % Cotrast1 + Contrast2 <= 1.0 % Otherwise "rangecheck error" for operator "put" will result. % Orientation of the whole patch, i.e., orientation of (y == const) scan lines. /Orientation 15 def % This will rotate the whole thing together % === Grating componet #1 --- This component may be oriented (90 deg is vertical) /Ncycles1 5.0 def % # of cycles in patch (fractional values OK) /Orient1 60.0 def % Orientation relative to that of component #2 % Note: Orient1 != 0 or 180 (or any multiple of 180) /Contrast1 0.4 def % Note: Cotrast1 + Contrast2 <= 1.0 /Phase1 0 def % === Grating componet #2 --- Horizontal grating component (0 deg is horizontal) % This component is always parallel to scan lines (y == const) of image. /Ncycles2 5.0 def % # of cycles in patch (fractional values OK) % /Orient2 0.0 def % Take this as a constant HORIZONTAL component /Contrast2 0.4 def % Note: Cotrast1 + Contrast2 <= 1.0 /Phase2 90 def % If you need a rectangular or circular frame or border around the patch, % set Frame to true, and adjust line characteristics of frame. /Frame false def % Frame On flag. "false" for no frame /FrameLineWidth 2.0 def % line width of frame /FrameGray 0.0 def % gray level of frame 0=black, 1=white % Choose shape: Circular (true) or Square (false) /Circular true def % circular patch ("Xsize" is the diameter) % "false" for rectangular patch /inch {72 mul} def % sigh. /nx 100 def % Resolution of 2-D image /ny 100 def /Xsize 3 inch def % Patch size (if modified, %%BoundingBox: must be changed) /Ysize 3 inch def /Xcenter 4.5 inch def % Center coordinate of patch /Ycenter 4.5 inch def % ================================================================================ % No user serviceable parts below this line. % PS code execution starts here newpath Xcenter Ycenter translate % move to center of patch Orientation rotate % rotate the whole patch Xsize -0.5 mul Ysize -0.5 mul translate % move origin to base of "image" gsave % make square image of desired withd Xsize Ysize scale % number of cells across image % Drawing within a unit square will be scaled to Xsize Ysize % Do clipping. Circular { % circular clipping newpath 0.5 0.5 0.5 0 360 arc clip newpath } { % rectangular clipping newpath 0 0 moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto closepath clip newpath } ifelse % Init some internal variables /S nx string def /period1 nx Ncycles1 div def % spatial period in # of pixels for V grating /periodOR1 period1 Orient1 sin div def % spatial period for orientation Orient1 /period2 ny Ncycles2 div def % spatial period in # of pixels for H grating /tanval Orient1 sin Orient1 cos div def % tan(Orient1) /y 0 def % Here's the pixel value compute loop for (nx, ny) points. nx ny 8 [nx 0 0 ny 0 0] { y period2 div dup truncate sub 360 mul Phase2 add sin 127.5 mul Contrast2 mul /val2 exch def % save grating component-2 value in val1 /offset y tanval div dup periodOR1 div floor periodOR1 mul sub def % offset % do a scan line at current y 0 1 nx 1 sub { S exch dup offset sub % string (index+offset) (index) periodOR1 div dup truncate sub % 0..1 for each cycle (saw tooth) 360 mul Phase1 add sin % sin = -1 .. 1 127.5 mul % -127 .. 127 Contrast1 mul % component-1 val2 add 128 add cvi put } for /y y 1 add def % increment y S } image % Draw frame if needed grestore Frame { FrameLineWidth setlinewidth FrameGray setgray Circular { % circular frame Xsize 2.0 div dup Ysize 2.0 div exch 0 360 arc closepath stroke } { % rectangular frame 0 0 moveto Xsize 0 rlineto 0 Ysize rlineto Xsize neg 0 rlineto closepath stroke } ifelse % Circular } if % Frame showpage % is allowed in EPS %%Trailer