Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <graphics.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <dos.h>
  6.  
  7. #define MAXPOINT 100
  8. #define DELAY 100
  9.  
  10. struct point {
  11. int x, y, state, color, congtru;
  12. };
  13.  
  14. void drawpoint(struct point p, int vexoa)
  15. {
  16. int color;
  17. if (vexoa)
  18. color = p.color;
  19. else
  20. color = BLACK;
  21. setcolor(color);
  22. switch(p.state)
  23. {
  24. case 0: putpixel(p.x, p.y, color);
  25. break;
  26. case 1: line(p.x-1, p.y, p.x+1, p.y);
  27. line(p.x, p.y-1, p.x, p.y+1);
  28. break;
  29. case 2: line(p.x-2, p.y, p.x+2, p.y);
  30. line(p.x, p.y-2, p.x, p.y+2);
  31. break;
  32. case 3: line(p.x-4, p.y, p.x+4, p.y);
  33. line(p.x, p.y-4, p.x, p.y+4);
  34. rectangle(p.x-1, p.y-1, p.x+1, p.y+1);
  35. break;
  36. }
  37. }
  38. void drawstar()
  39. {
  40. struct point p[MAXPOINT];
  41. int maxx, maxy;
  42. maxx = getmaxx();
  43. maxy = getmaxy();
  44. for (int i=0; i<MAXPOINT; i++){
  45. p[i].x = rand() % maxx;
  46. p[i].y = rand() % maxy;
  47. p[i].state = rand() % 6;
  48. p[i].color = rand() % 17;
  49. p[i].congtru = rand() % 3;
  50. }
  51.  
  52. while (!kbhit()){
  53. for (int i=0; i<MAXPOINT; i++)
  54. drawpoint(p[i], 1);
  55. delay(DELAY);
  56. for (int i=0; i<MAXPOINT; i++)
  57. drawpoint(p[i], 0);
  58. for (int i=0; i<MAXPOINT; i++){
  59. if (p[i].congtru){
  60. p[i].state++;
  61. if (p[i].state >= 3)
  62. p[i].congtru = 0;
  63. }
  64. else{
  65. p[i].state--;
  66. if (p[i].state <= 0)
  67. p[i].congtru = 1;
  68. }
  69. }
  70. }
  71. }
  72.  
  73. int main()
  74. {
  75. int i, gd = DETECT, gm ;
  76. initgraph(&gd, &gm, "");
  77. srand(time(NULL));
  78. drawstar();
  79. closegraph();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement