the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include "Color.h"
4
5//Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0).
6//Alpha is defaulted to 1.0. The actual color used in rendering depends on finding the best match given the color space
7//available for a particular output device.
8//Parameters:
9//r - the red component
10//g - the green component
11//b - the blue component
12//Throws:
13//IllegalArgumentException - if r, g or b are outside of the range 0.0 to 1.0, inclusive
14Color::Color( float r, float g, float b)
15{
16 assert( r >= 0.0f && r <= 1.0f );
17 assert( g >= 0.0f && g <= 1.0f );
18 assert( b >= 0.0f && b <= 1.0f );
19
20 //argb
21 colour = ( (0xFF<<24) | ( (int)(r*255)<<16 ) | ( (int)(g*255)<<8 ) | ( (int)(b*255) ) );
22}
23
24Color::Color( int r, int g, int b)
25{
26 colour = ( (0xFF<<24) | ( (r&0xff)<<16 ) | ( (g&0xff)<<8 ) | ( (b&0xff) ) );
27}
28
29
30//Creates a Color object based on the specified values for the HSB color model.
31//The s and b components should be floating-point values between zero and one (numbers in the range 0.0-1.0).
32//The h component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1.
33//This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.
34//
35//Parameters:
36//h - the hue component
37//s - the saturation of the color
38//b - the brightness of the color
39//Returns:
40//a Color object with the specified hue, saturation, and brightness.
41Color Color::getHSBColor(float hue, float saturation, float brightness)
42{
43 int r = 0, g = 0, b = 0;
44 if (saturation == 0)
45 {
46 r = g = b = (int) (brightness * 255.0f + 0.5f);
47 }
48 else
49 {
50 float h = (hue - (float)floor(hue)) * 6.0f;
51 float f = h - (float)floor(h);
52 float p = brightness * (1.0f - saturation);
53 float q = brightness * (1.0f - saturation * f);
54 float t = brightness * (1.0f - (saturation * (1.0f - f)));
55 switch ((int) h)
56 {
57 case 0:
58 r = (int) (brightness * 255.0f + 0.5f);
59 g = (int) (t * 255.0f + 0.5f);
60 b = (int) (p * 255.0f + 0.5f);
61 break;
62 case 1:
63 r = (int) (q * 255.0f + 0.5f);
64 g = (int) (brightness * 255.0f + 0.5f);
65 b = (int) (p * 255.0f + 0.5f);
66 break;
67 case 2:
68 r = (int) (p * 255.0f + 0.5f);
69 g = (int) (brightness * 255.0f + 0.5f);
70 b = (int) (t * 255.0f + 0.5f);
71 break;
72 case 3:
73 r = (int) (p * 255.0f + 0.5f);
74 g = (int) (q * 255.0f + 0.5f);
75 b = (int) (brightness * 255.0f + 0.5f);
76 break;
77 case 4:
78 r = (int) (t * 255.0f + 0.5f);
79 g = (int) (p * 255.0f + 0.5f);
80 b = (int) (brightness * 255.0f + 0.5f);
81 break;
82 case 5:
83 r = (int) (brightness * 255.0f + 0.5f);
84 g = (int) (p * 255.0f + 0.5f);
85 b = (int) (q * 255.0f + 0.5f);
86 break;
87 }
88 }
89
90
91 return Color( r, g, b );
92}
93
94int Color::getRGB()
95{
96 return colour;
97}