Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

polyline.php 1.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/php5
  2. <?php
  3. /*
  4. * polyline.php sample program for libcaca php binding
  5. * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
  6. *
  7. * This program is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What the Fuck You Want
  10. * to Public License, Version 2, as published by Sam Hocevar. See
  11. * http://www.wtfpl.net/ for more details.
  12. */
  13. function transform($tbl, $tx, $ty, $sx, $sy) {
  14. $result = array();
  15. foreach($tbl as $pt)
  16. $result[] = array($pt[0] * $sx + $tx, $pt[1] * $sy + $ty);
  17. return $result;
  18. }
  19. if (php_sapi_name() != "cli") {
  20. die("You have to run this program with php-cli!\n");
  21. }
  22. $canvas = caca_create_canvas(0, 0);
  23. $display = caca_create_display($canvas);
  24. if (!$display) {
  25. die("Error while attaching canvas to display\n");
  26. }
  27. $tbl = array(
  28. array(5, 2),
  29. array(15, 2),
  30. array(20, 4),
  31. array(25, 2),
  32. array(34, 2),
  33. array(37, 4),
  34. array(36, 9),
  35. array(20, 16),
  36. array(3, 9),
  37. array(2, 4),
  38. array(5, 2)
  39. );
  40. for ($i = 0; $i < 10; $i++) {
  41. caca_set_color_ansi($canvas, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
  42. $scale = caca_rand(4, 10) / 10;
  43. $translate = array(caca_rand(-5, 55), caca_rand(-2, 25));
  44. $pts = transform($tbl, $translate[0], $translate[1], $scale, $scale);
  45. caca_draw_thin_polyline($canvas, $pts);
  46. }
  47. caca_put_str($canvas, 1, 1, "Caca forever...");
  48. caca_refresh_display($display);
  49. caca_get_event($display, CACA_EVENT_KEY_PRESS, 5000000);
  50. ?>