Skip to content

Instantly share code, notes, and snippets.

@skshetry
Last active March 1, 2018 15:22
Show Gist options
  • Save skshetry/3f0a62221860b171afc244585c6f0066 to your computer and use it in GitHub Desktop.
Save skshetry/3f0a62221860b171afc244585c6f0066 to your computer and use it in GitHub Desktop.
a.c
#include <stdio.h>
#include <graphics.h>
inline void initWindow(){
cleardevice();
setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
setbkcolor(BLACK);
return;
}
inline void renderBottomLine(int x, int y, int i){
line(i+x-270,y+150,i+x,y+150);
return;
}
inline void renderHouseBorders(int x, int y, int i){
line(i+x-270,y+150,i+x-270,y-55); // left-border
line(i+x,y+150,i+x,y-55); // right-border
}
inline void renderHouseRoof(int x, int y, int i){
line(i+x-285,y-47,i+x-135,y-120); // left lines of the roof.
line(i+x-285, y-65, i+x-135, y-140);
line(i+x+15,y-47,i+x-135,y-120); // right lines of the roof.
line(i+x+15, y-65, i+x-135,y-140);
}
inline void renderDoor(int x, int y, int i){
rectangle(i+x-170,y+30,i+x-100,y+150); // just the door.
}
inline void renderWindows(int x, int y, int i){
rectangle(i+x-250,y+20,i+x-200,y+70); // left window
floodfill(i+x-250,y+20,y+70);
rectangle(i+x-70,y+20,i+x-20,y+70); //right window
}
inline void renderHouse(int i)
{
int x, y;
x = getmaxx() / 2;
y = getmaxy() / 2;
initWindow();
renderBottomLine(x, y, i);
renderHouseBorders(x, y, i);
renderHouseRoof(x, y, i);
renderDoor(x, y, i);
renderWindows(x, y, i);
delay(10); // rendering rectangle takes some time. So, wait for it.
outtextxy(i+x-160,y, "Home");
delay(10); // text-rendering is slow.
}
inline void move_left(int);
inline void move_right(int max){
for(int i=0;i <= max-350;i++){
renderHouse(i);
}
move_left(max);
}
inline void move_left(int max){
for (int i=max-350;i>=0;i--)
{
renderHouse(i);
}
move_right(max);
}
inline void animateHouse(int max)
{
move_right(max); // go right first and then the left.
}
int main()
{
int gdriver = VGA, gmode = VGAHI;
initgraph(&gdriver, &gmode, "");
setcolor(BROWN);
register int max;
max = getmaxx();
animateHouse(max);
getch();
closegraph();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment