You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

245 lines
5.5 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_thin_lines(void);
  29. static void demo_circles(void);
  30. static void demo_radar(void);
  31. int clipping = 0;
  32. int main(int argc, char **argv)
  33. {
  34. void (*demo)(void) = NULL;
  35. int quit = 0;
  36. if(ee_init())
  37. {
  38. return 1;
  39. }
  40. display_menu();
  41. /* Go ! */
  42. while(!quit)
  43. {
  44. char key = ee_get_key();
  45. if(key && demo)
  46. {
  47. display_menu();
  48. demo = NULL;
  49. }
  50. else if(key)
  51. {
  52. switch(key)
  53. {
  54. case 'q':
  55. demo = NULL;
  56. quit = 1;
  57. break;
  58. case '1':
  59. ee_clear();
  60. demo = demo_dots;
  61. break;
  62. case '2':
  63. ee_clear();
  64. demo = demo_lines;
  65. break;
  66. case '3':
  67. ee_clear();
  68. demo = demo_thin_lines;
  69. break;
  70. case '4':
  71. ee_clear();
  72. demo = demo_circles;
  73. break;
  74. case '5':
  75. ee_clear();
  76. demo = demo_radar;
  77. break;
  78. }
  79. }
  80. if(demo)
  81. demo();
  82. }
  83. /* Clean up */
  84. ee_end();
  85. return 0;
  86. }
  87. static void display_menu(void)
  88. {
  89. int xo = ee_get_width() - 2;
  90. int yo = ee_get_height() - 2;
  91. ee_clear();
  92. ee_color(EE_WHITE);
  93. ee_draw_line(xo, yo, 1, yo, '.');
  94. ee_draw_line(1, yo, 1, 1, ':');
  95. ee_draw_line(xo, 1, xo, yo, ':');
  96. ee_draw_line(1, 1, xo, 1, '.');
  97. ee_goto((xo - strlen("libee demo")) / 2, 3);
  98. ee_putstr("libee demo");
  99. ee_goto((xo - strlen("============")) / 2, 4);
  100. ee_putstr("============");
  101. ee_goto(4, 6);
  102. ee_putstr("1: dots demo");
  103. ee_goto(4, 7);
  104. ee_putstr("2: lines demo");
  105. ee_goto(4, 8);
  106. ee_putstr("3: thin lines demo");
  107. ee_goto(4, 9);
  108. ee_putstr("4: circles demo");
  109. ee_goto(4, 10);
  110. ee_putstr("5: radar demo");
  111. ee_goto(4, yo - 2);
  112. ee_putstr("q: quit");
  113. ee_refresh();
  114. }
  115. static void demo_dots(void)
  116. {
  117. int xmax = ee_get_width() - 1;
  118. int ymax = ee_get_height() - 1;
  119. int i;
  120. for(i = 1000; i--;)
  121. {
  122. /* Putpixel */
  123. ee_color(ee_rand(1, 10));
  124. ee_goto(ee_rand(0, xmax), ee_rand(0, ymax));
  125. ee_putchar('#');
  126. }
  127. ee_refresh();
  128. }
  129. static void demo_lines(void)
  130. {
  131. int w = ee_get_width();
  132. int h = ee_get_height();
  133. /* Draw lines */
  134. ee_color(ee_rand(1, 10));
  135. if(clipping)
  136. {
  137. ee_draw_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  138. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#');
  139. }
  140. else
  141. {
  142. ee_draw_line(ee_rand(0, w - 1), ee_rand(0, h - 1),
  143. ee_rand(0, w - 1), ee_rand(0, h - 1), '*');
  144. }
  145. ee_refresh();
  146. }
  147. static void demo_thin_lines(void)
  148. {
  149. int w = ee_get_width();
  150. int h = ee_get_height();
  151. /* Draw lines */
  152. ee_color(ee_rand(1, 10));
  153. if(clipping)
  154. {
  155. ee_draw_thin_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  156. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h));
  157. }
  158. else
  159. {
  160. ee_draw_thin_line(ee_rand(0, w), ee_rand(0, h),
  161. ee_rand(0, w), ee_rand(0, h));
  162. }
  163. ee_refresh();
  164. }
  165. static void demo_circles(void)
  166. {
  167. int w = ee_get_width();
  168. int h = ee_get_height();
  169. /* Draw circles */
  170. if(clipping)
  171. {
  172. ee_color(ee_rand(1, 10));
  173. ee_draw_circle(ee_rand(- w, 2 * w),
  174. ee_rand(- h, 2 * h),
  175. ee_rand(0, (w + h) / 2),
  176. '#');
  177. }
  178. else
  179. {
  180. int x = ee_rand(0, w);
  181. int y = ee_rand(0, h);
  182. int r = ee_rand(0, (w + h) / 2);
  183. if(x - r < 0 || x + r >= w || y - r < 0 || y + r >= h)
  184. {
  185. demo_circles();
  186. return;
  187. }
  188. ee_color(ee_rand(1, 10));
  189. ee_draw_circle(x, y, r, '*');
  190. }
  191. ee_refresh();
  192. }
  193. static void demo_radar(void)
  194. {
  195. static int i = 0;
  196. int xo = ee_get_width() / 2;
  197. int yo = ee_get_height() / 2;
  198. int l = ee_get_height() + ee_get_width();
  199. i++;
  200. ee_color(EE_BLUE);
  201. ee_draw_line(xo,yo,xo+(sin(0.03*(i-30))*l*2),yo+(cos(0.03*(i-30))*l),'.');
  202. ee_color(EE_CYAN);
  203. ee_draw_line(xo,yo,xo+(sin(0.03*(i-2))*l*2),yo+(cos(0.03*(i-2))*l),':');
  204. ee_color(EE_WHITE);
  205. ee_draw_line(xo,yo,xo+(sin(0.03*(i-1))*l*2),yo+(cos(0.03*(i-1))*l),':');
  206. ee_color(EE_WHITE);
  207. ee_draw_line(xo,yo,xo+(sin(0.03*i)*l*2),yo+(cos(0.03*i)*l),'#');
  208. ee_refresh();
  209. }