It is currently Tue Dec 01, 2020 6:12 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: LineXY
PostPosted: Sat Sep 12, 2020 8:52 pm 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
I am playing with 2D graphics and I'm used to when y = 0 then I will be at the bottom.

Is't easy for me to reverse but can PB be ajusted to do that by a setting or similar to change that behaviar?


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 1:06 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1091
[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.

Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 7:00 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3965
Location: Berlin, Germany
BarryG wrote:
Ivan wrote:
I'm used to when y = 0 then I will be at the bottom.

PureBasic does that,
No, it does not do so with the 2DDrawing functions such as LineXY().

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:
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


@Ivan: There is no built-in command to change this for the 2DDrawing functions.
However, you have much more possibilities when using PB's more modern vector drawing library.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 9:47 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1278
Location: right here
BarryG 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.
Maybe you saw https://www.purebasic.com/documentation/engine3d/index.html
That's 3d space though and completely separate from normal 2d pixel space.


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 9:49 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1091
Yes #NULL, that's what I was thinking of. Thanks for finding it for me. Edited my other post.


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 10:53 am 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
@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.


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 11:16 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3965
Location: Berlin, Germany
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. :)

OK. But it works that way in many classic BASIC flavours, IIRC e.g. in GW-BASIC, QBASIC, QuickBASIC, Turbo BASIC, PowerBASIC, ...

Ivan wrote:
That very little I know about a coordinate system and math: Incrementing y-values goes up - not down.

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.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 12:58 pm 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 1:10 pm 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3965
Location: Berlin, Germany
There is no advantage. Whether 0 on the y-axis is at the bottom or at the top is just a convention.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 1:16 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 339
Location: Pandora
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

_________________
地球上の平和


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 1:25 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:17 pm
Posts: 355
Location: United Kingdom
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...


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 2:04 pm 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
@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?


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 2:20 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 339
Location: Pandora
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.

_________________
地球上の平和


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 2:53 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3706
Location: Netherlands
Saki wrote:
Images are always stored line by line,
the way you would read it.

That depends on the OS.
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.

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: LineXY
PostPosted: Sun Sep 13, 2020 3:44 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2730
Location: Germany
For this I like VectorDrawing ...

Example with some help macros
Code:
;-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 / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye