Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

218 строки
5.1 KiB

  1. /*
  2. * demo demo using libee
  3. * Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <math.h>
  23. #include <string.h>
  24. #include "ee.h"
  25. static void display_menu(void);
  26. static void demo_dots(void);
  27. static void demo_lines(void);
  28. static void demo_circles(void);
  29. static void demo_radar(void);
  30. int clipping = 0;
  31. int main(int argc, char **argv)
  32. {
  33. void (*demo)(void) = NULL;
  34. int quit = 0;
  35. if(ee_init())
  36. {
  37. return 1;
  38. }
  39. display_menu();
  40. /* Go ! */
  41. while(!quit)
  42. {
  43. char key = ee_get_key();
  44. if(key && demo)
  45. {
  46. display_menu();
  47. demo = NULL;
  48. }
  49. else if(key)
  50. {
  51. switch(key)
  52. {
  53. case 'q':
  54. demo = NULL;
  55. quit = 1;
  56. break;
  57. case '1':
  58. ee_clear();
  59. demo = demo_dots;
  60. break;
  61. case '2':
  62. ee_clear();
  63. demo = demo_lines;
  64. break;
  65. case '3':
  66. ee_clear();
  67. demo = demo_circles;
  68. break;
  69. case '4':
  70. ee_clear();
  71. demo = demo_radar;
  72. break;
  73. }
  74. }
  75. if(demo)
  76. demo();
  77. }
  78. /* Clean up */
  79. ee_end();
  80. return 0;
  81. }
  82. static void display_menu(void)
  83. {
  84. int xo = ee_get_width() - 2;
  85. int yo = ee_get_height() - 2;
  86. ee_clear();
  87. ee_color(EE_WHITE);
  88. ee_draw_line(xo, yo, 1, yo, '.');
  89. ee_draw_line(1, yo, 1, 1, ':');
  90. ee_draw_line(xo, 1, xo, yo, ':');
  91. ee_draw_line(1, 1, xo, 1, '.');
  92. ee_goto((xo - strlen("libee demo")) / 2, 3);
  93. ee_putstr("libee demo");
  94. ee_goto((xo - strlen("============")) / 2, 4);
  95. ee_putstr("============");
  96. ee_goto(4, 6);
  97. ee_putstr("1: dots demo");
  98. ee_goto(4, 7);
  99. ee_putstr("2: lines demo");
  100. ee_goto(4, 8);
  101. ee_putstr("3: circles demo");
  102. ee_goto(4, 9);
  103. ee_putstr("4: radar demo");
  104. ee_goto(4, yo - 2);
  105. ee_putstr("q: quit");
  106. ee_refresh();
  107. }
  108. static void demo_dots(void)
  109. {
  110. int i;
  111. for(i=1000; i--;)
  112. {
  113. /* Putpixel */
  114. ee_color(ee_rand(1, 10));
  115. ee_goto(ee_rand(0, ee_get_width() - 1),
  116. ee_rand(0, ee_get_height() - 1));
  117. ee_putchar('#');
  118. }
  119. ee_refresh();
  120. }
  121. static void demo_lines(void)
  122. {
  123. /* Draw lines */
  124. ee_color(ee_rand(1, 10));
  125. if(clipping)
  126. {
  127. ee_draw_line(ee_rand(- ee_get_width(), 2 * ee_get_width()),
  128. ee_rand(- ee_get_height(), 2 * ee_get_height()),
  129. ee_rand(- ee_get_width(), 2 * ee_get_width()),
  130. ee_rand(- ee_get_height(), 2 * ee_get_height()),
  131. '#');
  132. }
  133. else
  134. {
  135. ee_draw_line(ee_rand(0, ee_get_width()),
  136. ee_rand(0, ee_get_height()),
  137. ee_rand(0, ee_get_width()),
  138. ee_rand(0, ee_get_height()),
  139. '*');
  140. }
  141. ee_refresh();
  142. }
  143. static void demo_circles(void)
  144. {
  145. /* Draw circles */
  146. if(clipping)
  147. {
  148. ee_color(ee_rand(1, 10));
  149. ee_draw_circle(ee_rand(- ee_get_width(), 2 * ee_get_width()),
  150. ee_rand(- ee_get_height(), 2 * ee_get_height()),
  151. ee_rand(0, ee_get_width() + ee_get_height()) / 2,
  152. '#');
  153. }
  154. else
  155. {
  156. int x = ee_rand(0, ee_get_width());
  157. int y = ee_rand(0, ee_get_height());
  158. int r = ee_rand(0, (ee_get_width() + ee_get_height()) / 2);
  159. if(x - r < 0 || x + r >= ee_get_width() ||
  160. y - r < 0 || y + r >= ee_get_height())
  161. {
  162. demo_circles();
  163. return;
  164. }
  165. ee_color(ee_rand(1, 10));
  166. ee_draw_circle(x, y, r, '*');
  167. }
  168. ee_refresh();
  169. }
  170. static void demo_radar(void)
  171. {
  172. static int i = 0;
  173. int xo = ee_get_width() / 2;
  174. int yo = ee_get_height() / 2;
  175. int l = ee_get_height() + ee_get_width();
  176. i++;
  177. ee_color(EE_BLUE);
  178. ee_draw_line(xo,yo,xo+(sin(0.03*(i-30))*l*2),yo+(cos(0.03*(i-30))*l),'.');
  179. ee_color(EE_CYAN);
  180. ee_draw_line(xo,yo,xo+(sin(0.03*(i-2))*l*2),yo+(cos(0.03*(i-2))*l),':');
  181. ee_color(EE_WHITE);
  182. ee_draw_line(xo,yo,xo+(sin(0.03*(i-1))*l*2),yo+(cos(0.03*(i-1))*l),':');
  183. ee_color(EE_WHITE);
  184. ee_draw_line(xo,yo,xo+(sin(0.03*i)*l*2),yo+(cos(0.03*i)*l),'#');
  185. ee_refresh();
  186. }