fork download
  1. #include <graphics.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <math.h>
  5.  
  6. void tree(int x, int y, int height, float angle);
  7.  
  8. float branch_rotation = 30.0f;
  9. float branch_height_factor = 0.73;
  10.  
  11. void draw_loop()
  12. {
  13. int x = getmaxx() / 2;
  14. int y = getmaxy();
  15. int height = y - 32;
  16. float angle = -90;
  17.  
  18. setcolor(15);
  19.  
  20. while (1)
  21. {
  22. clrscr();
  23.  
  24. char message[128];
  25. sprintf(message, "height: %d; rotation: %f (z/x); branch offset %f (a/s)",
  26. height, branch_rotation, branch_height_factor);
  27. outtextxy(10, 10, message);
  28.  
  29. setcolor(11);
  30. tree(x, y, height, angle);
  31.  
  32. switch (getch())
  33. {
  34. case 'z':
  35. branch_rotation -= 1.0f;
  36. break;
  37.  
  38. case 'x':
  39. branch_rotation += 1.0f;
  40. break;
  41.  
  42. case 'a':
  43. branch_height_factor -= 0.01f;
  44. break;
  45.  
  46. case 's':
  47. branch_height_factor += 0.01f;
  48. break;
  49.  
  50. case ' ':
  51. case 'q':
  52. case 27: // Escape.
  53. return;
  54.  
  55. default:
  56. break;
  57. }
  58. }
  59. }
  60.  
  61. int main()
  62. {
  63. int gddriver = DETECT, gmode, errorcode;
  64. initgraph(&gddriver, &gmode, "");
  65. draw_loop();
  66. closegraph();
  67. return 0;
  68. }
  69.  
  70.  
  71.  
  72. void tree(int x, int y, int height, float angle)
  73. {
  74. // Convert angle to radians.
  75. float angle_rad = angle * (M_PI / 180.0);
  76.  
  77. // Calculate a direction vector.
  78. float xf = cos(angle_rad);
  79. float yf = sin(angle_rad);
  80.  
  81. // Draw subtrees.
  82. int branch_height = (int) (height * branch_height_factor);
  83. int branch_start_x = x + (int) (xf * (height - branch_height));
  84. int branch_start_y = y + (int) (yf * (height - branch_height));
  85.  
  86. // Stop recursion for extreme cases.
  87. if (branch_height < 1 || branch_height >= height)
  88. {
  89. return;
  90. }
  91.  
  92. // Draw the center of the (sub)tree.
  93. line(x, y, x + (int) (xf * height ), y + (int) (yf * height));
  94.  
  95. tree(branch_start_x, branch_start_y, branch_height, angle - branch_rotation);
  96. tree(branch_start_x, branch_start_y, branch_height, angle + branch_rotation);
  97. }
  98.  
  99.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:22: fatal error: graphics.h: No such file or directory
compilation terminated.
stdout
Standard output is empty