@@ -76,9 +76,36 @@ - (void)drawMandelbrotSetInComplexRect:(CGRect)cRect
76
76
}
77
77
}
78
78
if (cabs (z) > 1 ) {
79
- imageData[(i * height + j) * bytePerPixel + 0 ] = 255 * (1 - iteration / (double )maxIteration);
80
- imageData[(i * height + j) * bytePerPixel + 1 ] = 255 * (1 - iteration / (double )maxIteration);
81
- imageData[(i * height + j) * bytePerPixel + 2 ] = 255 * (1 - iteration / (double )maxIteration);
79
+ unsigned char R, G, B;
80
+
81
+ // RGB
82
+ // double darkness = 1 - (double)iteration / maxIteration;
83
+ // R = 255 * darkness, G = 255 * darkness, B = 255 * darkness;
84
+
85
+
86
+ // HSV -> RGB
87
+ // double H = iteration / (maxIteration + 1.0) * 100.0 + 200; // 0 <= hue < 360
88
+ double H = iteration / (maxIteration + 1.0 ) * 360 ; // 0 <= hue < 360
89
+ int Hi = floor (H / 60.0 );
90
+ double f = H / 60.0 - Hi;
91
+ double S = 1.0 ;
92
+ double V = (double )iteration / maxIteration; // Value (a.k.a Brightness, Lightness)
93
+ double p = V * (1 - S);
94
+ double q = V * (1 - f * S);
95
+ double t = V * (1 - (1 - f * S));
96
+ switch (Hi) {
97
+ case 0 : R = V * 255 , G = t * 255 , B = p * 255 ; break ;
98
+ case 1 : R = q * 255 , G = V * 255 , B = p * 255 ; break ;
99
+ case 2 : R = p * 255 , G = V * 255 , B = t * 255 ; break ;
100
+ case 3 : R = p * 255 , G = q * 255 , B = V * 255 ; break ;
101
+ case 4 : R = t * 255 , G = p * 255 , B = V * 255 ; break ;
102
+ case 5 : R = V * 255 , G = p * 255 , B = q * 255 ; break ;
103
+ default :R = 0 , G = 0 , B = 0 ; break ;
104
+ }
105
+
106
+ imageData[(i * height + j) * bytePerPixel + 0 ] = R;
107
+ imageData[(i * height + j) * bytePerPixel + 1 ] = G;
108
+ imageData[(i * height + j) * bytePerPixel + 2 ] = B;
82
109
}
83
110
}
84
111
}
0 commit comments