﻿ The Mandelbrot Set The Mandelbrot Set  Site Map Feedback       Fern Mandelbrot Parity SeedHead  To draw the Mandelbrot Set on the PixelBlock, mix in the CMandelbrotStencil class below and define the SetPixel abstract method to use CPixelBlock::SetPixel:
The following Stencil draws the Mandelbrot Set, a distinctive shape created by mathematicians for their own amusement:
```class CMandelbrotStencil {
virtual void SetPixel(WORD x, WORD y, DWORD Colour) =0;
public:
// l=Lower, u=Upper bounds of set to draw. d=Scale (Smaller number=Bigger Picture).
void Mandelbrot(double lx=-2, double ux=0.6, double ly=-1.2, double uy=1.2, double d=0.02) {
int px=0;
for(double x=lx; x<ux; x+=d) {
int py=0;
for(double y=ly; y<uy; y+=d) {
int iMax=50;
double X=x;
double Y=y;
for(int i=0; i<iMax; ++i) {
double x1=X*X-Y*Y+x;
double y1=2*X*Y+y;
if(x1*x1+y1*y1>=4) break;
X=x1;
Y=y1;
}
int c=iMax-i;
SetPixel(px, py++, ((((c*5)<<8)|(c<<4))<<8)|(c*12));
}
++px;
} }
};
```
You can mix in as many 'Stencils' as you like to provide all the primitives you need.

The Colours, Drawing and Effects sections have further extensions. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 