Create color swatches

Started by Joe, March 12, 2012, 01:28:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Joe

PS file linked here: [smg id=724 type=av]

Text:

Quote%!PS-Adobe-3.0
%%Title: (CMYKsurround.EPS)
%%Extensions: CMYK
%%DocumentProcessColors: Cyan Magenta Yellow Black
%%LanguageLevel: 2
%%BoundingBox: 0 0 720 1152    % EPS Box in points (10"x16") rectangle           ***USER MODIFICATION POSSIBLE***
%%EndComments

<< /PageSize [792 1224] >> setpagedevice   %use Tabloid.Portrait
36 36 translate

% ***** Constants Begin  *****
% ***** START OF USER MODIFICATION AREA *****

% ***** THE FOLLOWING FORMULA IS THE CENTER OF THE COLOR SPACE THAT WILL BE PRINTED *****
% ***** THIS EXAMPLE WILL PRINT C=0% M=0% Y=8% K=15%
/masterC   0.95 def   % C in % for CMYK Master recipe *** MODIFY THIS ***
/masterM   0.70 def   % M in % for CMYK Master recipe *** MODIFY THIS ***
/masterY   0.25 def   % Y in % for CMYK Master recipe *** MODIFY THIS ***
/masterK   0.25 def   % K in % for CMYK Master recipe *** MODIFY THIS ***

/epsBoxWidePoints   720      def      % must match the %%BoundingBox comment at top
/epsBoxHighPoints   1152   def      % must match the %%BoundingBox comment at top

% ***** END OF USER MODIFICATION AREA *****
/colorCasts 8 def   % Number of color casts (R,Y,G,C,B,M,CMY,K)
/colorIntensities 20 def   % Number of darker patches for a single color cast   ***USER MODIFICATION POSSIBLE***

/patchesStrokeLineWidth 1 def % 1/72 inch frame around the patches
/patchesWidePoints epsBoxWidePoints colorCasts div floor def                % width = casts
/patchesHighPoints epsBoxHighPoints colorIntensities 2 mul 1 add div floor def    % height = intensities (Dark+Light+Master)

% ***** Constants End *****

/SetBestFontSize            % set the optimal currentFontSize based on patchesWidePoints
{   /tempFontSize 20 def      % for a first try only
   /Helvetica-Bold findfont
   tempFontSize scalefont
   setfont
   
   /tempRatio
   {   patchesWidePoints               % available horizontal space
      0.75 mul                     % use 75% of it
      (100c.100m.100y.100k) stringwidth   % space occupied by the longest formula 
      pop                           % remove the height component
      div                           % ratio to apply to tempFontSize
   } def

   /currentFontSize
   {   tempFontSize tempRatio mul floor   % currentFontSize will be used for overprint in the patches
   } def
   
   /Helvetica-Bold findfont
   currentFontSize scalefont            % we will now print in the optimized currentFontSize
   setfont
} def

/SetBestOverlayColor      % set CMYK to be contrasting with the prefixed 4 numbers CMYK formula;
                     % prefixed numbers are lost
{   0.5 0.5 0.5 0.5 setcmykcolor % we will print using composite black unless the formula leads to a dark color
   3   { dup             % for each CMY values
      3 1 roll
      add               % add K value to that channel
      0.40 gt {   0 0 0 0 setcmykcolor} if   % print in white if this channel is darker than threshold value
      } repeat   
   pop                  % removes the last dup K
} def

/Range0to1               % return the prefixed number if between 0 to 1 ; otherwise returns 0 or 1
{   dup 0 lt {pop 0.0} {dup 1 gt {pop 1.0} if} ifelse
} def

/MyRectFill               % print at prefixed X, Y coordinates in the current color
{   patchesWidePoints patchesHighPoints rectfill
} def

/MyRectStroke            % print at prefixed X, Y coordinates in the current color
{    patchesWidePoints patchesHighPoints rectstroke
} def

/WritePercentNumber      % print in current color the prefixed real number (0.0<x<1.0); prefixed lost
{   100 mul round cvi   % make it percent
   /tempStr 20 string def
   tempStr cvs
   show
}def

