Alexander De Geeter / Color

Dependents:   coap

Files at this revision

API Documentation at this revision

Comitter:
de_geeter_alexander
Date:
Fri Dec 25 19:32:59 2015 +0000
Commit message:
Color klasse om de kleuren bij te houden

Changed in this revision

color.cpp Show annotated file Show diff for this revision Revisions of this file
color.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/color.cpp	Fri Dec 25 19:32:59 2015 +0000
@@ -0,0 +1,44 @@
+/**
+*Dit is de klasse color
+
+*/
+
+#include "color.h"
+
+Color::Color(int red, int green, int blue){
+    this->red=red;
+    this->green=green;
+    this->blue=blue;
+    }
+    
+Color::Color(float red, float green, float blue){
+    this->red=(int) (red*255);
+    this->green=(int) (green*255);
+    this->blue=(int) (blue*255);
+    }
+    
+    Color::Color(int color){ //0xAABBCC
+        this->red=(color>>16) & 0x0000FF;
+        this->green=(color>>8) & 0x0000FF;
+        this->blue=(color>>0) & 0x0000FF;
+        }
+    
+int Color::floatToColorValue(float value){
+    return (int) (value*MAX_COLOR_VALUE);
+    }
+    
+int Color::getRed(){
+    return red;
+    }
+
+int Color::getGreen(){
+    return green;
+    }
+
+int Color::getBlue(){
+    return blue;
+    }    
+
+int Color::getHex(){
+    return (red <<16) + (green<<8) + (blue<<0);
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/color.h	Fri Dec 25 19:32:59 2015 +0000
@@ -0,0 +1,22 @@
+#ifndef COLOR_H
+#define COLOR_H
+
+class Color{
+    int red, green, blue;
+    int floatToColorValue(float value);
+    static const int MAX_COLOR_VALUE=255;
+    
+    public:
+    enum colors {RED=0xFF0000, GREEN=0x00FF00, BLUE=0x0000FF, CYAN=0x00FF00, MAGENTA=0xFF00FF, YELLOW=0x00FFFF, WHITE=0xFFFFFF};
+    
+    Color(int red, int green, int blue);
+    Color(int color);
+    Color(float red, float green, float blue);
+    int getHex();
+    int getRed();
+    int getGreen();
+    int getBlue();
+    
+    };
+
+#endif
\ No newline at end of file