You are on page 1of 15

Puzzle Image Creation Tutorial – By Swaroop Guggilam

Setting up EPS
1) You need to install following 2 softwares in order:
 Ghoscript – https://www.ghostscript.com/download/
 GS View - http://pages.cs.wisc.edu/~ghost/gsview/
2) Download the software from above mentioned links and follow the setup
directions, its pretty straight forward and easy.

Testing the Installation


(7 steps)
1) Cope the code below in a new text file and save it as “filename1.eps” file

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 181 425 475 745
%%HiResBoundingBox: 174.700 444.700 455.300 725.300
%CreatedBy deb.mohanty@gmail.com on Sat Feb 13
16:10:33 IST 2010

/ShowSolution false def

% ----------- Style Definitions ----------------

/CellSize 32 def

/Colorful false def


Colorful {
/bgcolor [ 219 255 div 248 255 div 132 255 div ] def
/darkColor [ 1 153 255 div 0 ] def
}
{
/bgcolor [ 0 0 0 0 ] def
/darkColor [ 0 0 0 .3 ] def
} ifelse

/Style
[
[ %Normal Cell
[0 0 0 1 ] %Stroke
bgcolor false %Fill

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

.75 %LineWidth
]
[ %Normal Cell
[0 0 0 1 ] %Stroke
[0 .1 .1 .3 ] true %Fill
.75 %LineWidth
]
[ %Normal Cell
[0 0 0 1 ] %Stroke
[.1 .1 0 .6 ] true %Fill
.75 %LineWidth
]
[ %OuterGrid or Shaped area
darkColor %Stroke
[0 0 0 0 ] false %Fill
CellSize 2.5 div %LineWidth
]
[ %Circle
.6 % Size of the circle in terms of CellSize
darkColor %Stroke
darkColor true %fill
1 %LineWidth
]
[ %OuterGrid or Shaped area
[0 0 0 1 ] %Stroke
[0 0 0 0 ] false %Fill
CellSize 10 div %LineWidth
]
] def

/LoopStyle Style 3 get def


/WhiteCircleStyle Style 4 get def
/OuterGridStyle Style 5 get def

/FontStyles
[
[ % Normal Cell
0.7 CellSize mul %Size
(Arial) %Font
[0 0 0 1 ] %Color
]
[ % Normal Cell

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

0.7 CellSize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]
[ [2 4][2 5][3 5][3 4] ]
[ [3 3][3 4] ]
[ [7 5][7 6][4 6] ]
[ [2 7][6 7] ]
[ [2 8][5 8] ]
[ [4 9][4 8][5 8] ]
[ [5 9][6 9][6 8][7 8][7 7] ]
[ [8 3][8 5] ]
[ [7 4][8 4][8 5] ]
[ [9 4][8 4][8 5] ]
[ [8 8][8 6][9 6][9 5] ]
] def

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

% ------------ Definitions based on puzzle data ---


----------

/GridHeight CellSize AreaData length mul def


/GridWidth CellSize AreaData 1 get length mul def
/HalfCellSize CellSize 2 div def

% ----- Define procedures ---

/SetColour {aload length 4 eq {setcmykcolor}


{setrgbcolor} ifelse} def

/doARectangle %stack : Style, x,y,length,width %x,


y is the center of the square
{
/Width exch def
/Length exch def
/yy exch def
/xx exch def
/Cy yy Width 2 div sub def
/Cx xx Length 2 div sub def
aload pop
/LineWidth exch def
{ SetColour Cx Cy Length Width rectfill } { pop
} ifelse
LineWidth setlinewidth
SetColour
Cx Cy Length Width rectstroke
} def

/doALine %stack : Style, x1,y1,x2,y2


{
newpath
moveto
lineto
closepath
aload pop
setlinewidth
pop pop %% Fill colour not used
SetColour
stroke

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

} def

/doACircle %stack : Style, x,y


{
/yy exch def
/xx exch def
aload pop
/lw exch def
/fill_p exch def
/fill_c exch def
/line_c exch def
/radius exch def
/radius radius HalfCellSize mul def
xx yy radius newpath 0 360 arc closepath
lw setlinewidth
fill_p { gsave fill_c SetColour fill grestore } if
line_c SetColour stroke
} def

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ----- Define procedures for height and width of


