Author |
Topic: Drawing lines (Read 791 times) |
|
Monkfish
Full Member
member is offline
Gender:
Posts: 104
|
|
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?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
Logged
|
|
|
|
Monkfish
Full Member
member is offline
Gender:
Posts: 104
|
|
Re: Drawing lines
« Reply #2 on: Jul 24th, 2015, 4:32pm » |
|
Thanks for pointing me in the right direction. I will read up
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
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
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
Logged
|
|
|
|
Monkfish
Full Member
member is offline
Gender:
Posts: 104
|
|
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?
|
|
Logged
|
|
|
|
Rod
Full Member
member is offline
Gender:
Posts: 110
|
|
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
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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: 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.
|
|
|
|
Monkfish
Full Member
member is offline
Gender:
Posts: 104
|
|
Re: Drawing lines
« Reply #8 on: Jul 25th, 2015, 8:34pm » |
|
Thanks guys
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
|
|
|