Facebook
From Content on Demand, 8 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 584
  1. // C program to implement
  2. // the above approach
  3. #include <conio.h>
  4. #include <graphics.h>
  5. #include <stdio.h>
  6. #define ScreenWidth getmaxx()
  7. #define ScreenHeight getmaxy()
  8. #define GroundY ScreenHeight * 0.75
  9. int ldisp = 0;
  10.  
  11. // Creating a hut
  12. void hut()
  13. {
  14.  setcolor(WHITE);
  15.  rectangle(150, 180, 250, 300);
  16.  rectangle(250, 180, 420, 300);
  17.  rectangle(180, 250, 220, 300);
  18.  
  19.  line(200, 100, 150, 180);
  20.  line(200, 100, 250, 180);
  21.  line(200, 100, 370, 100);
  22.  line(370, 100, 420, 180);
  23.  
  24.  setfillstyle(SOLID_FILL, BROWN);
  25.  floodfill(152, 182, WHITE);
  26.  floodfill(252, 182, WHITE);
  27.  setfillstyle(SLASH_FILL, BLUE);
  28.  floodfill(182, 252, WHITE);
  29.  setfillstyle(HATCH_FILL, GREEN);
  30.  floodfill(200, 105, WHITE);
  31.  floodfill(210, 105, WHITE);
  32. }
  33.  
  34. // Drawing a Man with
  35. // an umbrella
  36. void DrawManAndUmbrella(int x,
  37.       int ldisp)
  38. {
  39.  circle(x, GroundY - 90, 10);
  40.  line(x, GroundY - 80, x,
  41.   GroundY - 30);
  42.  line(x, GroundY - 70,
  43.   x + 10, GroundY - 60);
  44.  line(x, GroundY - 65, x + 10,
  45.   GroundY - 55);
  46.  line(x + 10, GroundY - 60,
  47.   x + 20, GroundY - 70);
  48.  line(x + 10, GroundY - 55,
  49.   x + 20, GroundY - 70);
  50.  
  51.  line(x, GroundY - 30,
  52.   x + ldisp, GroundY);
  53.  line(x, GroundY - 30,
  54.   x - ldisp, GroundY);
  55.  
  56.  pieslice(x + 20, GroundY - 120,
  57.    0, 180, 40);
  58.  line(x + 20, GroundY - 120,
  59.   x + 20, GroundY - 70);
  60. }
  61.  
  62. // Creating the Rainfall
  63. void Rain(int x)
  64. {
  65.  int i, rx, ry;
  66.  for (i = 0; i < 400; i++)
  67.  {
  68.   rx = rand() % ScreenWidth;
  69.   ry = rand() % ScreenHeight;
  70.   if (ry < GroundY - 4)
  71.   {
  72.    if (ry < GroundY - 120 ||
  73.    (ry > GroundY - 120 &&
  74.    (rx < x - 20 ||
  75.     rx > x + 60)))
  76.     line(rx, ry,
  77.      rx + 0.5, ry + 4);
  78.   }
  79.  }
  80. }
  81.  
  82. // Creating the rainbow
  83. void rainbow()
  84. {
  85.  int x, y, i;
  86.  
  87.  circle(ScreenWidth - 100,
  88.   50, 30);
  89.  setfillstyle(SOLID_FILL,
  90.     YELLOW);
  91.  floodfill(ScreenWidth - 100,
  92.    50, WHITE);
  93.  
  94.  ldisp = (ldisp + 2) % 20;
  95.  DrawManAndUmbrella(x, ldisp);
  96.  hut();
  97.  x = getmaxx() / 5;
  98.  y = getmaxy() / 5;
  99.  
  100.  for (i = 30; i < 100; i++)
  101.  {
  102.   // for animation
  103.   delay(50);
  104.  
  105.   setcolor(i / 10);
  106.  
  107.   arc(x, y, 0, 180, i - 10);
  108.  }
  109.  getch();
  110. }
  111.  
  112. // Driver code
  113. int main()
  114. {
  115.  int gd = DETECT, gm, x = 0;
  116.  
  117.  initgraph(&gd;, &gm;,
  118.    "C:TurboC3BGI");
  119.  
  120.  // executes till any key
  121.  // is pressed
  122.  while (!kbhit())
  123.  {
  124.   hut();
  125.   circle(ScreenWidth - 100,
  126.    50, 30);
  127.   setfillstyle(SOLID_FILL,
  128.      YELLOW);
  129.   floodfill(ScreenWidth - 100,
  130.     50, WHITE);
  131.   line(0, GroundY, ScreenWidth,
  132.    GroundY);
  133.   Rain(x);
  134.  
  135.   ldisp = (ldisp + 2) % 20;
  136.   DrawManAndUmbrella(x, ldisp);
  137.   delay(20);
  138.   cleardevice();
  139.   x = (x + 2) % ScreenWidth;
  140.  }
  141.  // if the key is pressed the
  142.  // rain stops, rainbow appears
  143.  ldisp = (ldisp + 2) % 20;
  144.  DrawManAndUmbrella(x, ldisp);
  145.  rainbow();
  146.  getch();
  147. }
  148.