1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
*Global Scope*
float zoom= 200.0f;
int translX= -185,
translY= -224;
int rectSizeX= 0,
rectSizeY= 0;
...
*Routine Scope*
int middleX= (cr.right - cr.left) + translX;
int middleY= (cr.bottom - cr.top) + translY;
const double saturation= 0.5;
const double value= 0.7;
const double rotation= 120.0; //adjusts hue
const int maxIterations= 100;
rectSizeX= cr.right - cr.left;
rectSizeY= cr.bottom - cr.top;
for(int vPos= cr.top; vPos < cr.bottom; vPos++)
{
for(int hPos= cr.left; hPos < cr.right; hPos++)
{
COLORREF color= NULL;
double x0= (hPos - middleX) / zoom,y0= (vPos - middleY) / zoom;
double x= x0,y= y0;
double hue= 0,f= 0;
int p,q,t;
int iteration= 0;
while((x*x) + (y*y) <= 4 && iteration < maxIterations)
{
double xTemp= x*x - y*y + x0;
y= 2*x*y + y0;
x= xTemp;
iteration++;
}
if(iteration == maxIterations)
color= RGB(0,0,0);
else
{
hue = iteration * 360.0 / maxIterations + rotation;
while( hue >= 360.0 ) hue -= 360.0;
// Convert HSV to RGB
f = hue / 60 - (int)(hue / 60);
p = (int) (value * (1 - saturation) * 255);
q = (int) (value * (1 - f * saturation) * 255);
t = (int) (value * (1 - (1 - f) * saturation) * 255);
switch( (int)(hue / 60) % 6 )
{
case 0: color = RGB( value, t, p ); break;
case 1: color = RGB( q, value, p ); break;
case 2: color = RGB( p, value, t ); break;
case 3: color = RGB( p, q, value ); break;
case 4: color = RGB( t, p, value ); break;
case 5: color = RGB( value, p, q ); break;
default: break;
}
}
SetPixel(hdc,hPos,vPos,color);
}
}
| |