Write a program to rotate a wheel with fill color as per user’s choice.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>

#define ROUND(x) ( (int) (x+0.5) )

void lineDDA(int, int, int, int, int);
void midpoint(int, int, int, int);
void circlepoints(int, int, int, int, int);

void main()
{
    int gdriver=DETECT, gmode;
    int x1,y1,x2,y2,r;

    initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

    cleardevice();

    //printf("Enter the value of (X1,Y1) : ");
    //scanf("%d %d",&x1,&y1);
    printf("Enter the value of (X2,Y2) : ");
    scanf("%d %d",&x2,&y2);
    printf("Enter the Radius : ");
    scanf("%d",&r);
    x1=getmaxx()/2;
    y1=getmaxy()/2;

    //printf("%d %d",x1,y1);
    lineDDA(x1,y1,x2,y2,r);

    getch();
    closegraph();
}

void lineDDA(int x1, int y1, int x2, int y2, int r)
{
    int dx=x2-x1, dy=y2-y1, step, i;
    float xIncr, yIncr, x=x1, y=y1;
 //    int midx = 319, midy = 239;

    if (abs(dx) > abs(dy))
        step = abs(dx);
    else
        step = abs(dy);

    xIncr = dx / (float) step;
    yIncr = dy / (float) step;

    midpoint(ROUND(x), ROUND(y), r, 9);

    for(i=0 ; i<step ; i++)
    {
        midpoint(ROUND(x), ROUND(y), r, 9);
        delay(10);
        midpoint(ROUND(x), ROUND(y), r, 0);

        x += xIncr;
        y += yIncr;
    }
    midpoint(ROUND(x), ROUND(y), r, 9);
}

void midpoint(int dx, int dy, int r, int c)
{
    int x=0, y=r, d=1-r;
    int de=3, dse=-2*r+5;

    circlepoints(x,y,dx,dy,c);

    while(y > x)
    {
        if(d < 0)
        {
            d += de;
            dse += 2;
        }
        else
        {
            d += dse;
            dse += 4;
            y--;
        }
        de += 2;
        x++;
        circlepoints(x,y,dx,dy,c);
    }
    setfillstyle(1,c);
    floodfill(dx,dy,c);
}

void circlepoints(int x, int y, int dx, int dy, int c)
{
    putpixel(dx+x,dy+y,c);
    putpixel(dx+x,dy-y,c);
    putpixel(dx-x,dy+y,c);
    putpixel(dx-x,dy-y,c);
    putpixel(dx+y,dy+x,c);
    putpixel(dx+y,dy-x,c);
    putpixel(dx-y,dy+x,c);
    putpixel(dx-y,dy-x,c);
}

Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP