Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

334 Zeilen
7.7 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 "config.h"
  23. #include <math.h>
  24. #include <string.h>
  25. #include "ee.h"
  26. static void display_menu(void);
  27. static void demo_dots(void);
  28. static void demo_lines(void);
  29. static void demo_thin_lines(void);
  30. static void demo_circles(void);
  31. static void demo_triangles(void);
  32. static void demo_outlined_triangles(void);
  33. int clipping = 0;
  34. int main(int argc, char **argv)
  35. {
  36. void (*demo)(void) = NULL;
  37. int quit = 0;
  38. if(ee_init())
  39. {
  40. return 1;
  41. }
  42. display_menu();
  43. /* Go ! */
  44. while(!quit)
  45. {
  46. char key = ee_get_key();
  47. if(key && demo)
  48. {
  49. display_menu();
  50. demo = NULL;
  51. }
  52. else if(key)
  53. {
  54. switch(key)
  55. {
  56. case 'q':
  57. demo = NULL;
  58. quit = 1;
  59. break;
  60. case '1':
  61. ee_clear();
  62. demo = demo_dots;
  63. break;
  64. case '2':
  65. ee_clear();
  66. demo = demo_lines;
  67. break;
  68. case '3':
  69. ee_clear();
  70. demo = demo_thin_lines;
  71. break;
  72. case '4':
  73. ee_clear();
  74. demo = demo_circles;
  75. break;
  76. case '5':
  77. ee_clear();
  78. demo = demo_triangles;
  79. break;
  80. case '6':
  81. ee_clear();
  82. demo = demo_outlined_triangles;
  83. break;
  84. }
  85. }
  86. if(demo)
  87. demo();
  88. }
  89. /* Clean up */
  90. ee_end();
  91. return 0;
  92. }
  93. static void display_menu(void)
  94. {
  95. int xo = ee_get_width() - 2;
  96. int yo = ee_get_height() - 2;
  97. ee_clear();
  98. ee_color(EE_WHITE);
  99. ee_draw_line(xo, yo, 1, yo, '.');
  100. ee_draw_line(1, yo, 1, 1, ':');
  101. ee_draw_line(xo, 1, xo, yo, ':');
  102. ee_draw_line(1, 1, xo, 1, '.');
  103. ee_goto((xo - strlen("libee demo")) / 2, 3);
  104. ee_putstr("libee demo");
  105. ee_goto((xo - strlen("============")) / 2, 4);
  106. ee_putstr("============");
  107. ee_goto(4, 6);
  108. ee_putstr("1: dots demo");
  109. ee_goto(4, 7);
  110. ee_putstr("2: lines demo");
  111. ee_goto(4, 8);
  112. ee_putstr("3: thin lines demo");
  113. ee_goto(4, 9);
  114. ee_putstr("4: circles demo");
  115. ee_goto(4, 10);
  116. ee_putstr("5: triangles demo");
  117. ee_goto(4, 11);
  118. ee_putstr("6: outlined triangles demo");
  119. ee_goto(4, yo - 2);
  120. ee_putstr("q: quit");
  121. ee_refresh();
  122. }
  123. static void demo_dots(void)
  124. {
  125. int xmax = ee_get_width() - 1;
  126. int ymax = ee_get_height() - 1;
  127. int i;
  128. for(i = 1000; i--;)
  129. {
  130. /* Putpixel */
  131. ee_color(ee_rand(1, 10));
  132. ee_goto(ee_rand(0, xmax), ee_rand(0, ymax));
  133. ee_putchar('#');
  134. }
  135. ee_refresh();
  136. }
  137. static void demo_lines(void)
  138. {
  139. int w = ee_get_width();
  140. int h = ee_get_height();
  141. /* Draw lines */
  142. ee_color(ee_rand(1, 10));
  143. if(clipping)
  144. {
  145. ee_draw_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  146. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#');
  147. }
  148. else
  149. {
  150. ee_draw_line(ee_rand(0, w - 1), ee_rand(0, h - 1),
  151. ee_rand(0, w - 1), ee_rand(0, h - 1), '#');
  152. }
  153. ee_refresh();
  154. }
  155. static void demo_thin_lines(void)
  156. {
  157. int w = ee_get_width();
  158. int h = ee_get_height();
  159. /* Draw lines */
  160. ee_color(ee_rand(1, 10));
  161. if(clipping)
  162. {
  163. ee_draw_thin_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  164. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h));
  165. }
  166. else
  167. {
  168. ee_draw_thin_line(ee_rand(0, w), ee_rand(0, h),
  169. ee_rand(0, w), ee_rand(0, h));
  170. }
  171. ee_refresh();
  172. }
  173. static void demo_circles(void)
  174. {
  175. int w = ee_get_width();
  176. int h = ee_get_height();
  177. /* Draw circles */
  178. if(clipping)
  179. {
  180. ee_color(ee_rand(1, 10));
  181. ee_draw_circle(ee_rand(- w, 2 * w),
  182. ee_rand(- h, 2 * h),
  183. ee_rand(0, (w + h) / 2),
  184. '#');
  185. }
  186. else
  187. {
  188. int x = ee_rand(0, w);
  189. int y = ee_rand(0, h);
  190. int r = ee_rand(0, (w + h) / 2);
  191. if(x - r < 0 || x + r >= w || y - r < 0 || y + r >= h)
  192. {
  193. demo_circles();
  194. return;
  195. }
  196. ee_color(ee_rand(1, 10));
  197. ee_draw_circle(x, y, r, '#');
  198. }
  199. ee_refresh();
  200. }
  201. static void demo_triangles(void)
  202. {
  203. int w = ee_get_width();
  204. int h = ee_get_height();
  205. /* Draw lines */
  206. ee_color(ee_rand(1, 10));
  207. if(clipping)
  208. {
  209. ee_fill_triangle(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  210. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  211. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#');
  212. }
  213. else
  214. {
  215. ee_fill_triangle(ee_rand(0, w - 1), ee_rand(0, h - 1),
  216. ee_rand(0, w - 1), ee_rand(0, h - 1),
  217. ee_rand(0, w - 1), ee_rand(0, h - 1), '#');
  218. }
  219. ee_refresh();
  220. }
  221. static void demo_outlined_triangles(void)
  222. {
  223. int w = ee_get_width();
  224. int h = ee_get_height();
  225. /* Draw lines */
  226. ee_color(ee_rand(1, 10));
  227. if(clipping)
  228. {
  229. ee_fill_triangle(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  230. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  231. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#');
  232. }
  233. else
  234. {
  235. int x1, y1, x2, y2, x3, y3;
  236. x1 = ee_rand(0, w - 1);
  237. y1 = ee_rand(0, h - 1);
  238. x2 = ee_rand(0, w - 1);
  239. y2 = ee_rand(0, h - 1);
  240. x3 = ee_rand(0, w - 1);
  241. y3 = ee_rand(0, h - 1);
  242. ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
  243. ee_color(ee_rand(1, 10));
  244. ee_draw_thin_line(x1, y1, x2, y2);
  245. ee_draw_thin_line(x2, y2, x3, y3);
  246. ee_draw_thin_line(x3, y3, x1, y1);
  247. }
  248. ee_refresh();
  249. }
  250. static void demo_pyramid(void)
  251. {
  252. static int i = 0;
  253. int xo, yo, x1, y1, x2, y2, x3, y3;
  254. i++;
  255. xo = ee_get_width() * 5 / 8;
  256. yo = 2;
  257. x1 = ee_get_width() / 8 + sin(0.03*i) * 5;
  258. y1 = ee_get_height() / 2 + cos(0.03*i) * 5;
  259. x2 = ee_get_width() - 10 - cos(0.02*i) * 10;
  260. y2 = ee_get_height() - 5 + sin(0.02*i) * 5;
  261. x3 = ee_get_width() / 4 - sin(0.02*i) * 5;
  262. y3 = ee_get_height() + cos(0.02*i) * 5;
  263. ee_clear();
  264. ee_color(EE_GREEN);
  265. ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%');
  266. ee_color(EE_YELLOW);
  267. ee_draw_thin_line(xo, yo, x2, y2);
  268. ee_draw_thin_line(x2, y2, x1, y1);
  269. ee_draw_thin_line(x1, y1, xo, yo);
  270. ee_color(EE_RED);
  271. ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
  272. ee_color(EE_YELLOW);
  273. ee_draw_thin_line(x1, y1, x2, y2);
  274. ee_draw_thin_line(x2, y2, x3, y3);
  275. ee_draw_thin_line(x3, y3, x1, y1);
  276. ee_color(EE_BLUE);
  277. ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%');
  278. ee_color(EE_YELLOW);
  279. ee_draw_thin_line(xo, yo, x2, y2);
  280. ee_draw_thin_line(x2, y2, x3, y3);
  281. ee_draw_thin_line(x3, y3, xo, yo);
  282. ee_refresh();
  283. }