Page History: Sensible Cartesian Co-ordinate graphics pack
Compare Page Revisions
Page Revision: 2017/08/17 16:24
The standard Cartesian co-ordinate system places 0,0 in the bottom left corner of the view (ignoring offsets) e.g. like a piece of graph paper.
Modern windowing and LCD panel co-ordinate systems place 0,0 in the top left position.
The following is a series of graphics primitive subroutines that make it easy to pass conventional x,y co-ordinates and plot them correctly using the native windowing co-ordinates, using old the school drawing commands PLOT, DRAW and MOVE. This makes it a cinch to produce nice looking graphs without tying your brain in a knot with windowing co-ordinates.
I have more to add (including a scaling ORIGIN command to place the co-ordinate system anywhere you choose) but they need some honing.
Note:Always uses the current graphics pen (colour)
'screen dimensions follow LCDPANEL settings
Const G_xm=MM.HRes-1,G_ym=MM.VRes-1 ' 0 to zzz
'The global variables Gx and Gy always contain the current graphic cursor in native co-ordinates
Dim Integer G_x,G_y
'plot a point a single point
Sub Plot(x As Integer,y As Integer)
G_x=x:G_y=G_ym-y:Pixel G_x,G_y
End Sub
'Draw a line from the current graphics cursor to the specified point
Sub Draw(x As Integer,y As Integer)
Line G_x,G_y,x,G_ym-y:G_x=x:G_y=G_ym-y
End Sub
'move the graphics cursor to the specified point but doesn't draw anything
Sub Move(x As Integer,y As Integer)
G_x=x:G_y=G_ym-y
End Sub
Demo code
Do
cls
For n =0 To 239 Step 8'239 To 0 Step -4
move 239-n,n
draw n,239
Next
For x=0 To maxx Step 10
For y=0 To maxy Step 10
move x,y
circle Gx,Gy,4
Next y,x
Loop