char ---
/showCharORDigit %stack : c, Style, x, y %c could
be a digit or a char
{
moveto
aload pop
SetColour
findfont
exch scalefont setfont
/c exch def
c type /integertype eq {
/e c def
e 9999 gt { /c {(XXXXX)} def
c 0 48 e 10000 idiv add put /e e 10000
mod def
c 1 48 e 1000 idiv add put /e e 1000
mod def
c 2 48 e 100 idiv add put /e e 100
mod def

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

c 3 48 e 10 idiv add put


c 4 48 e 10 mod add put } {
e 999 gt { /c {(XXXX)} def
c 0 48 e 1000 idiv add put /e e 1000
mod def
c 1 48 e 100 idiv add put /e e 100
mod def
c 2 48 e 10 idiv add put
c 3 48 e 10 mod add put } {
e 99 gt { /c {(XXX)} def
c 0 48 e 100 idiv add put /e e 100
mod def
c 1 48 e 10 idiv add put
c 2 48 e 10 mod add put }
{ e 9 gt { /c {(XX)} def
c 0 48 e 10 idiv add put
c 1 48 e 10 mod add put }
{ e 0 gt { /c (X) def
c 0 48 e add put }
{ /c () def } ifelse
} ifelse } ifelse } ifelse } ifelse
} if
gsave
newpath
0 0 moveto
c false charpath
flattenpath
pathbbox
grestore
% stack = llx lly urx ury
/ury exch def
/urx exch def
/lly exch def
/llx exch def
urx llx sub 2 div neg ury lly sub 2 div neg rmoveto
llx neg lly neg rmoveto
c show
} def

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

200 700 translate

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

/DrawPath {
/path exch def
/firstpoint path 0 get def
/xHere firstpoint 0 get def
/yHere firstpoint 1 get def
/xHere xHere 1 sub CellSize mul def
/yHere yHere 1 sub CellSize mul def
newpath
yHere xHere neg moveto
path { aload pop 1 sub CellSize mul exch 1 sub neg
CellSize mul lineto } forall
stroke
} def

LoopStyle aload pop setlinewidth pop SetColour


SetColour
LoopPath { DrawPath } forall

/DrawPath {
/path exch def
/firstpoint path 0 get def
/xHere firstpoint 0 get def
/yHere firstpoint 1 get def
/xHere xHere 1 sub CellSize mul def
/yHere yHere 1 sub CellSize mul def
yHere xHere neg moveto
stroke
path { /aaa exch def } forall
WhiteCircleStyle aaa aload pop 1 sub CellSize mul
exch 1 sub neg CellSize mul doACircle
} def

LoopStyle aload pop setlinewidth pop SetColour


SetColour
LoopPath { DrawPath } forall

/y 0 def
/row 0 def
AreaData {
/x 0 def

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

/col 0 def
{
Style 0 get x y CellSize CellSize doARectangle
/col col 1 add def
/x x CellSize add def
} forall
/y y CellSize sub def
/row row 1 add def
} forall

/row 0 def
/y 0 def
AreaData {
/col 0 def
/prev 0 def
/x 0 def
{
/c exch def
c prev ne {
OuterGridStyle x HalfCellSize sub y
HalfCellSize sub x HalfCellSize sub y HalfCellSize
add doALine
} if
row 0 gt {
/r_minus_1 row 1 sub def
/prev_col AreaData r_minus_1 get col get def
c prev_col ne {
OuterGridStyle x HalfCellSize add y
HalfCellSize add x HalfCellSize sub y HalfCellSize
add doALine
} if
} if
/x x CellSize add def
/col col 1 add def
/prev c def
} forall
/y y CellSize sub def
/row row 1 add def
} forall

ShowSolution {

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

/y 0 def
SolutionDigits {
/x 0 def
{
/c exch def
c 0 gt { c FontStyles 0 get x y showCharORDigit
} if
/x x CellSize add def
} forall
/y y CellSize sub def
} forall
} if

/y 0 def
ShowDigits {
/x 0 def
{
/c exch def
c 0 gt { c FontStyles c 9 gt { 2 } { 0 } ifelse
get x y showCharORDigit } if
/x x CellSize add def
} forall
/y y CellSize sub def
} forall

% draw puzzle border


OuterGridStyle
GridHeight 2 div HalfCellSize sub
GridWidth 2 neg div HalfCellSize add
GridHeight
GridWidth doARectangle

-70 50 translate

/ArrowFont
[ % Normal Cell
.3 CellSize mul %Size
(Arial Rounded MT Bold) %Font
[0 0 0 0] %Color
]
def

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

/row1 4 def
/row2 6 def
/col 2 def

