00001 00008 /* 00009 This file is part of Teapot Colony Wars. 00010 00011 Teapot Colony Wars is free software: you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 Teapot Colony Wars is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with Teapot Colony Wars. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 #include "GenColor.h" 00026 00027 #include "Constants.h" 00028 00029 GenColor* GenColor::_instance = NULL; 00030 unsigned int GenColor::_nb_colors = 0; 00031 float GenColor::_factor = 1.0; 00032 00033 GenColor::GenColor() { 00034 00035 } 00036 00037 GenColor::~GenColor() { 00038 destroy(); 00039 } 00040 00041 GenColor* GenColor::instance() { 00042 if(_instance == NULL) { 00043 _instance = new GenColor(); 00044 } 00045 00046 return _instance; 00047 } 00048 00049 void GenColor::destroy() { 00050 if(_instance != NULL) { 00051 delete _instance; 00052 _instance = NULL; 00053 _nb_colors = 0; 00054 _factor = 1.0; 00055 } 00056 } 00057 00058 GLubyte* GenColor::getNewColor() { 00059 GLubyte *colors; 00060 00061 colors = new GLubyte[3]; 00062 _nb_colors++; 00063 00064 if(_nb_colors % 8 == 0) { 00065 _factor /= 2.0; 00066 } 00067 colors[0] = ((_nb_colors + 1) % 2 == 0 ? 00068 (GLubyte) (_factor * ((float) (COLOR_MAX - COLOR_LIMIT))) : 00069 (GLubyte) COLOR_MIN); 00070 colors[1] = (((int) (_nb_colors / 2) + 1) % 2 == 0 ? 00071 (GLubyte) (_factor * ((float) (COLOR_MAX - COLOR_LIMIT))) : 00072 (GLubyte) COLOR_MIN); 00073 colors[2] = (((int) (_nb_colors / 4) + 1) % 2 == 0 ? 00074 (GLubyte) (_factor * ((float) (COLOR_MAX - COLOR_LIMIT))) : 00075 (GLubyte) COLOR_MIN); 00076 00077 return colors; 00078 }