ascii_cuboid.pl 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 05 June 2012
  4. # License: GPLv3
  5. # https://github.com/trizen
  6. use 5.010;
  7. # usage: script X Y Z [S]
  8. sub cuboid {
  9. # Constant dimensions of the cuboid
  10. my ($x, $y, $z) = map { int } @_[0 .. 2];
  11. # ASCII characters
  12. # $c = corner point
  13. # $h = horizontal line
  14. # $v = vertical line
  15. # $d = diagonal line
  16. # $s = space (inside the cuboid)
  17. my ($c, $h, $v, $d, $s) = ('+', '-', '|', '/', shift(@ARGV) // q{ });
  18. say q{ } x ($z + 1), $c, $h x $x, $c;
  19. say q{ } x ($z - $_ + 1), $d, $s x $x, $d, $s x ($_ - ($_ > $y ? ($_ - $y) : 1)),
  20. $_ - 1 == $y ? $c : $_ > $y ? $d : $v for 1 .. $z;
  21. say $c, $h x $x, $c, ($s x ($z < $y ? $z : $y), $z < $y ? $v : $z == $y ? $c : $d);
  22. say $v, $s x $x, $v, $z > $y ? $_ >= $z ? ($s x $x, $c) : ($s x ($y - $_), $d)
  23. : $y - $_ > $z ? ($s x $z, $v) : ($s x ($y - $_), $y - $_ == $z ? $c : $d) for 1 .. $y;
  24. say $c, $h x $x, $c;
  25. }
  26. cuboid(shift() // rand(20), shift() // rand(10), shift() // rand(10));