/NewHArrow {
/yyy exch def
/xxx exch def
[0 0 0 .9] SetColour
newpath
xxx yyy moveto
.7 CellSize mul .4 CellSize mul rlineto
-.7 CellSize mul .4 CellSize mul rlineto
.1 CellSize mul -.4 CellSize mul rlineto
closepath
fill
ArrowFont xxx .28 CellSize mul add yyy .4 CellSize
mul add showCharORDigit
} def

%(A) CellSize 0.8 mul CellSize row1 mul neg CellSize


-1.94 mul add NewHArrow
%(B) CellSize -.9 mul CellSize row2 mul neg CellSize
.72 mul add NewHArrow

/NewVArrow {
[0 0 0 .9] SetColour
/yyy exch def
/xxx exch def
newpath
xxx yyy moveto
.4 CellSize mul -.7 CellSize mul rlineto
.4 CellSize mul .7 CellSize mul rlineto
-.4 CellSize mul -.1 CellSize mul rlineto
closepath
fill
ArrowFont xxx .42 CellSize mul add yyy -.3 CellSize
mul add showCharORDigit
} def

%(A) 3 CellSize col mul add CellSize 4.4 mul add


CellSize -2.7 mul add CellSize -.2 mul NewVArrow

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

%(B) 3 CellSize col mul add CellSize 4.4 mul add


CellSize 1.30 mul add CellSize -.2 mul NewVArrow

clear

showpage

2) Run the Gsview application


3) In options  Select “EPS Clip”
4) Click File  Open and select the filename1.eps, You should be able to see
following image.
(As you can see there is extra white space on top)

5) To get rid of extra white space.


Click File  PS to EPS  If a dialog box opens, select yes and make sure that
“Automatically calculate bounding box is checked” (Ignore this part, if no
dialogue box appears)
Save it as “filename2.eps”

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

6) Click File  Open  Filename2.eps


Now you should notice it is fit to size of image. It should look like below.

7) To insert images in word file, simple Click Insert Images  Select


“filename2.eps”

To View Solution

1) Change 7th line of code “ShowSolution false” to True. Save.


2) Open Gsview  File  Open  You will see following image (Note if
Gsvew is already open with “filename2.eps”, it will automatically update
the screen as soon as you make changes in the .eps file. You can use any
text editor to make changes in .eps file”

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

To Edit Puzzle Content


1) Just edit following section
% PUZZLE_DATA - START
/PuzzleId (148) def
/ShowDigits
[
[ 0 5 0 0 0 0 0 2 0 ]
[ 6 0 0 0 0 0 0 0 1 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 5 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 3 0 0 0 0 0 0 0 2 ]
[ 0 8 0 0 0 0 0 9 0 ]
]
def
/SolutionDigits

11th Nov 2017


Puzzle Image Creation Tutorial – By Swaroop Guggilam

[
[ 9 5 8 1 6 7 3 2 4 ]
[ 6 2 3 5 4 8 9 7 1 ]
[ 7 1 4 2 3 9 8 6 5 ]
[ 5 4 2 8 9 1 6 3 7 ]
[ 8 7 6 3 5 2 4 1 9 ]
[ 1 3 9 6 7 4 2 5 8 ]
[ 2 6 7 9 8 5 1 4 3 ]
[ 3 9 5 4 1 6 7 8 2 ]
[ 4 8 1 7 2 3 5 9 6 ]
]
def

% PUZZLE_DATA - END
/LoopPath
[
[ [3 6][1 6][1 4] ]
[ [2 3][2 2][3 2] ]
[ [4 1][4 2][3 2] ]
[ [5 1][5 3][4 3] ]
[ [6 3][4 3] ]
[ [7 3][7 2][6 2][6 1] ]
[ [8 2][6 2][6 1] ]
[ [4 5][4 4][5 4] ]
[ [6 5][6 4][5 4] ]
[ [2 4][2 5][3 5][3 4] ]
[ [3 3][3 4] ]
[ [7 5][7 6][4 6] ]
[ [2 7][6 7] ]
[ [2 8][5 8] ]
[ [4 9][4 8][5 8] ]
[ [5 9][6 9][6 8][7 8][7 7] ]
[ [8 3][8 5] ]
[ [7 4][8 4][8 5] ]
[ [9 4][8 4][8 5] ]
[ [8 8][8 6][9 6][9 5] ]
] def

Final Words – Above code is for Thermo Sudoku, once you have setup the
process, you can request either me or Prasanna to send the eps file for the
Sudoku Type you want to create.

11th Nov 2017

You might also like