/WriteFormula         % print the prefixed 4 numbers as a CMYK formula through the setBestOverlayColor;
                  % the prefixed numbers are lost
{   4 copy            % make a copy of the CMYK formula for SetBestOverlayColor
   SetBestOverlayColor
   
   4 1 roll         % the stack was CMYK ; make it KYMC
   3 1 roll
   2 1 roll

   4 4 moveto
   WritePercentNumber
   (c.) show
   WritePercentNumber
   (m.) show
   WritePercentNumber
   (y.) show
   WritePercentNumber
   (k) show
}def

/FillAndStrokeDarkIntensities         % starts printing at current coordinates
{   gsave                        % Preserve coordinates
   /CurrentIntensity colorIntensities def
   /loopIncrement -1 def            % ***** differs from LightIntensities
   colorIntensities loopIncrement 1   % Start, Increment, Last, Procedure
   {
      /intensityEffect {CurrentIntensity 100 div} def         % variation = 1%
         masterC castEffectOnC intensityEffect mul add Range0to1
          masterM castEffectOnM intensityEffect mul add Range0to1
          masterY castEffectOnY intensityEffect mul add Range0to1
          masterK castEffectOnK intensityEffect mul add Range0to1
      4 copy                     % **** keep copy of CMYK values for WriteFormula ****
       setcmykcolor
      0 0 MyRectFill

      0.5 0.5 0.5 0.5 setcmykcolor   % formula for the surrounding box
      0 0 MyRectStroke

      WriteFormula               % **** removes 4 elements from the stack ****

      0 patchesHighPoints translate % next patch vertically positioned
      /CurrentIntensity CurrentIntensity loopIncrement add def
   } for
   grestore                     % Coordinates returned as they were
} def

/FillAndStrokeLightIntensities          % starts printing at current coordinates
{   gsave                        % Preserve coordinates
   /CurrentIntensity 1 def
   /loopIncrement 1 def            % ***** differs from DarkIntensities
   1 loopIncrement colorIntensities   % Start, Increment, Last, Procedure
   {
      /intensityEffect {CurrentIntensity 100 div} def         % variation = 1%
         masterC castEffectOnC intensityEffect mul add Range0to1
          masterM castEffectOnM intensityEffect mul add Range0to1
          masterY castEffectOnY intensityEffect mul add Range0to1
          masterK castEffectOnK intensityEffect mul add Range0to1
      4 copy                     % **** keep copy of CMYK values for WriteFormula ****
       setcmykcolor
      0 0 MyRectFill

      0.5 0.5 0.5 0.5 setcmykcolor   % formula for the surrounding box
      0 0 MyRectStroke

      WriteFormula               % **** removes 4 elements from the stack ****

      0 patchesHighPoints translate % next patch vertically positioned
      /CurrentIntensity CurrentIntensity loopIncrement add def
   } for
   grestore                     % Coordinates returned as they were
} def

/FillAndStrokeMasterCMYK
{      startMasterCMYX startMasterCMYY translate    % master patch positioned

      masterC masterM masterY masterK
      4 copy                     % **** keep copy of CMYK values for WriteFormula ****
      setcmykcolor
         0 0
         patchesWidePoints colorCasts mul patchesHighPoints
      rectfill

      0.5 0.5 0.5 0.5 setcmykcolor   % formula for the surrounding box
         0 0 patchesWidePoints colorCasts mul patchesHighPoints
      rectstroke

      WriteFormula               % **** removes 4 elements from the stack ****
} def

