Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Pset to Line

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
mcupwr

Bascom Member



Joined: 29 Mar 2008
Posts: 85
Location: EU

blank.gif
PostPosted: Sun Mar 15, 2015 1:30 pm    Post subject: Pset to Line Reply with quote

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.. Rolling Eyes

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
Back to top
View user's profile
snipsnip

Bascom Member



Joined: 10 Feb 2014
Posts: 66
Location: Melbourne

australia.gif
PostPosted: Sun Mar 15, 2015 2:32 pm    Post subject: Reply with quote

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
View user's profile
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 482
Location: Cleveland, OH

usa.gif
PostPosted: Tue Mar 17, 2015 1:38 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2107

netherlands.gif
PostPosted: Tue Mar 17, 2015 9:06 am    Post subject: Re: Pset to Line Reply with quote

mcupwr wrote:

X,Y are words...


Think that PSET expects bytes for X and Y.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

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