-
Notifications
You must be signed in to change notification settings - Fork 34
/
ascii_cuboid.pl
executable file
·34 lines (26 loc) · 1.01 KB
/
ascii_cuboid.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# Date: 05 June 2012
# License: GPLv3
# https://github.com/trizen
use 5.010;
# usage: script X Y Z [S]
sub cuboid {
# Constant dimensions of the cuboid
my ($x, $y, $z) = map { int } @_[0 .. 2];
# ASCII characters
# $c = corner point
# $h = horizontal line
# $v = vertical line
# $d = diagonal line
# $s = space (inside the cuboid)
my ($c, $h, $v, $d, $s) = ('+', '-', '|', '/', shift(@ARGV) // q{ });
say q{ } x ($z + 1), $c, $h x $x, $c;
say q{ } x ($z - $_ + 1), $d, $s x $x, $d, $s x ($_ - ($_ > $y ? ($_ - $y) : 1)),
$_ - 1 == $y ? $c : $_ > $y ? $d : $v for 1 .. $z;
say $c, $h x $x, $c, ($s x ($z < $y ? $z : $y), $z < $y ? $v : $z == $y ? $c : $d);
say $v, $s x $x, $v, $z > $y ? $_ >= $z ? ($s x $x, $c) : ($s x ($y - $_), $d)
: $y - $_ > $z ? ($s x $z, $v) : ($s x ($y - $_), $y - $_ == $z ? $c : $d) for 1 .. $y;
say $c, $h x $x, $c;
}
cuboid(shift() // rand(20), shift() // rand(10), shift() // rand(10));