Translate

Animation of Shape Changing Robot with Code.



#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include"graphics.h"
using namespace std;
#include<windows.h>
#include<process.h>
#pragma comment(lib, "Winmm.lib")
struct point
{
    int x;
    int y;
};
class gate
{
public:
    gate(){};
    gate(int x1,int y1,int x2,int y2){
    aa.x=x1;
    aa.y=y1;
    bb.x=x2;
    bb.y=y2;
   
    draw();
    };
    void draw()

    {setfillstyle(4,8);
   setcolor(9);
    rectangle(aa.x,aa.y,bb.x,bb.y);
    };
    void blink()
    {for(;;){
setcolor(RED);
    draw();
    delay(1000);
    setcolor(YELLOW);
    draw();
    delay(1000);}
    }
    void open()
    {PlaySound("det.wav", GetModuleHandle(NULL), SND_FILENAME | SND_ASYNC);
        for(int loop=0;loop<=200;loop++)
        {
    setcolor(0);
   
    rectangle(aa.x,aa.y,bb.x,bb.y);
   aa.y--;
   bb.y--;
   setcolor(9);   
   rectangle(aa.x,aa.y,bb.x,bb.y);
   delay(10);   
        }
    };

    void close()
    {PlaySound("det.wav", GetModuleHandle(NULL), SND_FILENAME | SND_ASYNC);
        for(int loop=0;loop<=200;loop++)
        {
    setcolor(0);
    rectangle(aa.x,aa.y,bb.x,bb.y);
   aa.y++;
   bb.y++;
   setcolor(9);
   rectangle(aa.x,aa.y,bb.x,bb.y);
   delay(10);   
        }
    };
//private:
struct point aa;
struct point bb;
};
class hurdle
{
public:
    hurdle()
    {
};
    void hurdle1(int a,int b,char c)
    {
    drawhurdle(a,b,c);
    };
    void drawhurdle(int a,int b,char c)
    {
        setcolor(c);
        x=a;
        y=b;
    for (int h =0;h<=50;h++){
        delay(20);
        arc(x+50, y, 0, 180, h);
    }
    setvalues();
};
    void setvalues()
    {
    a.x=x-50;
    a.y=y-50;
    b.x=x+50;
    b.y=y;
   
    };
   
   

    ~hurdle(){};

//private:
    int x;
    int y;
    point a;
    point b;
};
class robot
{
public:
    robot()
    {
count=0;   
    };
    robot(int a,int b,int a1,int b1)
    {
    c.x=a;
    c.y=b;
    d.x=a1;
    d.y=b1;
    draw();
    };
    void draw()
    {setfillstyle(5,7);
        rectangle(c.x,c.y,d.x,d.y);
    };
    void drawhor()
    {
    setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
    c.x++;
    d.x++;
       setcolor(1);
   rectangle(c.x,c.y,d.x,d.y);
   delay(10);
   
   
    };

    void drawdown(hurdle &aa)
    {for(;c.y<aa.b.y;){
    setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
   c.y++;
   d.y++;
       setcolor(1);
   rectangle(c.x,c.y,d.x,d.y);
   delay(10);}
    };

    void drawup()
    {
       
    setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
   c.y--;
  d.y--;
       setcolor(10);
   rectangle(c.x,c.y,d.x,d.y);
   delay(10);   
       
    };
    void drawdown()
    {
       
    setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
   c.y++;
   d.y++;
       setcolor(9);
   rectangle(c.x,c.y,d.x,d.y);
   delay(10);       
       
    };
    void sudomove()
    {
    for(int loop=0;loop<=65;loop++)
    {
    drawup();
    }
    }
   
