LineXY
Re: LineXY
[Edit] I was mistaken - sorry. I was thinking of the 3D Engine library where X/Y/Z default to bottom-left of the screen.
Last edited by BarryG on Sun Sep 13, 2020 9:48 am, edited 2 times in total.
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: LineXY
No, it does not do so with the 2DDrawing functions such as LineXY().BarryG wrote:PureBasic does that,Ivan wrote:I'm used to when y = 0 then I will be at the bottom.
When using PB's 2DDrawing functions, x = 0 is at the very left, and y = 0 is at the very top of the output area (this is the classic behaviour of the BASIC programming language).
The following example demonstrates this behaviour:
Code: Select all
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 200, 200, "2DDrawing Example") = 0
End
EndIf
If CreateImage(0, DesktopScaledX(200), DesktopScaledY(200)) And StartDrawing(ImageOutput(0))
LineXY(0, 0, DesktopScaledX(100), DesktopScaledY(150))
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
However, you have much more possibilities when using PB's more modern vector drawing library.
Re: LineXY
Maybe you saw https://www.purebasic.com/documentation/engine3d/index.htmlBarryG wrote:My apologies. I could've sworn I've previously seen a diagram in the PureBasic Help that showed the X/Y/Z dimensions as a 3D box (with Y at the bottom), but can't find it now to defend myself.
That's 3d space though and completely separate from normal 2d pixel space.
Re: LineXY
Yes #NULL, that's what I was thinking of. Thanks for finding it for me. Edited my other post.
Re: LineXY
@Little John
"(this is the classic behaviour of the BASIC programming language)." - not the BBC Basic I was used to in the eighties.
That very little I know about a coordinate system and math: Incrementing y-values goes up - not down.
I'm in a learning process of trigonometry and was surprised.
Although I'm used to text location (x,y) goes from the top and down.
"(this is the classic behaviour of the BASIC programming language)." - not the BBC Basic I was used to in the eighties.
That very little I know about a coordinate system and math: Incrementing y-values goes up - not down.
I'm in a learning process of trigonometry and was surprised.
Although I'm used to text location (x,y) goes from the top and down.
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: LineXY
OK. But it works that way in many classic BASIC flavours, IIRC e.g. in GW-BASIC, QBASIC, QuickBASIC, Turbo BASIC, PowerBASIC, ...Ivan wrote:@Little John
"(this is the classic behaviour of the BASIC programming language)." - not the BBC Basic I was used to in the eighties.
This is true for the "normal" Cartesian coordinate system that most people learn at school. Hoewever, mathematicians also work with various other coordinate systems, and everyone is free to define her/his own coordinate system. The creators of many classic BASIC flavours took the freedom to define it the way that incrementing y-values go down from the top.Ivan wrote:That very little I know about a coordinate system and math: Incrementing y-values goes up - not down.
Re: LineXY
It's proberly becauce I not a mathematician, but what is the advantace in a 2D-system, to let y go down when increcing in value and not using the "normal" Cartesian coordinate system.
Is't possible to explain that in a pedagogical way to a matematical layman like me?
Is't possible to explain that in a pedagogical way to a matematical layman like me?
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: LineXY
There is no advantage. Whether 0 on the y-axis is at the bottom or at the top is just a convention.
Re: LineXY
An image that is stored in memory starts at this point.
The coordinate you want is somewhere before the end of the image in memory.
It is simply illogical and unwise to complicate this simple thing.
Best Regards Saki
The coordinate you want is somewhere before the end of the image in memory.
It is simply illogical and unwise to complicate this simple thing.
Best Regards Saki
地球上の平和
Re: LineXY
You can't be that much of a mathematical layman if you've recognised that the Cartesian co-ordinate system is being ignored!
There really isn't any 'logic' to it - it goes back to when computer terminals were really just jumped up electric typewriters.
A positive column movement moved the teletypewriter head from left to right across the paper. A positive row movement fed paper through the head - effectively moving the head 'down' the page. This system doesn't really have an origin because it depends where the operator leaves the paper when they load it (I'm talking continuous tractor feed paper here) but its 'virtual' origin would be at the top left corner of the page, if the operator loaded it properly.
When terminals started moving to block video rather than paper, the tab, line feed, carriage return concepts came with and no-one ever corrected the inconsistency because there was a fuzzy changeover with both systems being used simultaneously - not a clearly defined one.
Nor did it get corrected when true graphic displays were introduced for the same reason. The tab column and line analogy was dropped in favour of X and Y based co-ordinates to differentiate 'high resolution' video from block video, but the Y direction was reversed with respect to normal mathematical practice.
When true page printers were introduced they followed the same odd convention...
There really isn't any 'logic' to it - it goes back to when computer terminals were really just jumped up electric typewriters.
A positive column movement moved the teletypewriter head from left to right across the paper. A positive row movement fed paper through the head - effectively moving the head 'down' the page. This system doesn't really have an origin because it depends where the operator leaves the paper when they load it (I'm talking continuous tractor feed paper here) but its 'virtual' origin would be at the top left corner of the page, if the operator loaded it properly.
When terminals started moving to block video rather than paper, the tab, line feed, carriage return concepts came with and no-one ever corrected the inconsistency because there was a fuzzy changeover with both systems being used simultaneously - not a clearly defined one.
Nor did it get corrected when true graphic displays were introduced for the same reason. The tab column and line analogy was dropped in favour of X and Y based co-ordinates to differentiate 'high resolution' video from block video, but the Y direction was reversed with respect to normal mathematical practice.
When true page printers were introduced they followed the same odd convention...
Re: LineXY
@spikey - thanks.
It seems logical when cr/lf scrolls up seen in the historical perspective.
I find it interesting to know, if one of the PB-programmers would explain why, they made that decision...
@Saki - would you elaborate?
It seems logical when cr/lf scrolls up seen in the historical perspective.
I find it interesting to know, if one of the PB-programmers would explain why, they made that decision...
@Saki - would you elaborate?
Re: LineXY
Hi,
Images are always stored line by line,
the way you would read it.
Also with sprites or shapes, the color of the mask is read from coordinate 0, 0 by default.
Images are always stored line by line,
the way you would read it.
Also with sprites or shapes, the color of the mask is read from coordinate 0, 0 by default.
地球上の平和
Re: LineXY
That depends on the OS.Saki wrote:Images are always stored line by line,
the way you would read it.
If you look at the documentation for DrawingBufferPixelFormat() you see there's a flag #PB_PixelFormat_ReversedY to determine how the image is stored in memory.
On Linux and macOS it's stored as you see it but on Windows a BMP is usually stored upside down.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: LineXY
For this I like VectorDrawing ...
Example with some help macros
Example with some help macros
Code: Select all
;-TOP
; Flip Y-Coordinates by mk-soft, v0.6
EnableExplicit
Global _IsFlipped_, _OldY_.d
Macro _PB_(Function)
Function
EndMacro
Macro BeginFlipCoordinates()
FlipCoordinatesY(VectorOutputHeight() * 0.5) : _IsFlipped_ = #True
EndMacro
Macro EndFlipCoordinates()
_PB_(ResetCoordinates)() : _IsFlipped_ = #False
EndMacro
Macro ResetCoordinates(_Value_=#PB_Coordinate_User)
_PB_(ResetCoordinates)(_Value_) : If _IsFlipped_ : FlipCoordinatesY(VectorOutputHeight() * 0.5, _Value_) : EndIf
EndMacro
Macro DrawVectorText(_Text_)
If _IsFlipped_
_OldY_ = PathCursorY()
FlipCoordinatesY(_OldY_) : _PB_(DrawVectorText)(_Text_) : FlipCoordinatesY(_OldY_)
Else
_PB_(DrawVectorText)(_Text_)
EndIf
EndMacro
Define i
If OpenWindow(0, 0, 0, 450, 300, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 450, 300)
LoadFont(0, "Impact", 11)
If StartVectorDrawing(CanvasVectorOutput(0))
VectorFont(FontID(0))
MovePathCursor(10, 10)
DrawVectorText("Flip Coordinates Example")
BeginFlipCoordinates()
; Part 1
ResetCoordinates()
AddPathSegments("M 40 20 L 120 20 L 120 60 L 200 60 L 200 100 L 280 100 L 280 140 L 360 140 L 360 180")
VectorSourceColor(RGBA(255, 0, 0, 255))
StrokePath(5, #PB_Path_RoundCorner)
MovePathCursor(10, 30)
RotateCoordinates(10, 30, 45)
DrawVectorText("Red Line")
;Part 2
ResetCoordinates()
TranslateCoordinates(50, 50)
AddPathSegments("M 40 20 L 120 20 L 120 60 L 200 60 L 200 100 L 280 100 L 280 140 L 360 140 L 360 180")
VectorSourceColor(RGBA(0, 0, 255, 255))
StrokePath(5, #PB_Path_RoundCorner)
MovePathCursor(10, 30)
RotateCoordinates(10, 30, 45)
DrawVectorText("Blue Line")
; Part 3
ResetCoordinates()
AddPathCircle(80, 80, 50, 0, 45)
VectorSourceColor(RGBA(255, 0, 0, 255))
StrokePath(5, #PB_Path_RoundCorner)
AddPathCircle(80, 80, 50, 45, 90)
VectorSourceColor(RGBA(0, 0, 255, 255))
StrokePath(5, #PB_Path_RoundCorner)
; Part 4
ResetCoordinates()
VectorSourceColor(RGBA(64, 64, 64, 255))
For i = 0 To 260 Step 20
MovePathCursor(420, i + VectorTextHeight("X"))
DrawVectorText(Str(i))
Next
EndFlipCoordinates()
StopVectorDrawing()
EndIf
Repeat
Define Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive