lcd_line(0,0,83,47,1) produces 0,0 to 50,47

lcd_line(83,0,0,47,1) produces 83,0,34,47

I can't see anything wrong with optimizing code, but my number one
goal was to get the functionality
I have not design the algorithm. Bresenham did and the code I used was
taken from some papers describing
Bresenham and the optimizing, through the years, by other clever
people.

I do agree with you to save RAM where possible.
I also know that with the small screens a super speedy algorithm is
not needed.

I have 50 pages about Bresenham algorithms.
I can put them in a file on my website. It's nice reading

Paul

On 15 Dec., 05:05, mattschinkel <[email protected]> wrote:
> I guess line draw algorithms such as the ones you have used where
> originally written with negative numbers. It may be too time consuming
> to fix, so leave yours as they are.
>
> Could you please test the lcd_line procedure that is currently in the
> glcd_common library? I am just wondering weather it works on your
> screen.
>
> Matt.
>
> On Dec 14, 4:56 pm, mattschinkel <[email protected]> wrote:
>
>
>
>
>
>
>
> > The point I was making is simply that your x and y should always fit
> > into a byte. sword, word, etc are all too large. sbyte is not good to
> > use either since someone with more then 127 x_pixels or y_pixels can't
> > use byte.
>
> > If all your swords are changed to byte, you will save 7 bytes ram, and
> > some program memory. It takes longer to process larger variables.
>
> > You don't have to change it, I'm just suggesting.
>
> > Matt.
>
> > On Dec 14, 4:23 pm, pdhaene <[email protected]> wrote:
>
> > > I used sword because:
>
> > > x0 = 50
> > > x1 = 3
>
> > > will make dx < 0
>
> > > Paul
>
> > > On 14 Dec., 21:27, mattschinkel <[email protected]> wrote:
>
> > > > Thanks, I'll have a look.
>
> > > > I modified your LCD line procedure (this works on my glcd as well),
> > > > but why do you use sword to draw a line? I assume that you can only
> > > > start and end a line within LCD_X_RES 0 to 84, and LCD_Y_RES 0 to 48.
> > > > It is good practice to use small variables if possible. In your case,
> > > > byte variables may be enough. The same may be true for ellipse/circle
>
> > > > -- draw line procedure
> > > > procedure  lcd_line_2(byte in x0,byte in y0, byte in x1, byte in y1)
> > > > is
> > > >   var sword dx = sword(x1) - sword(x0)
> > > >   var sword dy = sword(y1) - sword(y0)
> > > >   var sword twoDx = dx + dx
> > > >   var sword twoDy = dy + dy
> > > >   var sword currentX = sword(x0), currentY = sword(y0)
> > > >   var sword xinc = 1, yinc = 1
> > > >   var sword twoDx_accumulated_error, twoDy_accumulated_error
>
> > > >   if dx < 0 then
> > > >     xinc = -1
> > > >     dx = -dx
> > > >     twoDx = -twoDx
> > > >   end if
> > > >   if dy < 0 then
> > > >     yinc = -1
> > > >     dy = -dy
> > > >     twoDy = -twoDy
> > > >   end if
> > > >   lcd_write_pixel(x0,y0,LCD_PEN_COLOR) -- first point is special case
>
> > > >   if (dx != 0) | (dy != 0) then -- are there other points on the line?
> > > >     if dy <= dx then -- is the slope <= 1 ?
> > > >       twoDx_accumulated_error = 0 -- initialize error
> > > >       while currentX != x1 loop
> > > >         currentX = currentX + xinc -- consider x's from x0 to x1
> > > >         twoDx_accumulated_error = twoDx_accumulated_error + twoDy
> > > >         if twoDx_accumulated_error > dx then
> > > >           currentY = currentY + yinc
> > > >           twoDx_accumulated_error = twoDx_accumulated_error - twoDx
> > > >         end if
> > > >         lcd_write_pixel(byte(currentX), byte(currentY), LCD_PEN_COLOR)
> > > >       end loop
> > > >     else -- the slope is large: reverse roles of X & Y
> > > >       twoDy_accumulated_error = 0 -- initialize error
> > > >       while currentY != y1 loop
> > > >         currentY = currentY + yinc -- consider y's from y0 to y1
> > > >         twoDy_accumulated_error = twoDy_accumulated_error + twoDx
> > > >         if twoDy_accumulated_error > dy then
> > > >           currentX = currentX + xinc
> > > >           twoDy_accumulated_error = twoDy_accumulated_error - twoDy
> > > >         end if
> > > >         lcd_write_pixel(byte(currentX), byte(currentY), LCD_PEN_COLOR)
> > > >       end loop
> > > >     end if
> > > >   end if
> > > > end procedure
>
> > > > Matt.- Hide quoted text -
>
> > > - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to