Page History: Sensible Cartesian Co-ordinate graphics pack
Compare Page Revisions
Page Revision: 2017/08/17 16:48
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 ' current native x,y (i.e. not cartesian) coord system
'plot a point
Sub Plot(x As Integer,y As Integer)
G_x=x:G_y=G_ym-y
Pixel G_x,G_y
End Sub
'plot a point relative to the cursor e.g. PlotR -1,-1 plots a point one pixel left and down from the current graphics cursor
Sub PlotR(x As Integer,y As Integer)
G_x=G_x+x:G_y=G_y-y
Pixel G_x,G_y
End Sub
'Draw a line from the current graphics cursor to the x,y given
Sub Draw(x As Integer,y As Integer) 'draw a line from the current graphics cursor to the specified point
Line G_x,G_y,x,G_ym-y
G_x=x:G_y=G_ym-y
End Sub
'Draw a line from the current graphics cursor to the relative point x,y from the cursor
Sub DrawR(x As Integer,y As Integer)
Line G_x,G_y,G_x+x,G_y-y
G_x=G_x+x:G_y=G_y-y
End Sub
'move the graphics cursor to the given x,y but doesn't draw anything
Sub Move(x As Integer,y As Integer)
G_x=x:G_y=G_ym-y
End Sub
'move the graphics cursor to the point x,y relative to the current cursor but doesn't draw anything
Sub MoveR(x As Integer,y As Integer)
G_x=G_x+x:G_y=G_y-y
End Sub
Demo code
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 G_xm Step 10
For y=0 To G_ym Step 10
move x,y
circle G_x,G_y,4
drawr rnd*20-10,rnd*20-10
Next y,x