C:/sources/c++/buddhabrot/buddhabrot/fulllinear.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2010 Pierre SCHWARTZ
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
00005 documentation files (the "Software"), to deal in the Software without restriction, including without 
00006 limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
00007 of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 
00008 conditions: The above copyright notice and this permission notice shall be included in all copies or 
00009 substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00010 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
00011 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
00012 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
00013 OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
00014 */
00015 
00023 #include "fulllinear.h"
00024 #include <cmath>
00025 
00026 fullLinear::fullLinear(int nbColors):colorMaker(nbColors){
00027 }
00028 
00029 fullLinear::~fullLinear(){
00030 }
00031 
00032 // level va de 0 à 999
00033 QColor fullLinear::get(int level){
00034         int red, green, blue;
00035 
00036         //float ii = sqrt(sqrt(float(level)/nblevels)) * nblevels;
00037         int ii = level;
00038 
00039         if (level == 50)
00040                 level++;
00041 
00042         // rouge
00043         if (ii < nblevels/4)
00044                 red = 0;
00045         else if (ii < nblevels /2)
00046                 red = -255 + 4*ii*255/nblevels;
00047         else
00048                 red = 255;
00049 
00050         // vert
00051         if (ii< nblevels/2)
00052                 green = 0;
00053         else if (ii < 3*nblevels/4)
00054                 green = -510 + 4*ii*255/nblevels;
00055         else
00056                 green = 255;
00057 
00058         // bleu
00059         if (ii< nblevels/4)
00060                 blue = 4*255*ii/nblevels;
00061         else if (ii < nblevels/2)
00062                 blue = 511 - 4*ii*255/nblevels;
00063         else if (ii < 3*nblevels/4)
00064                 blue = 0;
00065         else 
00066                 blue = -767 + 4*ii*255/nblevels;
00067 
00068         if (blue < 0) blue=0;
00069         if (blue > 255) blue = 255;
00070         if (green < 0) green = 0;
00071         if (green > 255) green = 255;
00072         if (red < 0) red = 0;
00073         if (red > 255) red = 255;
00074 
00075         return QColor(red, green, blue);
00076 }

Generated on Fri Feb 26 21:07:52 2010 for BuddhaBrot by  doxygen 1.4.6-NO