Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / I can't draw lines :(

Author
Message
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 23rd Dec 2007 22:14
At some angles the DB line command is very wobbly (baddum tsh!)
I want to make my own line function but my previous attempt, although accurate, was extremely slow and primitive.
I am pretty sure that the formula used in the DB line function is sound but the reason it looks bad is that DB doesn't round up decimals. I have made a function to round up decimals but I can't work out how to draw an accurate line.

Here is my best attempt, the problem is the formula doesn't work if width or height are 0.



Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 24th Dec 2007 01:32
I'll give you a hint - before you try and make a line routine, try doing a circle ! if you cant figure it out then let me know

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Dec 2007 12:05 Edited at: 24th Dec 2007 12:29
Ah, I think I get your hint, thanks

[edit]

I think I worked it out but it's still a bit slow and on diagonal lines there's an extra pixel for some reason.


Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 24th Dec 2007 12:27
Your welcome

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Dec 2007 12:29 Edited at: 24th Dec 2007 12:30
^bump for edit^

Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 24th Dec 2007 13:18
yes you have the idea, now to add lightning speed -



as you can see there is little difference between the two.

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th Dec 2007 00:56 Edited at: 26th Dec 2007 12:22
@Obese
Your algorithm might need a little tweaking. Compare line and dline over a larger y difference at different angles and you'll notice a skew and a length difference as in the example. If you can avoid cos and sin as functions, you can improve on speed also. If you want to use cos and sin in your method, try creating lookup tables for each and just call the values by indexing an array.



Look up Bressenham's algorithm. Should give you a couple of ideas

Enjoy your day.

Login to post a reply

Server time is: 2025-06-02 09:56:31
Your offset time is: 2025-06-02 09:56:31