From: jgm@cs.brown.edu (Jonathan Monsarrat)
Newsgroups: comp.lang.postscript
Subject: Make your icons come alive with randomness (or look stupid?)
Date: 29 Aug 1992 04:27:56 GMT
Organization: Brown University Department of Computer Science
Distribution: world
NNTP-Posting-Host: vegas.cs.brown.edu

Howdy! This is Jonathan Monsarrat coming at you from Brown University.

Here's an idea: why not make your icons come alive through the use of
randomness? Here's an example I call "the Little Wizard". Does
it make it any harder to "spot" as the icon? You decide.

Also small PS hack. Is there an obfuscated PS contest around?

-Jon
%! Obfuscated PostScript /r{repeat<267F>ge{pop}if}def/dup{pop}def/cvx{show}def
/p{translate}def/y{-1 roll exec}def{<2020202020666F6E74>dup 0 4 y putinterval
cvx 0 y}dup dup/Times-Roman<2066696E64>3 y 100<7363616C65>4 y<2020736574>3 y
90 rotate 0 -612 p 1 1.8 scale 36 144 moveto <50532020202020207B484F4E4B7D2069
66> show gsave 220 130 p {0 0 moveto 29 58 29 -45 180 arc} cvx dup 0 y -1 1
scale 0 y gsave 0.6 setgray fill grestore 2 setlinewidth stroke showpage
----------------------------------------------------------------------------

---------------- The Little Wizard ----------------------------------
%! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% THE FOLLOWING ROUTINES ARE USED IN THE WIZARD ICON %%
%%%%%%%%%%%%%%%% -  Wizard - %%%%%%%%%%%%%%%%%%%%%%%%%%%

/BIG 1073741824 def

% Gives a random number between 0 and N
%   N   Random  random-number
/Random
{
   rand BIG div mul 2 div
} bind def 

/Hat
{
    gsave
    25 54 moveto
    35 51 lineto
    35 Random
    15 add /x exch def    % Hat tilt randomness
    x 5 add 68 x 70 3 arcto pop pop pop pop
    x 5 sub 68 x 2 sub 65 2 arcto pop pop pop pop
    x 2 add 66 lineto 
    closepath
    1 setlinejoin
    gsave dup setgray fill grestore gsave stroke grestore
    % Add the while circles
    clip
    .7 gt { 0 } { 1 } ifelse setgray
    newpath
    0 1 20
    {
      pop 40 Random 20 add 20 Random 50 add 1.5 0 360 arc fill
    } for
    grestore
} bind def

% Takes two angles for the arms.
/Clothes
{
    gsave
    1 setlinejoin
    % Robes
    25 30 moveto
    25 20 20 10 17 3 curveto
    30 0 40 5 50 2 curveto
    38 25 34 32 36 35 curveto

    % Right arm
    40 Random 10 add            % Right arm randomness
    50 exch lineto 5 15 rlineto
    currentpoint 5 70 -110 arcn
    10 20 rlineto -10 -18 rlineto
    40 43 lineto
    26 43 lineto
    22 42 lineto

    % Left arm
    45 Random 20 add dup dup   % Left arm randomness
    10 exch lineto 15 sub 10 exch lineto
    10 exch lineto
    -5 1 -6 -10 0 -10 rcurveto
    0 -5 rlineto
    closepath
    % Add the while circles
    gsave dup setgray fill grestore gsave stroke grestore clip
    .7 gt { 0 } { 1 } ifelse setgray
    newpath
    0 1 50
    {
      pop 60 Random 10 add 50 Random 1.5 0 360 arc fill
    } for
    grestore
} bind def

/Face
{
   gsave
      % setgray
      1 setgray
      25 54 moveto 25 33 37 33 35 52 curveto fill
      % currentgray .7 gt { 0 } { 1 } ifelse setgray
      0 setgray
      25 54 moveto 25 33 37 33 35 52 curveto stroke
         newpath .3 setlinewidth
         28 49 1 0 360 arc stroke
         32 48 1 0 360 arc stroke
         30 45 1 0 360 arc fill

      % Whiskers
      .7 gt { 0 } { 1 } ifelse setgray
      0 1 10
      {
         25 add
         0 1 5
         {
           pop dup 10 Random 36 add
           moveto -3 Random -1 1 -3 Random 0 -5 Random rcurveto stroke
	 } for
         pop
      } for
   grestore
} bind def

% draws a picture of a wizard in a 1"x1" square
/Wizard
{
  newpath .5 setlinewidth
  1 Random dup Clothes
  Face
  1 Random Hat
} bind def

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% END OF ROUTINES FOR THE WIZARD ICON
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/in {72 mul} def

/IconDemo
{
  /icon exch def
  1 1 11
  {
    pop
    1 1 8
    {
      0 0 moveto 72 0 lineto 72 72 lineto 0 72 lineto closepath stroke
      icon cvx exec
      pop 1 in 0 translate
    } for
    -8 in 1 in translate
  } for
} bind def

/Wizard IconDemo showpage
Xref: sparky comp.lang.postscript:4516 comp.unix.aix:9211