Forum - MCS Electronics

Author Message
mcupwr Joined: 29 Mar 2008
Posts: 85
Location: EU  Posted: Sun Mar 15, 2015 1:30 pm    Post subject: Pset to Line Does someone have tip how to join two pixels X1 and X2 with some pixels between (not line)
in this code (now is between two pixels empty space)? For an example, if is Y1=10 and next
randome Y2=20, between is empty line (space), but it should be solid, filled with pixels...

I was tried to use in code this math Y = Y1 +((y2 - Y1) /(x2 - X1)) *(x - X1) , but 2.0.7.8
BASCOM write an error "Data type of souorce and target variables does not match".....
X,Y are words...probably I use wrong sintax.. Code: 'basic loop Do    For X = 0 To 64               Y = Some_random_value '0-2000               Y = Y / 8       Y = 32 - Y                     Pset X , Y , 255 Loop

Tnx

(BASCOM-AVR version : 2.0.7.8 )

_________________
MCUpwr  snipsnip Joined: 10 Feb 2014
Posts: 66
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)  JC Joined: 15 Dec 2007
Posts: 505
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   Evert :-)  Joined: 18 Feb 2005
Posts: 2126  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   Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum BASCOM AVR/8051----------------BASCOM-AVRBASCOM-8051BASCOM-ARDUINOShare your working BASCOM-8051 code hereShare your working BASCOM-AVR code hereBASCOM BETA-SLA BASCOM Related----------------EASY TCP/IPAVR-DOSAR7212KokkeKat FAT-free SD card libBASCOM Project Blog Other Stuff----------------VariousPCB'sRoboticsNew WebSiteAnnouncementsAVR Archive----------------BASCOM-AVR ArchiveBASCOM-8051 ArchiveBASCOM-AVR Unsupported versionsEasy TCP/IP ArchiveBASCOM-EDB
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