basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Feb 09. 2010, 05:34
Home Help Search Calendar Login Register
News: Link MOJO : A Link Exchange For Small Software Developers

+  BASIC programming forum
|-+  Basic Coding
| |-+  Basic Interpreters.
| | |-+  Playing with Blassic
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Reply Print
Author Topic: Playing with Blassic  (Read 265 times)
Cybermonkey
Global Moderator
Hero Member
*****
Offline Offline

Posts: 692



WWW
« on: May 07. 2009, 07:41 » Reply with quote

Hi, since I am waiting for a new Yabasic version, I am coding sometimes with Blassic. Here is an example how to use postscript with Blassic. The trick is to install the cups-pdf driver add a printer and the result you'll find on /var/spool/cups-pdf/YOURNAME
Code:
     10 REM Postscript with Blassic
     30 LPRINT "%!"
     40 LPRINT "newpath"
     50 LPRINT "100 100 moveto"
     60 LPRINT "0 100 rlineto"
     70 LPRINT "100 0 rlineto"
     80 LPRINT "0 -100 rlineto"
     90 LPRINT "-100 0 rlineto"
    100 LPRINT "closepath"
    110 LPRINT "gsave"
    120 LPRINT "0.5 1 0.5 setrgbcolor"
    130 LPRINT "fill"
    140 LPRINT "grestore"
    150 LPRINT "1 0 0 setrgbcolor"
    160 LPRINT "4 setlinewidth"
    170 LPRINT "stroke"
    180 LPRINT "showpage"
    190 CLOSE LPRINT
Okay I must admit, it is more postscript than BASIC ...  Grin
Don't know if there is a LPRINT on Ybasic which uses lp, then this example should be easy to port.
Report to moderator   Logged

Best wishes,
Cybermonkey
Derek
Administrator
Hero Member
*****
Offline Offline

Posts: 873



WWW
« Reply #1 on: May 07. 2009, 10:40 » Reply with quote

Hi,

this isn't the same but
Code:
open window 200,200
open printer "file.ps"
line 0,0 to 200,200
text 100,100,"Hallo"
close window
close printer
will create this file:
Code:
%!PS-Adobe-1.0
%%Title: (null) grafic
%%BoundingBox: 0 0 505 505
%%DocumentFonts: Helvetica
%%Creator: yabasic
%%Pages: (atend)
%%EndComments
gsave
/txt 4 dict def
/rec 6 dict def
/tri 8 dict def
/cir 5 dict def
/rgb 3 dict def
rgb /r 0 put
rgb /g 0 put
rgb /b 0 put
0 setgray
/M {moveto} def
/RL {rlineto} def
/L {lineto} def
/N {newpath} def
/S {stroke} def
/CLYN {(y) eq {1 setgray} {rgb /r get rgb /g get rgb /b get setrgbcolor} ifelse} def
/DO {CLYN N M 0 2.5272 RL 2.5272 0 RL 0 -2.5272 RL closepath fill (n) CLYN} def
/LI {CLYN N M L stroke (n) CLYN} def
/CI {mark 6 1 roll cir /fi 3 -1 roll put
     cir /cl 3 -1 roll put
     cir /r 3 -1 roll put
     cir /x 3 -1 roll put
     cir /y 3 -1 roll put
     cir /cl get (y) CLYN
     N cir /x get cir /y get cir /r get 0 360 arc
     closepath cir /fi get (y) eq {fill} {stroke} ifelse
     (n) CLYN cleartomark} def
/AT {mark 5 1 roll txt /txt 3 -1 roll put
     txt /xa 3 -1 roll put
     txt /y 3 -1 roll put
     txt /x 3 -1 roll put
     N txt /x get txt /y get M
     txt /txt get false charpath flattenpath pathbbox
     pop exch pop exch sub
     txt /x get exch
     txt /xa get (c) eq {2 div sub} if
     txt /xa get (l) eq {pop} if
     txt /xa get (r) eq {sub} if
     txt /y get M
     txt /txt get show cleartomark
     } def
/RE {mark 7 1 roll rec /fi 3 -1 roll put
     rec /cl 3 -1 roll put
     rec /y2 3 -1 roll put
     rec /x2 3 -1 roll put
     rec /y1 3 -1 roll put
     rec /x1 3 -1 roll put
     rec /cl get CLYN
     N rec /x1 get rec /y1 get M
     rec /x1 get rec /y2 get L
     rec /x2 get rec /y2 get L
     rec /x2 get rec /y1 get Lcolour 255,0,0
     rec /x1 get rec /y1 get L
     closepath rec /fi get (y) eq {fill} {stroke} ifelse
     (n) CLYN cleartomark} def
/TRI {mark 9 1 roll tri /fi 3 -1 roll put
     tri /cl 3 -1 roll put
     tri /y3 3 -1 roll put
     tri /x3 3 -1 roll put
     tri /y2 3 -1 roll put
     tri /x2 3 -1 roll put
     tri /y1 3 -1 roll put
     tri /x1 3 -1 roll put
     tri /cl get CLYN
     N tri /x1 get tri /y1 get M
     tri /x2 get tri /y2 get L
     tri /x3 get tri /y3 get L
     closepath tri /fi get (y) eq {fill} {stroke} ifelse
     (n) CLYN cleartomark} def
30 30 translate
2.5272 setlinewidth
0 505.44 505.44 0 (n) LI
/Helvetica findfont setfont newpath 0 0 moveto
(The Quick Brown Fox Jumped Over The Lazy Dog 0123456789) false charpath flattenpath pathbbox
3 -1 roll pop pop sub abs 913.204 exch div
/Helvetica findfont exch scalefont setfont
252.72 252.72 (l) (Hallo) AT
showpage
grestore
%%Trailer

which is rather good, IMO. That example was posted on the old Yabasic forum and according to my reply it didn't work under Windows or, perhaps, I was misunderstanding what it did (my money is on the latter LOL). The code produced opens perfectly with The Gimp, Evince etc.

Just opening the printer and omitting to open the file will simply send the output of the program to the printer.

Derek.

Edit: In that case you can draw whatever you want, send the output to a postscript file, open it with PhotoShop, The Gimp etc, edit it and save it as any picture format you want! Yabasic never ceases to surprise me!
« Last Edit: May 07. 2009, 10:49 by Derek » Report to moderator   Logged

wget http://*
Cybermonkey
Global Moderator
Hero Member
*****
Offline Offline

Posts: 692



WWW
« Reply #2 on: May 07. 2009, 14:11 » Reply with quote

Wow, that is great! I didn't know...
And you can just use imagemagick to get a PDF:
Code:
convert file.ps file.pdf
Report to moderator   Logged

Best wishes,
Cybermonkey
Pages: [1] Go Up Reply Print 
« previous next »
Jump to:  
Atom RDF RSS 0.91 RSS 2.0


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!