Advertisement
junest

dohoamaytinh

Mar 17th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <graphics.h>
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include "windows.h"
  7. using namespace std;
  8. void KhoiTaoDohoa()
  9. {
  10. int driver=0,mode;
  11. initgraph(&driver,&mode,"");
  12. }
  13. void Bresenham_Circle(int xc, int yc, int Radius, int color)
  14. {
  15. int x, y, d;
  16. x = 0; y = Radius;
  17. d = 3 - 2 * Radius;
  18. while (x <= y)
  19. {
  20. putpixel(xc + x, yc + y, color);
  21. putpixel(xc - x, yc + y, color);
  22. putpixel(xc + x, yc - y, color);
  23. putpixel(xc - x, yc - y, color);
  24. putpixel(xc + y, yc + x, color);
  25. putpixel(xc - y, yc + x, color);
  26. putpixel(xc + y, yc - x, color);
  27. putpixel(xc - y, yc - x, color);
  28. if (d < 0)
  29. d+=4*x+6;
  30. else {
  31. d+=4*(x-y)+10;
  32. y--;
  33. }
  34. x++;
  35. }
  36. }
  37. void bline(int x1,int y1,int x2,int y2,int color)
  38. // 0<m<1
  39. {
  40. int x_max,x,y;
  41. int dx=abs(x1-x2);
  42. int dy=abs(y1-y2);
  43. int c1=2*dy;
  44. int c2=2*(dy-dx);
  45. int p=2*dy-dx;
  46. if (x1>x2)
  47. {
  48. x=x2; y=y2; x_max=x1;
  49. }
  50. else
  51. {
  52. x=x1; y=y1; x_max=x2;
  53. }
  54. putpixel(x,y,color);
  55. delay(5);
  56. while (x < x_max)
  57. {
  58. x=x+1;
  59. if (p<0) p=p+c1;
  60. else
  61. {
  62. y=y+1;
  63. p=p+c2;
  64. }
  65. putpixel(x,y,color);
  66. delay(5);
  67. }
  68. }
  69. int main(int argc, char *argv[])
  70. {
  71. KhoiTaoDohoa();
  72. setbkcolor(2);
  73. setcolor(YELLOW);
  74. line(1,100,800,100);
  75. delay(5000);
  76. bline(1,100,800,100,2);
  77. // Bresenham_Circle(
  78. //circle(200,150,100);
  79. setcolor(10); // set text color
  80. outtextxy(250,100,"DRAW A HOUSE");// print text in window graphics
  81. setcolor(6);
  82. line(300,120,500,180);
  83. delay(50);
  84. line(100,180,300,120);
  85. delay(50);
  86. line(100,180,500,180);
  87. setcolor(6);
  88. line(160,180,160,400);
  89. delay(50);
  90. line(440,180,440,400);
  91. delay(50);
  92. line(160,400,440,400);
  93. setcolor(6);
  94. rectangle(250,240,350,399);
  95. setfillstyle(1,RED);
  96. floodfill(300,160,6);
  97. setfillstyle(1,BLUE);
  98. floodfill(300,230,6);
  99. setfillstyle(1,WHITE);
  100. floodfill(300,360,6);
  101. setcolor(6);
  102. setfillstyle(1,YELLOW);
  103. rectangle(180,200,220,240);
  104. rectangle(420,200,380,240);
  105. floodfill(200,220,6);
  106. floodfill(400,220,6);
  107. line(200,200,200,240);
  108. line(180,220,220,220);
  109. line(400,200,400,240);
  110. line(420,220,380,220);
  111. line(300,240,300,399);
  112. line(298,240,298,399);
  113. setfillstyle(1,BLACK);
  114. circle(310,320,5);
  115. circle(290,320,5);
  116. floodfill(310,320,6);
  117. floodfill(290,320,6);
  118.  
  119. setfillstyle(1,YELLOW);
  120. for (int i=1;i<=200;i++)
  121. {
  122. setcolor(i%13);
  123. circle(300,50,40);
  124. setfillstyle(1,i%13);
  125. floodfill(300,50,i%13);
  126. delay(1000);
  127. };
  128.  
  129. while(!kbhit()) delay(1); // pause screen
  130. system("PAUSE");
  131. return EXIT_SUCCESS;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement