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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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_all(void);
  28. static void demo_dots(void);
  29. static void demo_lines(void);
  30. static void demo_thin_lines(void);
  31. static void demo_circles(void);
  32. static void demo_triangles(void);
  33. static void demo_outlined_triangles(void);
  34. static void demo_sprites(void);
  35. int force_clipping = 0;
  36. struct ee_sprite *sprite = NULL;
  37. int main(int argc, char **argv)
  38. {
  39. void (*demo)(void) = NULL;
  40. int quit = 0;
  41. if(ee_init())
  42. {
  43. return 1;
  44. }
  45. /* Initialize data */
  46. sprite = ee_load_sprite("data/bar_boss");
  47. /* Main menu */
  48. display_menu();
  49. /* Go ! */
  50. while(!quit)
  51. {
  52. char key = ee_get_key();
  53. if(key && demo)
  54. {
  55. display_menu();
  56. demo = NULL;
  57. }
  58. else if(key)
  59. {
  60. switch(key)
  61. {
  62. case 'q':
  63. demo = NULL;
  64. quit = 1;
  65. break;
  66. case '0':
  67. ee_clear();
  68. demo = demo_all;
  69. break;
  70. case '1':
  71. ee_clear();
  72. demo = demo_dots;
  73. break;
  74. case '2':
  75. ee_clear();
  76. demo = demo_lines;
  77. break;
  78. case '3':
  79. ee_clear();
  80. demo = demo_thin_lines;
  81. break;
  82. case '4':
  83. ee_clear();
  84. demo = demo_circles;
  85. break;
  86. case '5':
  87. ee_clear();
  88. demo = demo_triangles;
  89. break;
  90. case '6':
  91. ee_clear();
  92. demo = demo_outlined_triangles;
  93. break;
  94. case '7':
  95. ee_clear();
  96. demo = demo_sprites;
  97. break;
  98. }
  99. }
  100. if(demo)
  101. demo();
  102. }
  103. /* Clean up */
  104. ee_free_sprite(sprite);
  105. ee_end();
  106. return 0;
  107. }
  108. static void display_menu(void)
  109. {
  110. int xo = ee_get_width() - 2;
  111. int yo = ee_get_height() - 2;
  112. ee_clear();
  113. ee_color(EE_WHITE);
  114. ee_draw_line(xo, yo, 1, yo, '.');
  115. ee_draw_line(1, yo, 1, 1, ':');
  116. ee_draw_line(xo, 1, xo, yo, ':');
  117. ee_draw_line(1, 1, xo, 1, '.');
  118. ee_goto((xo - strlen("libee demo")) / 2, 3);
  119. ee_putstr("libee demo");
  120. ee_goto((xo - strlen("============")) / 2, 4);
  121. ee_putstr("============");
  122. ee_goto(4, 6);
  123. ee_putstr("0: complete demo");
  124. ee_goto(4, 7);
  125. ee_putstr("1: dots demo");
  126. ee_goto(4, 8);
  127. ee_putstr("2: lines demo");
  128. ee_goto(4, 9);
  129. ee_putstr("3: thin lines demo");
  130. ee_goto(4, 10);
  131. ee_putstr("4: circles demo");
  132. ee_goto(4, 11);
  133. ee_putstr("5: triangles demo");
  134. ee_goto(4, 12);
  135. ee_putstr("6: outlined triangles demo");
  136. ee_goto(4, 13);
  137. ee_putstr("7: sprites demo");
  138. ee_goto(4, yo - 2);
  139. ee_putstr("q: quit");
  140. ee_refresh();
  141. }
  142. static void demo_all(void)
  143. {
  144. static int i = 0;
  145. int j, xo, yo, x1, y1, x2, y2, x3, y3;
  146. i++;
  147. ee_clear();
  148. /* Draw the sun */
  149. ee_color(EE_YELLOW);
  150. xo = ee_get_width() / 4;
  151. yo = ee_get_height() / 4 + 5 * sin(0.03*i);
  152. for(j = 0; j < 16; j++)
  153. {
  154. x1 = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
  155. y1 = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
  156. ee_draw_thin_line(xo, yo, x1, y1);
  157. }
  158. ee_color(EE_WHITE);
  159. for(j = 15 + sin(0.03*i) * 8; j--;)
  160. {
  161. ee_draw_circle(xo, yo, j, '#');
  162. }
  163. ee_color(EE_YELLOW);
  164. ee_draw_circle(xo, yo, 15 + sin(0.03*i) * 8, '#');
  165. /* Draw the pyramid */
  166. xo = ee_get_width() * 5 / 8;
  167. yo = 2;
  168. x1 = ee_get_width() / 8 + sin(0.03*i) * 5;
  169. y1 = ee_get_height() / 2 + cos(0.03*i) * 5;
  170. x2 = ee_get_width() - 10 - cos(0.02*i) * 10;
  171. y2 = ee_get_height() * 3 / 4 - 5 + sin(0.02*i) * 5;
  172. x3 = ee_get_width() / 4 - sin(0.02*i) * 5;
  173. y3 = ee_get_height() * 3 / 4 + cos(0.02*i) * 5;
  174. ee_color(EE_GREEN);
  175. ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%');
  176. ee_color(EE_YELLOW);
  177. ee_draw_thin_line(xo, yo, x2, y2);
  178. ee_draw_thin_line(x2, y2, x1, y1);
  179. ee_draw_thin_line(x1, y1, xo, yo);
  180. ee_color(EE_RED);
  181. ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
  182. ee_color(EE_YELLOW);
  183. ee_draw_thin_line(x1, y1, x2, y2);
  184. ee_draw_thin_line(x2, y2, x3, y3);
  185. ee_draw_thin_line(x3, y3, x1, y1);
  186. ee_color(EE_BLUE);
  187. ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%');
  188. ee_color(EE_YELLOW);
  189. ee_draw_thin_line(xo, yo, x2, y2);
  190. ee_draw_thin_line(x2, y2, x3, y3);
  191. ee_draw_thin_line(x3, y3, xo, yo);
  192. /* Draw a background triangle */
  193. x1 = 2;
  194. y1 = 2;
  195. x2 = ee_get_width() - 3;
  196. y2 = ee_get_height() / 2;
  197. x3 = ee_get_width() / 3;
  198. y3 = ee_get_height() - 3;
  199. ee_color(EE_BLUE);
  200. // ee_fill_triangle(x1, y1, x2, y2, x3, y3, '.');
  201. ee_color(EE_CYAN);
  202. ee_draw_thin_line(x1, y1, x3, y3);
  203. ee_draw_thin_line(x2, y2, x1, y1);
  204. ee_draw_thin_line(x3, y3, x2, y2);
  205. xo = ee_get_width() / 2 + cos(0.027*i) * ee_get_width() / 3;
  206. yo = ee_get_height() / 2 - sin(0.027*i) * ee_get_height() / 2;
  207. ee_draw_thin_line(x1, y1, xo, yo);
  208. ee_draw_thin_line(x2, y2, xo, yo);
  209. ee_draw_thin_line(x3, y3, xo, yo);
  210. /* Draw a sprite behind the pyramid */
  211. ee_draw_sprite(xo, yo, sprite);
  212. /* Draw a trail behind the foreground sprite */
  213. for(j = i - 60; j < i; j++)
  214. {
  215. int delta = ee_rand(-5, 5);
  216. ee_color(ee_rand(1, 10));
  217. ee_goto(ee_get_width() / 2
  218. + cos(0.02*j) * (delta + ee_get_width() / 4),
  219. ee_get_height() / 2
  220. + sin(0.02*j) * (delta + ee_get_height() / 3));
  221. ee_putchar('#');
  222. }
  223. /* Draw foreground sprite */
  224. ee_draw_sprite(ee_get_width() / 2 + cos(0.02*i) * ee_get_width() / 4,
  225. ee_get_height() / 2 + sin(0.02*i) * ee_get_height() / 3,
  226. sprite);
  227. ee_refresh();
  228. }
  229. static void demo_dots(void)
  230. {
  231. int xmax = ee_get_width() - 1;
  232. int ymax = ee_get_height() - 1;
  233. int i;
  234. for(i = 1000; i--;)
  235. {
  236. /* Putpixel */
  237. ee_color(ee_rand(1, 10));
  238. ee_goto(ee_rand(0, xmax), ee_rand(0, ymax));
  239. ee_putchar('#');
  240. }
  241. ee_refresh();
  242. }
  243. static void demo_lines(void)
  244. {
  245. int w = ee_get_width();
  246. int h = ee_get_height();
  247. /* Draw lines */
  248. ee_color(ee_rand(1, 10));
  249. if(force_clipping)
  250. {
  251. ee_draw_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  252. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#');
  253. }
  254. else
  255. {
  256. ee_draw_line(ee_rand(0, w - 1), ee_rand(0, h - 1),
  257. ee_rand(0, w - 1), ee_rand(0, h - 1), '#');
  258. }
  259. ee_refresh();
  260. }
  261. static void demo_thin_lines(void)
  262. {
  263. int w = ee_get_width();
  264. int h = ee_get_height();
  265. /* Draw lines */
  266. ee_color(ee_rand(1, 10));
  267. if(force_clipping)
  268. {
  269. ee_draw_thin_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  270. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h));
  271. }
  272. else
  273. {
  274. ee_draw_thin_line(ee_rand(0, w), ee_rand(0, h),
  275. ee_rand(0, w), ee_rand(0, h));
  276. }
  277. ee_refresh();
  278. }
  279. static void demo_circles(void)
  280. {
  281. int w = ee_get_width();
  282. int h = ee_get_height();
  283. /* Draw circles */
  284. if(force_clipping)
  285. {
  286. ee_color(ee_rand(1, 10));
  287. ee_draw_circle(ee_rand(- w, 2 * w),
  288. ee_rand(- h, 2 * h),
  289. ee_rand(0, (w + h) / 2),
  290. '#');
  291. }
  292. else
  293. {
  294. int x = ee_rand(0, w);
  295. int y = ee_rand(0, h);
  296. int r = ee_rand(0, (w + h) / 2);
  297. if(x - r < 0 || x + r >= w || y - r < 0 || y + r >= h)
  298. {
  299. demo_circles();
  300. return;
  301. }
  302. ee_color(ee_rand(1, 10));
  303. ee_draw_circle(x, y, r, '#');
  304. }
  305. ee_refresh();
  306. }
  307. static void demo_triangles(void)
  308. {
  309. int w = ee_get_width();
  310. int h = ee_get_height();
  311. /* Draw lines */
  312. ee_color(ee_rand(1, 10));
  313. if(force_clipping)
  314. {
  315. ee_fill_triangle(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  316. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),
  317. ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#');
  318. }
  319. else
  320. {
  321. ee_fill_triangle(ee_rand(0, w - 1), ee_rand(0, h - 1),
  322. ee_rand(0, w - 1), ee_rand(0, h - 1),
  323. ee_rand(0, w - 1), ee_rand(0, h - 1), '#');
  324. }
  325. ee_refresh();
  326. }
  327. static void demo_outlined_triangles(void)
  328. {
  329. int w = ee_get_width();
  330. int h = ee_get_height();
  331. int x1, y1, x2, y2, x3, y3;
  332. /* Draw lines */
  333. ee_color(ee_rand(1, 10));
  334. if(force_clipping)
  335. {
  336. x1 = ee_rand(- w, 2 * w);
  337. y1 = ee_rand(- h, 2 * h);
  338. x2 = ee_rand(- w, 2 * w);
  339. y2 = ee_rand(- h, 2 * h);
  340. x3 = ee_rand(- w, 2 * w);
  341. y3 = ee_rand(- h, 2 * h);
  342. }
  343. else
  344. {
  345. x1 = ee_rand(0, w - 1);
  346. y1 = ee_rand(0, h - 1);
  347. x2 = ee_rand(0, w - 1);
  348. y2 = ee_rand(0, h - 1);
  349. x3 = ee_rand(0, w - 1);
  350. y3 = ee_rand(0, h - 1);
  351. }
  352. ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
  353. ee_color(ee_rand(1, 10));
  354. ee_draw_thin_line(x1, y1, x2, y2);
  355. ee_draw_thin_line(x2, y2, x3, y3);
  356. ee_draw_thin_line(x3, y3, x1, y1);
  357. ee_refresh();
  358. }
  359. static void demo_sprites(void)
  360. {
  361. ee_draw_sprite(ee_rand(0, ee_get_width() - 1),
  362. ee_rand(0, ee_get_height() - 1), sprite);
  363. ee_refresh();
  364. }
  365. static void demo_pyramid(void)
  366. {
  367. static int i = 0;
  368. int xo, yo, x1, y1, x2, y2, x3, y3;
  369. i++;
  370. xo = ee_get_width() * 5 / 8;
  371. yo = 2;
  372. x1 = ee_get_width() / 8 + sin(0.03*i) * 5;
  373. y1 = ee_get_height() / 2 + cos(0.03*i) * 5;
  374. x2 = ee_get_width() - 10 - cos(0.02*i) * 10;
  375. y2 = ee_get_height() - 5 + sin(0.02*i) * 5;
  376. x3 = ee_get_width() / 4 - sin(0.02*i) * 5;
  377. y3 = ee_get_height() + cos(0.02*i) * 5;
  378. ee_clear();
  379. ee_color(EE_GREEN);
  380. ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%');
  381. ee_color(EE_YELLOW);
  382. ee_draw_thin_line(xo, yo, x2, y2);
  383. ee_draw_thin_line(x2, y2, x1, y1);
  384. ee_draw_thin_line(x1, y1, xo, yo);
  385. ee_color(EE_RED);
  386. ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
  387. ee_color(EE_YELLOW);
  388. ee_draw_thin_line(x1, y1, x2, y2);
  389. ee_draw_thin_line(x2, y2, x3, y3);
  390. ee_draw_thin_line(x3, y3, x1, y1);
  391. ee_color(EE_BLUE);
  392. ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%');
  393. ee_color(EE_YELLOW);
  394. ee_draw_thin_line(xo, yo, x2, y2);
  395. ee_draw_thin_line(x2, y2, x3, y3);
  396. ee_draw_thin_line(x3, y3, xo, yo);
  397. ee_refresh();
  398. }