#!perl
use strict;
use Video::Kaleidoscope::CLI;
exit Video::Kaleidoscope::CLI::run(@ARGV);
__END__

=head1 NAME

kaleidoscope - colours and a seed made into a looping kaleidoscope video

=head1 SYNOPSIS

    kaleidoscope --seed tulip --out tulip.mp4 ff0044 ffd400 0b3d91

    kaleidoscope [--seed TEXT] [--out FILE] [--size N or WxH] [--width N] [--height N]
                 [--rate N] [--seconds N] [--quality N] [--no-play] [--check] [--about]
                 COLOUR COLOUR ...
    kaleidoscope --seed TEXT --seed TEXT ... [--seconds N,N,...] [--blend N] ...
    kaleidoscope --help
    kaleidoscope --version

=head1 DESCRIPTION

C<kaleidoscope> takes from 2 to 16 colours and a seed and makes a short
video of a kaleidoscope in those colours that loops with no join.

It says in one line what the seed chose. Where it is run in a terminal it
plays the loop there once, as well as the terminal can show it. Then it
writes the video, H.264 in an MP4 file of 1080 pixels a side, 30 frames a
second and 10 seconds, and says the path and its size.

The same colours, the same seed and the same settings give the same file,
byte for byte, every time.

With more than one C<--seed> it makes one video that plays each seed in
turn and blends each into the next, and the last into the first.

While the loop plays, any key ends the playing and the file is then
written. C<q> ends the program with no file, and so does Control-C.

=head1 COLOURS

A colour is three or six hex digits: C<f04> and C<ff0044> are one colour.
A C<#> before them is taken as well, inside quotes, since a shell reads a
bare C<#> as the start of a comment.

    kaleidoscope --seed tulip ff0044 ffd400 0b3d91
    kaleidoscope --seed tulip '#ff0044' '#ffd400' '#0b3d91'

The order the colours are given in is part of the picture.

=head1 OPTIONS

An option takes its value from the next argument or from after an equals
sign, so C<--size 720> and C<--size=720> are the same. Options and colours
may come in any order. Two dashes alone end the options.

=over 4

=item --seed TEXT

The seed. Any text. With no seed one is made from the clock and printed
at the start of the first line, and giving that seed back makes the same
video again.

Given more than once, up to 64 times, it makes a chain: each seed plays in
the order given and blends into the one after it.

=item --out FILE

Where the video is written. C<kaleidoscope.mp4> in the directory the
program is run in, where it is not given. A file that is there already is
replaced once the new one is whole.

=item --size N, --size WxH

How many pixels a side: an even whole number from 16 to 4096. 1080 where
it is not given. Two numbers with an C<x> between are a width and a
height, for a video that is not square: C<--size 1920x1080>.

=item --width N, --height N

How many pixels wide, and how many high. Each is the size where it is not
given, so C<--width 1920> alone is 1920 by 1080.

=item --rate N

How many frames a second, or two numbers with a stroke between for a rate
that is a fraction, as C<30000/1001> is. 30 where it is not given.

=item --seconds N

How long the loop is, from 1 to 3600. 10 where it is not given. With more
than one seed it is how long each plays, or a length for each seed in
turn with commas between, as C<--seconds 8,5,10> is for three seeds.

=item --blend N

With more than one seed, how many whole seconds each takes to blend into
the next. 1 where it is not given, 0 for a cut, and no longer than the
shortest seed plays.

=item --quality N

From 1 to 100. 70 where it is not given. A higher quality is a larger file
and a picture nearer to the frames as they were drawn.

=item --no-play

Writes the video and plays nothing.

=item --check

After the video is written, runs the two checks and prints a line for
each. The first holds, for three frames of the loop, that every pixel is
the colour of its image in every mirror. The second reads the file back
and holds every frame of it to the frame drawn again. The program exits 1
where either fails.

=item --about

Prints the seed and everything it chose, a name and a value a line, and
writes no video. For a chain it prints each seed, then the whole, then
what each seed chose on lines that begin with that seed.

=item --help

Prints how the program is called.

=item --version

Prints the version.

=back

=head1 WHAT IT PRINTS

On standard output, a line of what the seed chose, a line for each check
where C<--check> was given, and a line of the path, the frames and the
bytes:

    seed tulip: two mirrors at 180/10 degrees, 20 copies, 21 shapes, 3 colours, 300 frames of 1080 by 1080
    tulip.mp4: 300 frames, 62427438 bytes

For a chain there is a line for each seed and then one of the whole:

    seed tulip: two mirrors at 180/10 degrees, 20 copies, 21 shapes, 240 frames
    seed amber: a 45-45-90 chamber, its cell 540 by 540 pixels, 18 shapes, 150 frames
    2 seeds, 3 colours, 390 frames of 1080 by 1080, each seed blended into the next over 1 second

Where standard output is not a terminal nothing is played, and what is
printed holds no code for a terminal. Where standard error is a terminal
it shows how many frames are written, on one line that is cleared when
the writing is done.

=head1 EXIT STATUS

=over 4

=item C<0>

The video was written, and the checks that were asked for held. Also
where C<q> ended it, and for C<--about>, C<--help> and C<--version>.

=item C<1>

It was refused: a colour that is none, a size that cannot be, a path that
could not be written, or a check that failed. What was wrong is on
standard error in one line.

=item C<2>

The arguments were wrong: too few colours or too many, an option that is
not known, or a value that is not a number. What was wrong is on standard
error, and after it how the program is called.

=item C<130>

It was stopped with Control-C. No file is left where it was stopped while
playing or writing.

=back

=head1 THE TERMINAL

The loop is played through L<Video::Frames>, which shows a picture where
the terminal takes pictures and blocks of colour or characters where it
does not. Where the terminal cannot show the frames as fast as the video
plays, frames are left out and the loop still takes its own time.
C<VIDEO_FRAMES_TERMINAL> names the way outright, and C<none>
there plays nothing. The terminal is left as it was found.

=head1 SEE ALSO

L<Video::Kaleidoscope>, which does all of this from Perl.

=head1 AUTHOR

LNATION <email@lnation.org>

=head1 LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION <email@lnation.org>.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

=cut
