Jump to content




Something is wrong with the line algoritm.


  • You cannot reply to this topic
7 replies to this topic

#1 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 23 February 2015 - 02:03 AM

So I was developing a graphic API today and stumbled upon a problem with my line function, it doesn't really work that well when drawing a vertical line. Here's a screenshot of what I mean.
Posted Image
See the difference? I don't really know what's wrong, I've looked into paintutils function but that didn't get me anywhere.
Some help would be much appreciated.

Here's the code for the Graphics API
Graphics API
Main code


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 February 2015 - 02:34 AM

You're drawing one character for each column the line covers, even though there's more rows than columns. Thus you get gaps.

#3 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 23 February 2015 - 02:43 AM

Call me stupid, but I'm not quite sure how to fix it ( I blame the lack of sleep ). Is there any error you can spot in the Graphics.line function that causes this?
Is there something wrong with the algoritm? ( FYI, I'm really bad with algoritms )

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 February 2015 - 03:08 AM

What I'm saying is that if your line will cover more columns then rows (that is to say, dx > dy), looping from x1 to x2 works fine - you're drawing one character in all columns, and you're drawing one or more characters in each row.

But if your line covers more rows than columns (dx < dy), looping from x1 to x2 will perform less iterations than there are rows - meaning some rows won't have a character drawn in them.

#5 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 23 February 2015 - 03:24 AM

Ahh, thanks. I'll try to fix it tomorrow. It's getting kinda late :P

#6 dan200

  • Administrators
  • 542 posts
  • LocationCambridge, England

Posted 23 February 2015 - 10:07 AM

You know the bresenham line drawing algorithm is already implemented in ComptuerCraft, right? paintutils.drawLine()

#7 ElvishJerricco

  • Members
  • 803 posts

Posted 23 February 2015 - 10:19 AM

 dan200, on 23 February 2015 - 10:07 AM, said:

You know the bresenham line drawing algorithm is already implemented in ComptuerCraft, right? paintutils.drawLine()

Yes, in his post he compared his algorithm to the one used by paintutils =P I think he just wants his own.

#8 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 23 February 2015 - 02:43 PM

 dan200, on 23 February 2015 - 10:07 AM, said:

...
Yes I know that, just wanted to create my own as ElvishJerricco said.

Edit: 1337th post! :D

Edited by TheOddByte, 23 February 2015 - 02:44 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users