Page 1 of 1

How to draw curve?

PostPosted: Sat Nov 27, 2010 1:24 pm
by sportmaster
How to draw curve from point to point with canvas ? I also would like to know how to draw sine wave and of course circle, and maybe sphere with gradient filling.

Re: How to draw curve?

PostPosted: Sat Nov 27, 2010 2:16 pm
by Bee-Ant
For wide circle, it seems you can't draw it with solid line...only with dotted line...
Here's the code if I'm not mistaken...
Code: Select all
int i,xx,yy,R=100;
erase(0,0,0,1);
for(i=0;i<360;i++)
{
    xx=cos(degtorad(i))*R;
    yy=sin(degtorad(i))*R;
    setpen(255,255,255,0,1);
    putpixel(width/2+xx,height/2+yy);
}

Re: How to draw curve?

PostPosted: Sat Nov 27, 2010 6:55 pm
by sportmaster
The circle looks... so, so, but the code is smart :o and I can't deny it is a circle, and what about just one curve line ? Is it possible to draw solid ?

Re: How to draw curve?

PostPosted: Sun Nov 28, 2010 2:43 pm
by lcl
You can make is smoother by adding another one, little bit larger and transparent circle under it.
Like this:
Code: Select all
int i, xx, yy, R = 100;
erase(0, 0, 0, 1);

for (i = 0; i < 360; i ++)
{
    xx = cos(degtorad(i)) * R;
    yy = sin(degtorad(i)) * R;
    setpen(255, 255, 255, 0.5, 4);
    putpixel(width / 2 + xx, height / 2 + yy);
}
for (i = 0; i < 360; i ++)
{
    xx = cos(degtorad(i)) * R;
    yy = sin(degtorad(i)) * R;
    setpen(255, 255, 255, 0, 2);
    putpixel(width / 2 + xx, height / 2 + yy);
}

Just edited Bee-Ant's code. :D

Re: How to draw curve?

PostPosted: Sun Nov 28, 2010 3:13 pm
by jimmynewguy
Kall's brother showed us a way of counting a circle path a whiles back, i just put that code in a canvas and you don't get a pixley one. But he wants a curved line so this doesn't help. Guess I'll make another one if i find time in the next couple of minutes :)

Re: How to draw curve?

PostPosted: Sun Nov 28, 2010 3:30 pm
by Bee-Ant
jimmynewguy wrote:Kall's brother

Kall's brother?you mean Kalladdolf's???
Who's he?

Re: How to draw curve?

PostPosted: Sun Nov 28, 2010 9:23 pm
by jimmynewguy

Re: How to draw curve?

PostPosted: Sun Nov 28, 2010 11:15 pm
by Bee-Ant
jimmynewguy wrote:yea, you were in this discussion bee!
viewtopic.php?f=5&t=4600&hilit=counting+a+circle+path&start=15

Owh, what an old topic...no wonder I forgot it :P

Re: How to draw curve?

PostPosted: Mon Nov 29, 2010 2:48 am
by sportmaster
lcl improved Bee - Ant's circle but Jimmy's looks better because it's clear but I probably can't get collision with that line so it's only visaul effect. The advantage of lcl's is that I can add physicall response with canvas. Thanks to you I know two ways to draw circle but I still don't know how to make a curve line from point to point. I need to know how to display by canvas lines with various curvature for my next game so I'm counting on you :)

Re: How to draw curve?

PostPosted: Mon Nov 29, 2010 7:27 am
by Bee-Ant
Something like this???
http://dl.dropbox.com/u/3997355/Curve.ged

Well, basically you just need an array to store all the y point value.
Then connect them using moveto() and lineto()

Re: How to draw curve?

PostPosted: Mon Nov 29, 2010 8:59 am
by sportmaster
Yeaaach!! Another point for Beeee - Aaant :D :D :D !

Re: How to draw curve?

PostPosted: Mon Nov 29, 2010 10:22 am
by Bee-Ant
Thanks. Glad I could help :D