using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace individual
{
    internal class Triangle
    {
        /******************************GLOBAL CONSTANTS************************************/
        //NAME: POINTS_SIZE
        //TYPE: Integer
        //PURPOSE: 'POINTS_SIZE' is the size of the 'points' array
        private const int POINTS_SIZE = 3;
        //NAME: MIN_RGB
        //TYPE: Integer
        //PURPOSE: 'MIN_RGB' is the minimum value possible for an RGB value
        private const int MIN_RGB = 0;
        //NAME: MAX_RGB
        //TYPE: Integer
        //PURPOSE: 'MAX_RGB' is the maximum value possible for an RGB value
        private const int MAX_RGB = 255;
        //NAME: MIN_A
        //TYPE: Integer
        //PURPOSE: 'MIN_A' is the minimum value possible for a color's alpha
        private const int MIN_A = 50;
        //NAME: MAX_A
        //TYPE: Integer
        //PURPOSE: 'MAX_A' is the maximum value possible for a color's alpha
        private const int MAX_A = 130;
        /********************************DATA MEMBERS**************************************/
        //NAME: points
        //TYPE: Point, array; LENGTH: 3
        //PURPOSE: 'point' stores three points to draw a triangle
        private Point[] points;
        //NAME: color
        //TYPE: Color
        //PURPOSE: 'color' stores an ARGB value for a triangle
        private Color color;
        /**********************************PROPERTIES**************************************/
        //PROPERTY: Points, get
        //PURPOSE: Accessor function, returns the array of points of a triangle
        public Point[] Points
        {
            get { return points; }
        }
        //PROPERTY: Color, set; Color, get
        //PURPOSE: Mutator function, sets the color object of a triangle
        //         Accessor function, returns the color object of a triangle
        public Color Color
        {
            set { color = value; }
            get { return color; }
        }
        /**********************************FUNCTIONS***************************************/
        //FUNCTION: Triangle, constructor
        //PARAMETERS: Width and Height of the Bitmap image
        //PURPOSE: The following function is the Triangle constructor. It allocates memory for its data members and calls functions to
        //         generate points and generate the color for an individual triangle
        public Triangle(int width, int height)
        {
            Console.WriteLine("in Triangle Constructor");
            points = new Point[POINTS_SIZE];
            color = new Color();

            Console.WriteLine("before GeneratePoints");
            this.GeneratePoints(width, height);
            Console.WriteLine(points);
            Console.WriteLine("after GeneratePoints");
            Console.WriteLine("before GenerateColor");
            this.GenerateColor();
            Console.WriteLine("after GenerateColor");
        }
        //FUNCTION: GeneratePoints 
        //PARAMETERS: Width and Height of the Bitmap Image
        //PURPOSE: The function 'GeneratePoints' will fill the contents of a triangle's Point array with randomly generated value within a specified range
        public void GeneratePoints(int width, int height)
        {
            int point_X, point_Y;
            Point temp_point;
            int temp_X, temp_Y;
            //first point
            point_X = RndNumGen.Next(0, width);
            point_Y = RndNumGen.Next(0, height);
            temp_point = new Point(point_X, point_Y);
            points[0] = temp_point;

            for (int i = 1; i < POINTS_SIZE; i++)
            {
                int min_X = (int)((-1) * (width / 2));
                int max_X = (int)((width / 2));
                int x = RndNumGen.Next(min_X, max_X);
                temp_X = point_X + x;
                if (temp_X < 0) { temp_X = 0; }
                else if (temp_X >= width) { temp_X = width - 1; }

                int min_Y = (int)((-1) * (height / 2));
                int max_Y = (int)((height / 2));
                int y = RndNumGen.Next(min_Y, max_Y);
                temp_Y = point_Y + y;
                if (temp_Y < 0) { temp_Y = 0; }
                else if (temp_Y >= height) { temp_Y = height - 1; }

                temp_point = new Point(temp_X, temp_Y);
                points[i] = temp_point;
            }
        }
        //FUNCTION: GenerateColor
        //PURPOSE: The function GenerateColor will randomly generate values within the specified range [0-255] to represent ALPHA, RED, GREEN, BLUE (color) values
        public void GenerateColor()
        {
            int alpha, red, green, blue;

            alpha = RndNumGen.Next(MIN_A, MAX_A);
            red = RndNumGen.Next(MIN_RGB, MAX_RGB);
            green = RndNumGen.Next(MIN_RGB, MAX_RGB);
            blue = RndNumGen.Next(MIN_RGB, MAX_RGB);
            this.Color = Color.FromArgb(alpha, red, green, blue);
        }
    }
}
