Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #2595
| Newsgroups | comp.lang.postscript |
|---|---|
| Date | 2016-06-01 16:54 -0700 |
| Message-ID | <ee5f9237-b314-4faf-9aad-a1c078e4258e@googlegroups.com> (permalink) |
| Subject | PostScript In IPython/Jupyter |
| From | Lawrence D’Oliveiro <lawrencedo99@gmail.com> |
You may have heard of IPython <http://ipython.org/> or its successor Jupyter <http://jupyter.org/>. If you haven’t, it offers a notebook-style interface (like Mathematica notebooks taken to the next level) which lets you experiment with short sequences of code, which can generate formatted text (in HTML or Markdown, with mathematical formulas courtesy of MathJax) and graphical output. They can even interact with the user.
IPython only allowed this with Python, while Jupyter generalizes it to allow alternative “kernels” that offer access to other languages. To my knowledge, no one has done a PostScript kernel yet...
I decided to add a PostScript interface another way, via a “cell magic”
<https://github.com/ldo/ipy_magics>. Unlike a kernel, there is no interpreter context maintained across notebook cells, so each cell has to hold a completely self-contained PostScript program. On the plus side, it is compatible with (pre-Jupyter) IPython.
To give some of the flavour, here are the examples I included in the readme. Formatted text:
%%ps --text=html
/TempStr 31 string def
(<table>\n<tr><th colspan="2">Dimensional Analysis</th></tr>\n) print
1 1 3
{
(<tr><td>$E = mc) print
dup 1 ne
{(^) print dup TempStr cvs print}
if
($</td><td>) print
2 eq
{(<b>Possible</b>)}
{(Rubbish)}
ifelse
print
(</td></tr>\n) print
}
for
(</table>\n) print
and graphics:
%%ps --papersize=250x500
/explode % explodes an array or dictionary into its components.
{
{} forall
}
def % explode
/CMYK % array of procedures for trying each CMYK colour in turn
[
[
[1.0 0.0 0.0 0.0]
[0.0 1.0 0.0 0.0]
[0.0 0.0 1.0 0.0]
[0.0 0.0 0.0 1.0]
]
{ % forall
explode /setcmykcolor load
5 array astore cvx
}
forall
]
def % CMYK
/RGB % array of procedures for trying each RGB colour in turn.
[
[
[1.0 0.0 0.0]
[0.0 1.0 0.0]
[0.0 0.0 1.0]
]
{ % forall
explode /setrgbcolor load
4 array astore cvx
}
forall
]
def % RGB
/PieSegments % x y r Colors PieSegments --
{
LocalDict % placeholder for local dictionary
begin
/Colors exch def
/Radius exch def
/YCenter exch def
/XCenter exch def
/NrColors Colors length def
/AngleStep 360 NrColors div def
/CurAngle -15 def
/Index 0 def
{ % loop
Index NrColors eq {exit} if
Colors Index get exec
newpath
XCenter YCenter moveto
XCenter YCenter Radius CurAngle dup AngleStep add arc
XCenter YCenter lineto
fill
/CurAngle CurAngle AngleStep add def
/Index Index 1 add def
}
loop
end % LocalDict
}
dup 0 10 dict put % create and insert LocalDict
def % PieSegments
120 120 100 CMYK PieSegments
120 370 100 RGB PieSegments
showpage
fun have. :)
Back to comp.lang.postscript | Previous | Next | Find similar | Unroll thread
PostScript In IPython/Jupyter Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-01 16:54 -0700
csiph-web