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.
 
 
 
 
 
 

89 lines
2.2 KiB

  1. #!/usr/bin/php5
  2. <?
  3. function display_menu($cv, $dp) {
  4. $xo = caca_get_canvas_width($cv) - 2;
  5. $yo = caca_get_canvas_height($cv) - 2;
  6. caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
  7. caca_clear_canvas($cv);
  8. caca_draw_thin_box($cv, 1, 1, $xo, $yo);
  9. caca_put_str($cv, ($xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
  10. caca_put_str($cv, ($xo - strlen("==============")) / 2, 4, "==============");
  11. caca_put_str($cv, 4, 6, "demos:");
  12. caca_put_str($cv, 4, 7, "'f': full");
  13. caca_put_str($cv, 4, 8, "'1': dots");
  14. caca_put_str($cv, 4, 9, "'2': lines");
  15. caca_put_str($cv, 4, 10, "'3': boxes");
  16. caca_put_str($cv, 4, 11, "'4': triangles");
  17. caca_put_str($cv, 4, 12, "'5': ellipses");
  18. caca_put_str($cv, 4, 13, "'c': colour");
  19. caca_put_str($cv, 4, 14, "'r': render");
  20. if ($sprite)
  21. caca_put_str($cv, 4, 15, "'s': sprites");
  22. caca_put_str($cv, 4, 16, "settings:");
  23. caca_put_str($cv, 4, 17, "'o': outline: ".((outline == 0) ? "none" : ((outline == 1) ? "solid" : "thin")));
  24. caca_put_str($cv, 4, 18, "'b': drawing boundaries: ".((bounds == 0) ? "screen" : "infinite"));
  25. caca_put_str($cv, 4, $yo - 2, "'q': quit");
  26. caca_refresh_display($dp);
  27. }
  28. function main() {
  29. $cv = caca_create_canvas(0, 0);
  30. if (!$cv) {
  31. die("Error while creating canvas\n");
  32. }
  33. $dp = caca_create_display($cv);
  34. if (!$dp) {
  35. die("Error while attaching canvas to display\n");
  36. }
  37. display_menu($cv, $dp);
  38. caca_set_display_time($dp, 40000);
  39. /* Disable cursor */
  40. caca_set_mouse($dp, 0);
  41. /* Main menu */
  42. display_menu($cv, $dp);
  43. caca_refresh_display($dp);
  44. sleep(1);
  45. for ($i = 0; $i < 100; $i++) {
  46. demo_lines($cv, true, 2);
  47. caca_refresh_display($dp);
  48. }
  49. }
  50. function demo_lines($cv, $bounds = true, $outline = 1) {
  51. $w = caca_get_canvas_width($cv);
  52. $h = caca_get_canvas_height($cv);
  53. if ($bounds) {
  54. $xa = caca_rand(- $w, 2 * $w); $ya = caca_rand(- $h, 2 * $h);
  55. $xb = caca_rand(- $w, 2 * $w); $yb = caca_rand(- $h, 2 * $h);
  56. }
  57. else {
  58. $xa = caca_rand(0, $w); $ya = caca_rand(0, $h);
  59. $xb = caca_rand(0, $w); $yb = caca_rand(0, $h);
  60. }
  61. caca_set_color_ansi($cv, caca_rand(0, 16), CACA_BLACK);
  62. if ($outline > 1)
  63. caca_draw_thin_line($cv, $xa, $ya, $xb, $yb);
  64. else
  65. caca_draw_line($cv, $xa, $ya, $xb, $yb, '#');
  66. }
  67. main();