Pendulum


#include<graphics.h> 
#include<conio.h> 
#include<dos.h> 
#include<process.h> 

int cx=300,cy=100,r=300; 
int x=0,y,p; 

int path(int dtn) 
{ 
    int x1,y1; 
    setcolor(15); 
    if(x>=y) 
    { 
        return 0; 
    } 
    cleardevice(); 

    if(dtn==1) 
    { 
        circle(cx+x,cy+y,20); 
        line(cx,cy,cx+x,cy+y); 
    } 
    else 
    { 
        circle(cx-x,cy+y,20); 
        line(cx,cy,cx-x,cy+y); 
    } 
    delay(10); 
    if(kbhit()) 
        exit(0); 
    x++; 
    if(p<0) 
        p+=2*x+1; 
    else 
    { 
        y--; 
        p+=2*(x-y)+1; 
    } 
    x1=x; 
    y1=y; 
    path(dtn); 

    cleardevice(); 
    if(dtn==1) 
    { 
        circle(cx+x1,cy+y1,20); 
        line(cx,cy,cx+x1,cy+y1); 
    } 
    else 
    { 
        circle(cx-x1,cy+y1,20); 
        line(cx,cy,cx-x1,cy+y1); 
    } 
    delay(10); 
    if(kbhit()) 
        exit(0);
    return(0);
} 

void main() 
{ 
    int gd=DETECT,gm=DETECT; 
    initgraph(&gd,&gm,""); 
    cleardevice(); 
    putpixel(300,100,4); 
    while(1) 
    { 
        x=0; 
        y=r; 
        p=1-r; 
        path(1); 
        x=0; 
        y=r; 
        p=1-r; 
        path(0); 
    } 
}

Comments

  1. Hii Dipin,
    I tried the pendulam program,but it gives warning
    My friend gave this program
    #include
    #include
    #include
    #include
    void main()
    {
    int gd=DETECT,gm;
    float xc=320,yc=240,x,y,l,r,a,i,rad;
    initgraph(&gd,&gm,"C:\\TC\\BGI");
    printf("\nEnter the length\n");
    scanf("%f",&l);
    printf("\nEnter radius\n");
    scanf("%f",&r);
    printf("\nEnter angle\n");
    scanf("%f",&a);
    a=a/2;
    while(!kbhit)
    {
    for(i=-a;i<=a;i++)
    {
    rad=(3.14*i)/180;
    x=xc+(l*sin(rad));
    y=yc+(l*cos(rad));
    line(xc,yc,x,y);
    circle(x,y,r);
    setfillstyle(SOLID_FILL,10);
    floodfill(x,y,10);
    delay(30);
    cleardevice();
    }
    for(i=a;i>=-a;i--)
    {
    rad=(3.14*i)/180;
    x=xc+(l*sin(rad));
    y=yc+(l*cos(rad));
    line(xc,yc,x,y);
    circle(x,y,r);
    setfillstyle(SOLID_FILL,10);
    floodfill(x,y,10);
    delay(30);
    cleardevice();
    }
    }
    getch();
    }
    But It didn'nt work out too
    Can you plz help me to correct my mistakes

    ReplyDelete
  2. my friend try using header filesthey are dos.h,stdio.h,maths.h,conio.h and graphics.h then it will show u successs........just try it...

    ReplyDelete
  3. to dipin:
    #include
    #include
    #include
    #include

    int cx=300,cy=100,r=300;
    int x=0,y,p;

    void path(int dtn)
    {
    int x1,y1;
    setcolor(15);
    if(x>=y)
    {
    exit (0);
    }
    cleardevice();

    if(dtn==1)
    {
    circle(cx+x,cy+y,20);
    line(cx,cy,cx+x,cy+y);
    }
    else
    {
    circle(cx-x,cy+y,20);
    line(cx,cy,cx-x,cy+y);
    }
    delay(10);
    if(kbhit())
    exit(0);
    x++;
    if(p<0)
    p+=2*x+1;
    else
    {
    y--;
    p+=2*(x-y)+1;
    }
    x1=x;
    y1=y;
    path(dtn);

    cleardevice();
    if(dtn==1)
    {
    circle(cx+x1,cy+y1,20);
    line(cx,cy,cx+x1,cy+y1);
    }
    else
    {
    circle(cx-x1,cy+y1,20);
    line(cx,cy,cx-x1,cy+y1);
    }
    delay(10);
    if(kbhit())
    exit(0);
    }



    void main()
    {
    int gd=DETECT,gm=DETECT;
    initgraph(&gd,&gm,"");
    cleardevice();
    putpixel(300,100,4);
    printf("enter 1 if u want to see pendulum");
    scanf("%d",&ch);
    while(ch!=1)
    {
    x=0;
    y=r;
    p=1-r;
    path(1);
    x=0;
    y=r;
    p=1-r;
    path(0);
    }
    getch();
    }dipin use this may be this will remove ur warnings..........

    ReplyDelete
  4. plzz tel me the coding to show the ticking the clock or minutes hand moving in a clock..

    ReplyDelete
  5. plz help me, i need a program of two balls are moving and when they collide,they become fours balls

    ReplyDelete

Post a Comment

Popular posts from this blog

Fish Movement

Moving Wheel