Advertisement
A4L

Chapter - 18 - Designing-Building Classes (Colour Class)

A4L
Dec 8th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. /*--== Create a Color class ==--
  7.     On a computer, colors are typically represented with a red, green, blue, and alpha
  8. (transparency) value, usually in the range of 0 to 255. Add these as instance variables.
  9.     A constructor that takes a red, green, blue, and alpha value.
  10.     A constructor that takes just red, green, and blue, while alpha defaults to 255 (opaque).
  11.     Methods to get and set the red, green, blue, and alpha values from a Color instance.
  12.     A method to get the grayscale value for the color, which is the average of the red, green and
  13. blue values.*/
  14. namespace Chapter18DesigningBuildingClasses
  15. {
  16.     class Colour
  17.     {
  18.         public byte red { get; set; } = 0;
  19.         public byte green { get; set; } = 0;
  20.         public byte blue { get; set; } = 0;
  21.         public byte alpha { get; set; } = 255;
  22.  
  23.         public Colour() { }
  24.  
  25.         public Colour(byte r, byte g, byte b)
  26.         {
  27.             this.red = r;
  28.             this.green = g;
  29.             this.blue = b;
  30.         }
  31.         public Colour(byte r, byte g, byte b, byte a)
  32.         {
  33.             this.red = r;
  34.             this.green = g;
  35.             this.blue = b;
  36.             this.alpha = a;
  37.         }
  38.  
  39.         public byte GetGrayScale()
  40.         {
  41.             float caculation = (red + green + blue) / 3;
  42.             return Convert.ToByte(caculation);
  43.         }
  44.         /*
  45.             public byte GetRed()
  46.             {
  47.                 return red;
  48.             }
  49.  
  50.             public byte GetGreen()
  51.             {
  52.                 return green;
  53.             }
  54.  
  55.             public byte GetBlue()
  56.             {
  57.                 return blue;
  58.             }
  59.  
  60.             public byte GetAlpha()
  61.             {
  62.                 return alpha;
  63.             }
  64.  
  65.             public byte SetRed(byte r)
  66.             {
  67.                 this.red = r;
  68.                 return red;
  69.             }
  70.  
  71.             public byte SetGreen(byte g)
  72.             {
  73.                 this.green = g;
  74.                 return green;
  75.             }
  76.  
  77.             public byte SetBlue(byte b)
  78.             { this.blue = b;
  79.                 return blue;
  80.             }
  81.  
  82.             public byte SetAlpha(byte a)
  83.             { this.alpha = a;
  84.                 return alpha;
  85.             }*/
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement