View previous topic :: View next topic |
Author |
Message |
mcupwr
Joined: 29 Mar 2008 Posts: 85 Location: EU
|
|
Back to top |
|
|
snipsnip
Joined: 10 Feb 2014 Posts: 74 Location: Melbourne
|
Posted: Sun Mar 15, 2015 2:32 pm Post subject: |
|
|
you should be able to mod something from here..
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
copied from above.
plotLine(x0,y0, x1,y1)
dx=x1-x0
dy=y1-y0
D = 2*dy - dx
plot(x0,y0)
y=y0
for x from x0+1 to x1
if D > 0
y = y+1
'maybe just randomise whether x,y are plotted here?????
plot(x,y)
D = D + (2*dy-2*dx)
else
plot(x,y)
D = D + (2*dy) |
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 585 Location: Cleveland, OH
|
Posted: Tue Mar 17, 2015 1:38 am Post subject: |
|
|
Remember you can only have one math function per line, in Bascom.
This is a line plotting routine in Bascom, using Bresenham's algorithm.
Obviously this isn't the full program, but perhaps it will help get you started.
Code: |
Glcdline:
'Draw a Straight Line on the GLCD, Pixel Coordinates.
'Use Bresenham's algorithm.
'On Entry have: (GX1,GY1) and (GX2,GY2)
'GX1, GX2: Columns: 0-127, Left to Right
'GY1, GY2: Rows: 0-63, Top Down
'Supports the Inverse Mode Flag, as does Text.
'Error Checks for valid location prior to plotting, (within GPixSet).
'Uses GPixSet
'Set Pixel Value for subsequent GPixSet routine
If I = 1 Then
Pv = 0 'Pixel = Off, Inverted
Else
Pv = 1 'Pixel = On, black on Clear
End If
'First look at Delta X & Delta Y, see slope of line, most flat or vert
Gdx = Gx2 - Gx1
Gdx = Abs(gdx)
Gdy = Gy2 - Gy1
Gdy = Abs(gdy)
Vert = 0 'Line is mostly horz, Slope < 45 degrees
If Gdy > Gdx Then
Vert = 1 'Line is mostly vertical, Slope > 45 deg
End If
'If line is mostly vertical, swap the coordinates
If Vert = 1 Then
Swap Gx1 , Gy1
Swap Gx2 , Gy2
End If
'If line is R to L, then Swap
If Gx1 > Gx2 Then
Swap Gx1 , Gx2
Swap Gy1 , Gy2
End If
Gdx = Gx2 - Gx1
Gdy = Gy2 - Gy1
Gdy = Abs(gdy)
Lerr = Gdx / 2
Gly = Gy1
If Gy1 < Gy2 Then
Ystep = 1
Else
Ystep = -1
End If
For Glx = Gx1 To Gx2 'Plot the points
If Vert = 1 Then
'Plot (Gly,Glx)
Pc = Low(gly)
Pr = Low(glx)
Else
'Plot (Glx,Gly)
Pr = Low(gly)
Pc = Low(glx)
End If
Gosub Gpixset 'Plot the point
Lerr = Lerr - Gdy
If Lerr < 0 Then
Gly = Gly + Ystep
Lerr = Lerr + Gdx
End If
Next Glx
Return
|
|
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Tue Mar 17, 2015 9:06 am Post subject: Re: Pset to Line |
|
|
mcupwr wrote: |
X,Y are words... |
Think that PSET expects bytes for X and Y. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
|
|
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 You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|