Page 1 of 1
[PB 6.20] StrokePath() cannot draw a 1px width line?
Posted: Sun Jun 08, 2025 5:36 pm
by osg
Subj
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
SetGadgetColor(0, #PB_Gadget_BackColor, #Black)
If StartVectorDrawing(CanvasVectorOutput(0))
MovePathCursor(0,10)
AddPathLine(68, 0, #PB_Path_Relative)
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(1)
MovePathCursor(0,20)
AddPathLine(68, 0, #PB_Path_Relative)
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(2)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
The width of the first line must be 1 pixel but it is 2px and kind of blurry.

Re: [PB 6.20] StrokePath() cannot draw a 1px width line?
Posted: Sun Jun 08, 2025 6:04 pm
by STARGÅTE
The coordinate 0,10 is exactly between two pixels, on the edge.
You have to draw at at 0.5, 10.5 in the middle of a pixel.
Re: [PB 6.20] StrokePath() cannot draw a 1px width line?
Posted: Sun Jun 08, 2025 7:44 pm
by osg
STARGÅTE wrote: Sun Jun 08, 2025 6:04 pm
The coordinate 0,10 is exactly between two pixels, on the edge.
You have to draw at at 0.5, 10.5 in the middle of a pixel.
Thank you. MovePathCursor(0.5,10.5) (or MovePathCursor(0,10.5)) helps a little, but it makes the line longer and blurry at the ends. This is all wrong, I think (0, 10) must define the pixel where the line starts.
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
SetGadgetColor(0, #PB_Gadget_BackColor, #Black)
If StartVectorDrawing(CanvasVectorOutput(0))
MovePathCursor(0.5,10.5)
AddPathLine(68, 0, #PB_Path_Relative)
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(1)
MovePathCursor(0,20)
AddPathLine(68, 0, #PB_Path_Relative)
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(2)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf

Re: [PB 6.20] StrokePath() cannot draw a 1px width line?
Posted: Sun Jun 08, 2025 8:03 pm
by infratec
I think you think wrong.
A line in vectorgraphic has always a center of 0 width and the stroke width is around that on all sides.
You can see this, for example, in inkscape if you choose the line end.
If you want the same length with stroke 2 and stroke 1 you need:
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
SetGadgetColor(0, #PB_Gadget_BackColor, #Black)
If StartVectorDrawing(CanvasVectorOutput(0))
MovePathCursor(1.5, 10.5)
AddPathLine(68, 0, #PB_Path_Relative) ; 1.5 - 0.5 to 1.5 + 68.0 + 0.5 -> 1 to 70
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(1, #PB_Path_SquareEnd)
MovePathCursor(2, 20)
AddPathLine(67, 0, #PB_Path_Relative) ; 2.0 - 1.0 to 2.0 + 67.0 + 1.0 -> 1 to 70
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(2, #PB_Path_SquareEnd)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
I placed it a bit right, because with a start at 0 you don't see that the stroke with 2 goes into the negative area.
I also use #PB_Path_SquareEnd that the line ending is 'plain'.
Both lines should go now from 1 to 70.
Re: [PB 6.20] StrokePath() cannot draw a 1px width line?
Posted: Sun Jun 08, 2025 8:27 pm
by infratec
With #PB_Path_Default, you can use this:
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
SetGadgetColor(0, #PB_Gadget_BackColor, #Black)
If StartVectorDrawing(CanvasVectorOutput(0))
MovePathCursor(1.5, 10.5)
AddPathLine(68, 0, #PB_Path_Relative)
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(1)
MovePathCursor(1, 20)
AddPathLine(68, 0, #PB_Path_Relative)
VectorSourceColor(RGBA(146, 146, 146, 255))
StrokePath(2)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Because then the line ends directly.
Problems occures when you want to make a vertical and horizontal line with different thickness and they should end at the same pixel.
Then you have to think about the coordinates.
Re: [PB 6.20] StrokePath() cannot draw a 1px width line?
Posted: Sun Jun 08, 2025 8:46 pm
by osg
Jesus... I didn't know that something could start between the pixels, thank you guys.
Re: [PB 6.20] StrokePath() cannot draw a 1px width line?
Posted: Sun Jun 08, 2025 9:03 pm
by infratec
Vectorlines always use an imaginary middle line of width 0.
The stroke width is arround this imaginary line.
So if you start at 0 with a stroke width of 1 the line is drawing at -0.5 to 0.5
That's the reason why all vector stuff uses floating point for the values.
In general and not only PB
Vector drawing is not always as simple as it sounds.