#!python
""" color-pal  -  Display color palate generated by color-gen

    Copyright (C) 2020  RueiKe

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""
__author__ = 'RueiKe'
__copyright__ = 'Copyright (C) 2020 RueiKe'
__credits__ = []
__license__ = 'GNU General Public License'
__program_name__ = 'color-pal'
__version__ = 'v0.0.1'
__maintainer__ = 'RueiKe'
__status__ = 'Development'
__docformat__ = 'reStructuredText'
# pylint: disable=multiple-statements
# pylint: disable=line-too-long

import argparse
import sys
import math
import matplotlib.pyplot as plt
import colorsugen


def main():
    """
    Main flow for color-pal.
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--about', help='README',
                        action='store_true', default=False)
    parser.add_argument('--num_colors', help='number of colors to generate',
                        type=int, default=150)
    parser.add_argument('--color_space', help='color space for source: rgb, hsv or yiq',
                        type=str, default='hsv')
    parser.add_argument('--normal', help='Normalize Luminosity',
                        action='store_true', default=False)
    parser.add_argument('-d', '--debug', help='Debug output',
                        action='store_true', default=False)
    args = parser.parse_args()

    # About me
    if args.about:
        print(__doc__)
        print('Author: ', __author__)
        print('Copyright: ', __copyright__)
        print('Credits: ', *['\n      {}'.format(item) for item in __credits__])
        print('License: ', __license__)
        print('Version: ', __version__)
        print('Maintainer: ', __maintainer__)
        print('Status: ', __status__)
        sys.exit(0)

    colors = colorsugen.colorsugen.ColorUgen()
    color_list = colors.color_gen_list(args.num_colors, color_space=args.color_space,
                                       normalization=args.normal, debug=args.debug)

    colors.print()

    fig_size = 10
    fig = plt.figure(figsize=(fig_size, fig_size))
    ax = fig.add_subplot(1, 1, 1)
    ax.set_facecolor('#d0dbd5')
    fig.patch.set_facecolor('#eeeeee')
    plt.subplots_adjust(left=0.01, right=0.99, top=0.99, bottom=0.01)

    c_len = len(color_list)
    for i, f_col in enumerate(color_list):
        a_deg = 90.0*float(i)/float(c_len)
        y1 = abs(math.sin(a_deg * math.pi / 180.0))
        x1 = abs(math.cos(a_deg * math.pi / 180.0))
        ref_y = [0.0, y1]
        ref_x = [0.0, x1]
        ax.plot(ref_x, ref_y, label=f_col, color=f_col, linewidth=2)
    plt.show()


if __name__ == '__main__':
    main()
