Wheel

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

int L=0; 

void ddaline(int x1,int y1,int x2,int y2) 
{ 

    int s,dx,dy,m,c=0; 
    float xi,yi,x,y; 

    dx=x2-x1; 
    dy=y2-y1; 

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

    xi=dx/(float)s; 
    yi=dy/(float)s; 

    x=x1; 
    y=y1; 

    putpixel(x1+0.5,y1+0.5,15); 
    for(m=0;m<s;m++) 
    { 
        x+=xi; 
        y+=yi; 
        if(getpixel(x+0.5,y+0.5)==4) 
        { 
            c++; 
            continue; 
        } 
        if(c%2==0) 
        { 
            putpixel(x+0.5,y+0.5,15); 
        } 
    } 
} 


void plotpoints(int x,int y,int cx,int cy,int s) 
{ 
    if(s==0) 
    { 
        if(L%20==0) 
        { 
            ddaline(cx-x,cy-y,cx+x,cy+y); 
            ddaline(cx-y,cy+x,cx+y,cy-x); 
            ddaline(cx-y,cy-x,cx+y,cy+x); 
            ddaline(cx-x,cy+y,cx+x,cy-y); 
        } 
        L++; 
    } 
    putpixel(cx+x,cy+y,4); 
    putpixel(cx-x,cy+y,4); 
    putpixel(cx+x,cy-y,4); 
    putpixel(cx-x,cy-y,4); 
    putpixel(cx+y,cy+x,4); 
    putpixel(cx-y,cy+x,4); 
    putpixel(cx+y,cy-x,4); 
    putpixel(cx-y,cy-x,4); 
} 


void mcircle(int cx,int cy,int r,int s) 
{ 
    int x=0,y,p; 

    y=r; 
    p=1-r; 

    while(x<=y) 
    { 
        plotpoints(x,y,cx,cy,s); 
        x++; 
        if(p<0) 
            p+=2*x+1; 
        else 
        { 
            y--; 
            p+=2*(x-y)+1; 
        } 
    } 

} 

void main() 
{ 
    int gd=DETECT,gm=DETECT; 
    initgraph(&gd,&gm,""); 

    mcircle(300,250,20,1); 
    mcircle(300,250,100,0); 

    getch(); 
}

Comments

Popular posts from this blog

Pendulum

Moving Wheel

Fish Movement