Hello everyone
Can someone tell me how do you use sin and cos? How can i use these on canvas to draw objects?
A small tutorial can help.
tvz wrote:Hello everyone
Can someone tell me how do you use sin and cos? How can i use these on canvas to draw objects?
A small tutorial can help.
int i;
setpen(255, 255, 255, 0, 2);
for(i=0; i<width; i++)
{
int sin_value = sin((double)i/width*(2*PI));
putpixel(i, height/2 + height/2.0*sin_value);
}
int i;
double radius = width/2;
setpen(255, 255, 255, 0, 2);
for(i=0; i<360; i++) // loops through angles 0-359 degrees
{
double rad = degtorad(i); // convert i to radians
int xp = radius*cos(rad); // get the x value of the circle at this angle
int yp = radius*sin(rad); // get the y value of the circle at this angle
putpixel(width/2 + xp, height/2 + yp); // place it in the center of the canvas
}
tvz wrote:1. I understood the first program but it just draws a straight white line horizontally on the screen.
int i;
setpen(255, 255, 255, 0, 2);
for(i=0; i<width; i++)
{
float sin_value = sin((double)i/width*(2.0*PI));
putpixel(i, height/2 + height/2.0*sin_value);
}
Users browsing this forum: No registered users and 1 guest