/FillAndStrokeColorCastsAndIntensities
{
   % ***** Dark Red Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 1 def
      /castEffectOnY 1 def
      /castEffectOnK 0 def

      startDarkRX startDarkRY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Light Red Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC -1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY 0 def
      /castEffectOnK 0 def

      startLightRX startLightRY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

   % ***** Dark Yellow Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY 1 def
      /castEffectOnK 0 def

      startDarkYX startDarkYY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Light Yellow Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC -1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM -1 def
      /castEffectOnY 0 def
      /castEffectOnK 0 def

      startLightYX startLightYY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

   % ***** Dark Green Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY 1 def
      /castEffectOnK 0 def

      startDarkGX startDarkGY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Light Green Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM -1 def
      /castEffectOnY 0 def
      /castEffectOnK 0 def

      startLightGX startLightGY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

   % ***** Dark Cyan Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY 0 def
      /castEffectOnK 0 def

      startDarkCX startDarkCY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Light Cyan Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM -1 def
      /castEffectOnY -1 def
      /castEffectOnK 0 def

      startLightCX startLightCY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

   % ***** Dark Blue Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 1 def
      /castEffectOnY 0 def
      /castEffectOnK 0 def

      startDarkBX startDarkBY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Light Blue Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY -1 def
      /castEffectOnK 0 def

      startLightBX startLightBY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

   % ***** Dark Magenta Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 1 def
      /castEffectOnY 0 def
      /castEffectOnK 0 def

      startDarkMX startDarkMY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Light Magenta Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC -1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY -1 def
      /castEffectOnK 0 def

      startLightMX startLightMY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

   % ***** Darker CMY (no) Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 1 def
      /castEffectOnY 1 def
      /castEffectOnK 0 def

      startDarkCMYX startDarkCMYY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Lighter CMY (no) Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC -1 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM -1 def
      /castEffectOnY -1 def
      /castEffectOnK 0 def

      startLightCMYX startLightCMYY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

   % ***** Darker K (no) Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY 0 def
      /castEffectOnK 1 def

      startDarkKX startDarkKY translate
      FillAndStrokeDarkIntensities
   grestore                  % Coordinates returned as they were
   % ***** Lighter K (no) Cast processing
   gsave                     % Preserve coordinates
      /castEffectOnC 0 def      % -1 decrease ; 0 no effect ; 1 increase
      /castEffectOnM 0 def
      /castEffectOnY 0 def
      /castEffectOnK -1 def

      startLightKX startLightKY translate
      FillAndStrokeLightIntensities
   grestore                  % Coordinates returned as they were

} def

% ***** Main Program Initializations *****

SetBestFontSize

patchesStrokeLineWidth setlinewidth
/myRectX patchesStrokeLineWidth 2 div def
/myRectY patchesStrokeLineWidth 2 div def

/startMasterCMYX myRectX def
/startMasterCMYY myRectY colorIntensities patchesHighPoints mul add def

/startDarkRX myRectX def                        % Column for R variation
/startLightRX myRectX def
/startDarkRY myRectY def
/startLightRY myRectY colorIntensities 1 add patchesHighPoints mul add def

/startDarkYX startDarkRX patchesWidePoints add def      % Column for Y variation
/startLightYX startDarkYX def
/startDarkYY myRectY def
/startLightYY startLightRY def

/startDarkGX startDarkYX patchesWidePoints add def      % Column for G variation
/startLightGX startDarkGX def
/startDarkGY myRectY def
/startLightGY startLightRY def

/startDarkCX startDarkGX patchesWidePoints add def      % Column for C variation
/startLightCX startDarkCX def
/startDarkCY myRectY def
/startLightCY startLightRY def

/startDarkBX startDarkCX patchesWidePoints add def      % Column for B variation
/startLightBX startDarkBX def
/startDarkBY myRectY def
/startLightBY startLightRY def

/startDarkMX startDarkBX patchesWidePoints add def      % Column for M variation
/startLightMX startDarkMX def
/startDarkMY myRectY def
/startLightMY startLightRY def

/startDarkCMYX startDarkMX patchesWidePoints add def   % Column for CMY variation
/startLightCMYX startDarkCMYX def
/startDarkCMYY myRectY def
/startLightCMYY startLightRY def

/startDarkKX startDarkCMYX patchesWidePoints add def   % Column for K variation
/startLightKX startDarkKX def
/startDarkKY myRectY def
/startLightKY startLightRY def

% ***** Main Program Start *****
FillAndStrokeColorCastsAndIntensities
FillAndStrokeMasterCMYK

%%Trailer
showpage
%%EOF

Change these values to your needs:

Quote% ***** THE FOLLOWING FORMULA IS THE CENTER OF THE COLOR SPACE THAT WILL BE PRINTED *****
% ***** THIS EXAMPLE WILL PRINT C=0% M=0% Y=8% K=15%
/masterC   0.00 def   % C in % for CMYK Master recipe *** MODIFY THIS ***
/masterM   0.00 def   % M in % for CMYK Master recipe *** MODIFY THIS ***
/masterY   0.08 def   % Y in % for CMYK Master recipe *** MODIFY THIS ***
/masterK   0.15 def   % K in % for CMYK Master recipe *** MODIFY THIS ***
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.