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.

-- 
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