Smooth Line Drawing?

Non-platform specific questions.

Smooth Line Drawing?

Postby Hblade » Tue Nov 22, 2011 7:27 pm

I'm trying to do smooth line drawing, how can I make this smoother?
Code: Select all
erase(0, 0, 0, 1);

setpen(143, 164, 193, .95, 12);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .90, 11);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .85, 10);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .80, 9);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .75, 8);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .70, 7);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .65, 6);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .60, 5);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .55, 4);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .35, 3);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, 0, 2);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(169, 219, 242, 0, 1);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

line_issue.png


EDIT:
I almost got it... by modding the transparency, like so:
Code: Select all
erase(0, 0, 0, 1);

setpen(143, 164, 193, .94, 12);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .93, 11);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .92, 10);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .91, 9);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .90, 8);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .85, 7);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .80, 6);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .60, 5);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .40, 4);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .20, 3);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(143, 164, 193, .10, 2);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);

setpen(169, 219, 242, 0, 1);
moveto(395-320, 100);
lineto(489-320, 122);
lineto(576-320, 87);
lineto(550-320, 178);
lineto(454-320, 196);
lineto(365-320, 281);
lineto(493-320, 297);
lineto(396-320, 367);
lineto(576-320, 367);
lineto(593-320, 440);
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Smooth Line Drawing?

Postby skydereign » Tue Nov 22, 2011 8:33 pm

User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Smooth Line Drawing?

Postby Hblade » Tue Nov 22, 2011 8:59 pm

Thats not what I mean, lol but thanks. What I mean is, to get rid of the jagged edges and make it look more shiny. (When going Diagnal, it causes jagged edges)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Smooth Line Drawing?

Postby skydereign » Tue Nov 22, 2011 9:43 pm

Ah I didn't enlarge the picture so I didn't see any of the rounding. With how the canvas works it'd be pretty hard to make a really smooth line, but this kind of approach is decent I guess. It can be tweaked to achieve better results, and you can add rgb values to pass to it, but here is a function for it.
Global Code
Code: Select all
void
draw_line(int s_x, int s_y, int f_x, int f_y, double size)
{
    double max_size = size;
    while(size>0)
    {
        setpen(255, 255, 255, size/max_size, size);
        moveto(s_x, s_y);
        lineto(f_x, f_y);
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Smooth Line Drawing?

Postby Hblade » Tue Nov 22, 2011 10:01 pm

Thank you!

however, I can't use this. I've found another way (Much more code, though), and I dont want to risk messing anything up. But thanks so much! next time I use lineto, I'll use this code.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Smooth Line Drawing?

Postby tintran » Mon Dec 05, 2011 11:09 pm

not sure if this is related to this topic, but this is Xiaolin Wu's line algorithm as found on http://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm

i just simply translated it, it looks smoother than the standard built in lineto function
instead of brightness, i just set the opacity/transparency (1-brightness).
the lighter gray background shows Xiaolin Wu's algorithm.
btw, i have no idea how it works.
Attachments
smoothline.ged
(5.04 KiB) Downloaded 77 times
Screenshot-Untitled Window.png
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score

Re: Smooth Line Drawing?

Postby Hblade » Tue Dec 06, 2011 3:56 am

yeah =D Thanks ^^
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest