hydrocomputer
Programmer
I am trying to write substantial algorithms in postscript and finding
it hard going. There are two questions inherent in this post. First,
how can I solve the problem. Second, rather than just giving me the
answers, is there any decent way of stepping through postscript code
so I can debug it? I am using gs on linux; if there are better tools,
great. If there aren't, do any of you have little subroutines to
display intermediate values, or techniques to help? I programmed in
forth ages ago but find the stack machine to be difficult to code. No
doubt part of that is just my rusty skills.
First, I want to setup a color table to index values 0-127 to rgb triples.
I try to index from [0 0 1] to [1 0 0]
384 /palettesize store
/palettesize load string /nyhopscolormap store
/red 0 store
/green 0 store
/blue 255 store
0 3 /palettesize load
{
/i exch store
/nyhopscolormap load /i load /red/ load put
/nyhopscolormap load /i load 1 add /green load put
/nyhopscolormap load /i load 2 add /blue load put
/red load 2 add /red store
/blue load 2 add /blue store
} for
[/nyhops DeviceRGB 255 /nyhopscolormap load] setcolorspace
Then, I want to create an array of x,y locations, each with a value.
A low-tech way might be:
[
[-74,40, 1], [-73.99,40.05, 1.2], [-73.99, 40.085, 1.21]
[-73.95,40, 1.01], [-73.956,40.061, 1.11], [-73.99, 40.09, 1.14]
[-73.92,40, 1.01], [-73.912,40.059, 1.11], [-73.93, 40.089, 1.4]
]
This describes a 2d grid. I'm aware that I could encode this better
using ascii or binary, but that's a detail. I'd like to traverse this grid, connecting each adjacent quadrilateral (they aren't squares), coloring them.
I could of course just generate code like:
1 setcolor
newpath
-74,40 moveto
-73.99,40.05 lineto
-73.95,40 lineto
-73.956,40.061 lineto
closepath
fill
and just repeat, but this bothers me. I'd rather be able to write a
loop that processes this repettetive data and just process the
data. Whenever I try, it fails, and I have no good way to debug pieces
at a time until I have a working entity. If I mistype a token, I can
see in the dump from gs that it failed on that token, but otherwise I
just get an error at position xxxx which is better than nothing, but
not much better (and I am trying to find byte xxx in emacs, which no doubt has a command). Any suggestions would be greatfully appreciated.
it hard going. There are two questions inherent in this post. First,
how can I solve the problem. Second, rather than just giving me the
answers, is there any decent way of stepping through postscript code
so I can debug it? I am using gs on linux; if there are better tools,
great. If there aren't, do any of you have little subroutines to
display intermediate values, or techniques to help? I programmed in
forth ages ago but find the stack machine to be difficult to code. No
doubt part of that is just my rusty skills.
First, I want to setup a color table to index values 0-127 to rgb triples.
I try to index from [0 0 1] to [1 0 0]
384 /palettesize store
/palettesize load string /nyhopscolormap store
/red 0 store
/green 0 store
/blue 255 store
0 3 /palettesize load
{
/i exch store
/nyhopscolormap load /i load /red/ load put
/nyhopscolormap load /i load 1 add /green load put
/nyhopscolormap load /i load 2 add /blue load put
/red load 2 add /red store
/blue load 2 add /blue store
} for
[/nyhops DeviceRGB 255 /nyhopscolormap load] setcolorspace
Then, I want to create an array of x,y locations, each with a value.
A low-tech way might be:
[
[-74,40, 1], [-73.99,40.05, 1.2], [-73.99, 40.085, 1.21]
[-73.95,40, 1.01], [-73.956,40.061, 1.11], [-73.99, 40.09, 1.14]
[-73.92,40, 1.01], [-73.912,40.059, 1.11], [-73.93, 40.089, 1.4]
]
This describes a 2d grid. I'm aware that I could encode this better
using ascii or binary, but that's a detail. I'd like to traverse this grid, connecting each adjacent quadrilateral (they aren't squares), coloring them.
I could of course just generate code like:
1 setcolor
newpath
-74,40 moveto
-73.99,40.05 lineto
-73.95,40 lineto
-73.956,40.061 lineto
closepath
fill
and just repeat, but this bothers me. I'd rather be able to write a
loop that processes this repettetive data and just process the
data. Whenever I try, it fails, and I have no good way to debug pieces
at a time until I have a working entity. If I mistype a token, I can
see in the dump from gs that it failed on that token, but otherwise I
just get an error at position xxxx which is better than nothing, but
not much better (and I am trying to find byte xxx in emacs, which no doubt has a command). Any suggestions would be greatfully appreciated.