Flag Waving Using C

Language

This is a simple C program. You can run this program in c compilers. In this program, dda line algorithm is used to plot the flagpole etc. By repeating algorithm in different position of the window, it look like waving in screen. You can enjoy it. Any queries contact me.
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<graphics.h>
  4. #include<math.h>
  5. #include<dos.h>
  6.  
  7. void dda(float x1,float y1,float x2,float y2,int z)
  8. {
  9. float dx,dy,x=x1,y=y1,m;
  10. int i;
  11.  
  12. dx=x2-x1;
  13. dy=y2-y1;
  14. if(abs(dx)>=abs(dy))
  15. m=abs(dx);
  16. else m=abs(dy);
  17. putpixel((int)x,(int)y,z);
  18. for(i=1;i<=m;i++)
  19. {
  20. x=x+dx/m;
  21. y=y+dy/m;
  22. putpixel((int)x,(int)y,z);
  23. }
  24. }
  25.  
  26. void main()
  27. {
  28.  
  29. float l1=250,l2=350,l3=50,l4=80,l5=120,l6=150,i,i1,i2,i3,b,a1,a2,a3,e;
  30.  
  31. int gd=DETECT,gm=DETECT;
  32. initgraph(&gd,&gm,"");
  33. printf(" Algorithm DDA");
  34. a1=(l2-l1)/3;
  35. a2=(l2-l1)/2;
  36. a3=(l5-l4)/2;
  37. i1=l1+a1;
  38. i2=i1-l1;
  39. i3=i1+i2;
  40. setbkcolor(0);
  41. while(!kbhit())
  42. { i=1;
  43. e=0;
  44.  
  45. while(((i<=i1)||(i<=i3)||(i<=l2))&&(i<=8))
  46. {
  47.  
  48. circle(245,47,4);
  49. dda(240,50,240,350,8);
  50. dda(250,50,250,350,8);
  51. dda(350,50-i,350,150-i,7);
  52. outtextxy(getmaxx()-150,(((getmaxy()/2)-50)+(10*i)),"JAIHIND !!!!");
  53. outtextxy(getmaxx()-170,getmaxy()-40,"DONE BY SEENIVASAN.P");
  54. setfillstyle(11,3);
  55. fillellipse(l1+a2,l4+a3-i,13,13-e);
  56. dda(l1,l3,i1,l3-i,6);
  57. dda(l1,l4,i1,l4-i,15);
  58. dda(l1,l5,i1,l5-i,15);
  59. dda(l1,l6,i1,l6-i,2);
  60.  
  61. dda(i1,l3-i,i3,l3,6);
  62. dda(i1,l4-i,i3,l4,15);
  63. dda(i1,l5-i,i3,l5,15);
  64. dda(i1,l6-i,i3,l6,2);
  65.  
  66. dda(i3,l3,l2,l3-i,6);
  67. dda(i3,l4,l2,l4-i,15);
  68. dda(i3,l5,l2,l5-i,15);
  69. dda(i3,l6,l2,l6-i,2);
  70.  
  71. bar3d(l1-50, 355, l1+50,350+55, 10, 3);
  72.  
  73. i=i+1;
  74. e=e+0.25;
  75. delay(200);
  76. cleardevice();
  77. }
  78. i=8;
  79. b=0;
  80. while(((i<=i1)||(i<=i3)||(i<=l1))&&(i>=1))
  81. {
  82. circle(245,47,4);
  83. dda(240,50,240,350,8);
  84. dda(250,50,250,350,8);
  85. dda(350,50-i,350,150-i,7);
  86. outtextxy(getmaxx()-150,(((getmaxy()/2))-50+(10*i)),"JAIHIND !!!!");
  87. outtextxy(getmaxx()-170,getmaxy()-40,"DONE BY SEENIVASAN.P");
  88. setfillstyle(11,4);
  89. fillellipse(l1+a2,l4+a3-i,13,13-e);
  90.  
  91. dda(l1,l3,i1,l3-i,6);
  92. dda(l1,l4,i1,l4-i,15);
  93. dda(l1,l5,i1,l5-i,15);
  94. dda(l1,l6,i1,l6-i,2);
  95.  
  96. dda(i1,l3-i,i3,l3,6);
  97. dda(i1,l4-i,i3,l4,15);
  98. dda(i1,l5-i,i3,l5,15);
  99. dda(i1,l6-i,i3,l6,2);
  100.  
  101. dda(i3,l3,l2,l3-i,6);
  102. dda(i3,l4,l2,l4-i,15);
  103. dda(i3,l5,l2,l5-i,15);
  104. dda(i3,l6,l2,l6-i,2);
  105.  
  106. bar3d(l1-50, 355, l1+50,350+55, 10, 3);
  107.  
  108. i=i-1;
  109. e=e-0.25;
  110. delay(200);
  111. cleardevice();
  112. }
  113. }
  114. getch();
  115.  
  116. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Tags

Add new comment