    void finalmove(gate &g,hurdle &hh1,hurdle &hh2,gate &g1)
    {
    int a=0,b=0,cc=0,min,eghurdle,endeg,count=0,anticount;
    a=hh1.a.y-250;
    b=hh2.a.y-hh1.b.y;
    cc=450-hh2.b.y;
    if(a<b&&a<cc){min=a;}
    if(b<a&&b<cc){min=b;}
    if(cc<b&&cc<a){min=cc;}
    if(hh1.a.x>=hh2.a.x)
    {
    eghurdle=hh2.a.x;
    endeg=hh1.b.x;
   
    }
    else
    {eghurdle=hh1.a.x;
    endeg=hh2.b.x;}
    printf("%d %d%d",endeg,b,cc);
   
    for(int loop=0;loop<=950;loop++)
    {
    drawhor();
    if(d.x+5==g.aa.x)
    {
    g.open();
    }
   
    if(c.x-5==g.bb.x)
    {
    g.close();
    sudomove();
    if(a>=50||b>=50||cc>=50)
    {
    for(int loop=0;loop<50;loop++){
            for(int loop1=0;loop1<50;loop1++){
            if(hh1.a.y+loop1==c.y+loop){
                drawdown(hh1);   
            }   
            }
        }
    for(int loop=0;loop<50;loop++){
            for(int loop1=0;loop1<50;loop1++){
            if(hh2.a.y+loop1==c.y+loop){
                drawdown(hh2);   
            }}}
   
    }
    }

    if(d.x+5==eghurdle+55){
    if(a<50&&b<50&&cc<50){
        if(a==min)
    {
    for(;c.y!=250;)
    {
    drawup();
    }
    for(;d.y!=hh1.a.y;)
    {count++;
        lenght();
    }

    anticount=count;
    printf("%d",anticount);
    for(;count!=0;count--)
    {
strech();
    }

    }

    if(b==min)
    {
    for(;c.y!=hh1.b.y;)
    {
        printf("\n%d,%d",hh1.a.x,c.y);
    drawdown();
    }
    for(;d.y!=hh2.a.y;)
    {count++;
        lenght();
    }

    anticount=count;
    for(;count!=0;count--)
    {
strech();
    }
    }   

    if(cc==min)
    {
    for(;c.y!=hh2.b.y;)
    {printf("\n%d,%d",c.x,hh2.a.x);
    drawdown();
    delay(10);
    }
    for(;d.y!=449;)
    {count++;

printf("\n%d",d.y);
        lenght();
    }

    anticount=count;
    for(;count!=0;count--)
    {
strech();
    }
    }
   
    }

    }

    if(d.x+5==g1.aa.x)
    {
    g1.open();
    }
    if(c.x==g1.bb.x)
    {
    g1.close();
    }   
    if(c.x-5==endeg+55)
    {printf("\n%d %d",endeg,c.x);
    for(;anticount!=0;anticount--)
    {
    antistrech();
    antilenght();
    }
   
   
    }   

}}


    void strech()
    {
    delay(10);   
                delay(100);   
        setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
    setcolor(1);
        c.x--;
        d.x++;
    rectangle(c.x,c.y,d.x,d.y);
   delay(1);

    }
    void antistrech()
    {
    delay(10);   
                delay(100);   
        setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
    setcolor(1);
        c.x++;
        d.x--;
    rectangle(c.x,c.y,d.x,d.y);
   delay(1);

    }
    void lenght()
    {
        delay(10);   
                delay(100);   
        setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
    setcolor(1);
   //c.y++;
   
        d.y--;
    //    c.x--;
        //d.x++;
    rectangle(c.x,c.y,d.x,d.y);
   delay(1);   
   count++;

   
   
    }
    void antilenght()
    {
    delay(10);   
                delay(100);   
        setcolor(0);
    rectangle(c.x,c.y,d.x,d.y);
    setcolor(1);
   //c.y++;
   
        d.y++;
    //    c.x--;
        //d.x++;
    rectangle(c.x,c.y,d.x,d.y);
   delay(1);   
   count++;
   
    }
    ~robot(){};
    private:
    point c;
    point d;
 int count;
};
void presented(int x1,int y1,int x2,int y2)
{
struct point a;
struct    point b;
void *plane;

a.x=x1;
a.y=y1;
b.x=x2;
b.y=y2;
readimagefile("META.bmp",a.x,a.y,b.x,b.y);
plane=malloc(imagesize(a.x,a.y,b.x,b.y));       
getimage(a.x,a.y,b.x,b.y,plane);                   
putimage(a.x,a.y,plane,1);                       
putimage(a.x,a.y,plane,0);
for(int loop1=0;loop1<=150;loop1++)
{
    delay(1);
putimage(a.x,a.y,plane,1);                       
putimage(a.x,a.y,plane,0);
a.y++;
}
}
void annspresent()
{PlaySound("audio1.wav", GetModuleHandle(NULL), SND_FILENAME | SND_ASYNC);
    readimagefile("1.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture1.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture2.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture3.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture4.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture5.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture6.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture7.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture8.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture8.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture9.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture10.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture11.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture12.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture13.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture14.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture15.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture16.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture17.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture18.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture19.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture20.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture21.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture22.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture23.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture24.bmp",0,50,1370,670);
    delay(400);
    readimagefile("capture25.bmp",0,50,1370,670);
    delay(400);
readimagefile("capture26.bmp",0,0,1370,720);
    delay(400);readimagefile("capture27.bmp",0,0,1370,720);
    delay(400);readimagefile("capture28.bmp",0,0,1370,720);
    delay(400);readimagefile("capture29.bmp",0,0,1370,720);
    delay(600);
}
void minion()
{
    PlaySound("3.wav", GetModuleHandle(NULL), SND_FILENAME | SND_ASYNC);
    for(;;){
    readimagefile("2.bmp",0,50,1370,670);
    delay(10);

    readimagefile("3.bmp",0,50,1370,670);
    delay(10);
    readimagefile("4.bmp",0,50,1370,670);
    delay(10);
    readimagefile("5.bmp",0,50,1370,670);
    delay(10);
    readimagefile("6.bmp",0,50,1370,670);
    delay(10);
    readimagefile("7.bmp",0,50,1370,670);
    delay(10);
    readimagefile("8.bmp",0,50,1370,670);
    delay(10);
    readimagefile("8.bmp",0,50,1370,670);
    delay(10);
    readimagefile("9.bmp",0,50,1370,670);
    delay(10);
    readimagefile("10.bmp",0,50,1370,670);
    delay(10);
    readimagefile("11.bmp",0,50,1370,670);
    delay(10);
    readimagefile("12.bmp",0,50,1370,670);
    delay(10);
    }

}
void main()
{
    initwindow(1370,720,"Hurdle");
    presented(340,0,1020,50);
    delay(1000);
    cleardevice();
    annspresent();
    int x, y;
point p[2];   
char str[5];
hurdle h[2];
int a=-1;
int count=-1;
setcolor(WHITE);
outtextxy(20, 20, "Press any key to end.");
cleardevice();
setcolor(9);
robot screen(150,100,1200,600);
setfillstyle(5,9);
    robot sensor(155,325,205,375);
    setfillstyle(1,9);
    setcolor(10);
    line(150,250,1200,250);
    line(150,450,1200,450);
    setcolor(8);
    setfillstyle(5,8);
        gate g1(500,250,525,450),g2(900,250,925,450);
while(!kbhit()){
    if(ismouseclick(WM_LBUTTONDOWN)){  
    count++;
        getmouseclick(WM_LBUTTONDOWN, x, y);
        outtextxy(20,20,"The mouse was clicked at: ");
        p[count].x=x;
        p[count].y=y;
        h[count].hurdle1(p[count].x,p[count].y,RED);
printf("\n%d,%d,%d,%d",h[count].a.x,h[count].b.x,h[count].a.y,h[count].b.y);
       
        if(count==1){goto l;}}

}

    printf("\n%d,%d,%d,%d",h[a].a.x,h[a].b.x,h[a].a.y,h[a].b.y);

l:


    setcolor(WHITE);
   


sensor.finalmove(g1,h[0],h[1],g2);
minion();
    while(kbhit)
{

}

}
Previous
Next Post »

Contact Form

Name

Email *

Message *