LB Booster
« Drawing lines »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:20am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Drawing lines  (Read 790 times)
Monkfish
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 104
xx Drawing lines
« Thread started on: Jul 24th, 2015, 3:13pm »

My program draws a host of characters composed of short horizontal and vertical lines. I am using the PLACE and GOTO commands to draw each line individually. The lines are one pixel wide.

I noticed that the last pixel was missing on each line; i.e. PLACE 5 5, GOTO 10 5, would actually draw a line from 5,5 to 9,5. So I decided to draw each line one pixel longer. That seemed to work fine.

However, I now want to draw everything at double the size and thought that simply increasing the line width to 2 pixels and doubling all my coordinates would achieve that result, but all my lines are off a bit. Also, some of the lines seem to have a single pixel (half the width) missing at one end.

Am I doing something wrong?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Drawing lines
« Reply #1 on: Jul 24th, 2015, 4:06pm »

on Jul 24th, 2015, 3:13pm, Monkfish wrote:
Am I doing something wrong?

Unlikely. Both LBB and LB offload graphics commands to the Windows API (GDI), so what happens is what GDI does when presented with those same parameters (for example PLACE maps directly to MoveToEx and GOTO to LineTo). So if you are unsure exactly what the commands should do you can refer to the linked documents at MSDN - to the extent that they say, at least.

Quote:
I noticed that the last pixel was missing on each line

The MSDN page says quite explicitly: "The LineTo function draws a line from the current position up to, but not including, the specified point" which explains your observation.

Richard.
User IP Logged

Monkfish
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 104
xx Re: Drawing lines
« Reply #2 on: Jul 24th, 2015, 4:32pm »

Thanks for pointing me in the right direction. I will read up smiley
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Drawing lines
« Reply #3 on: Jul 24th, 2015, 7:41pm »

There is an old trick allowing to "fix" last pixel
Code:
#main.gr "line 10 247 150 10" 'any coords actually.
'so LB/LBB/(windows?) does not paint last point
'but set current position to last point

'So we just pick that position and paint that point ourselves
#main.gr "posxy xVar yVar"
#main.gr "set ";xVar;" ";yVar
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Drawing lines
« Reply #4 on: Jul 24th, 2015, 9:06pm »

on Jul 24th, 2015, 7:41pm, tsh73 wrote:
There is an old trick allowing to "fix" last pixel

A neat, and slightly unexpected, thing about this trick is that it works if the line width (size command) is greater than 1, even if it's really big.

Richard.
User IP Logged

Monkfish
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 104
xx Re: Drawing lines
« Reply #5 on: Jul 25th, 2015, 07:24am »

Cool. I will give it a go.

The main reason I want to draw everything twice the size (including the font size) is that I want to increase the quality of my printouts. Although 8pt text is acceptable, 16pt would look better (but too large to use on the screen because it would make the overall image too big). I might not even want to display the double size image on the screen, just send it to the printer. I expect that is possible?
User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: Drawing lines
« Reply #6 on: Jul 25th, 2015, 07:41am »

To get the best out of your printer you need lots of pixels.

Imagine a graphic box 2100 pixels wide and 2950 pixels high. Now fill it with graphics or text and use print 2100 to send it to the printer.

That will get you good quality high resolution graphics. You don't need to be able to see all of the graphicbox on screen.

http://lbpe.wikispaces.com/GraphicPrinting2
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Drawing lines
« Reply #7 on: Jul 25th, 2015, 09:55am »

on Jul 25th, 2015, 07:41am, Rod wrote:
To get the best out of your printer you need lots of pixels.

Yes indeed. In fact, ideally, you should have as many pixels in your graphic as the printer has 'dots'. So for example if you want to print an 8" wide graphic at 300 DPI quality, you really want a graphic which is 2400 pixels wide!

Note that in LBB you cannot, by default, have a graphics canvas wider than your entire screen, but that is easily overcome by using the horizscrollbar command (depending on the height of your graphic you may need to use vertscrollbar too):

Code:
    open "High quality printing" for graphics_nsb as #w
    #w "horizscrollbar on 0 2400"
    #w "font Arial 0 120"
    #w "\\\    This should be printed in really high quality!"
    #w "print 2400"
    wait 

Quote:
http://lbpe.wikispaces.com/GraphicPrinting2

To make the example program there work correctly in LBB you need to add this before the graphics are drawn:

Code:
#1.g "horizscrollbar on 0 ";ImageWidth
#1.g "vertscrollbar on 0 ";ImageHeight 

on Jul 25th, 2015, 07:24am, Monkfish wrote:
I might not even want to display the double size image on the screen, just send it to the printer. I expect that is possible?

You could hide the graphicbox, or move it out of view:

Code:
    graphicbox #w.gb, 400, 0, 1, 1
    open "High quality printing" for graphics_nsb as #w
    #w.gb "horizscrollbar on 0 2400"
    #w.gb "font Arial 0 120"
    #w.gb "\\\    This should be printed in really high quality!"
    #w.gb "print 2400"
    wait 

Richard.
« Last Edit: Jul 25th, 2015, 10:36am by Richard Russell » User IP Logged

Monkfish
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 104
xx Re: Drawing lines
« Reply #8 on: Jul 25th, 2015, 8:34pm »

Thanks guys grin
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Drawing lines
« Reply #9 on: Jul 25th, 2015, 9:56pm »

On a related point, somebody at the Yahoo! group has asked how to make the ends of a 'thick' line flat rather than rounded. Nobody there seems to know the answer, but it's not difficult (this works in both LB and LBB):

Code:
    open "Line endcap" for graphics_nsb as #w
    thickness = 12
    #w "down; size ";thickness
    #w "line 50 100 250 150"
    hw = hwnd(#w)
    calldll #user32, "GetDC", hw as ulong, hdc as ulong
    struct logbrush, lbStyle as ulong, lbColor as ulong, lbHatch as ulong
    penstyle = _PS_GEOMETRIC or _PS_ENDCAP_FLAT
    calldll #gdi32, "ExtCreatePen", penstyle as long, thickness as long, _
      logbrush as struct, 0 as long, 0 as long, pen as ulong
    calldll #gdi32, "SelectObject", hdc as ulong, pen as ulong, old as ulong
    #w "line 50 200 250 250"
    calldll #gdi32, "SelectObject", hdc as ulong, old as ulong, pen as ulong
    calldll #gdi32, "DeleteObject", pen as ulong, ret as void
    wait 

Changing _PS_ENDCAP_FLAT to _PS_ENDCAP_SQUARE lengthens the line, but the ends remain straight.

Richard.
« Last Edit: Jul 25th, 2015, 11:36pm by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls