/* Generated by Interface Builder */

#import "MandelN.h"
#import <math.h>
#import <stdlib.h>
#import <stdio.h>
#import <appkit/Application.h>
#import <appkit/color.h>
#import <appkit/Form.h>

@implementation MandelN		/* Don 't forget the Nibload below!! (change
				 * name) */

- free
{
    [myInspector free];
 /* Free that pesky inspector. */
    [super free];
    return self;
}

- getController:sender :map
{
    [super getController:sender :map];
    [NXApp loadNibSection:"MandelN.nib" owner:self];
 /* Load the inspector */
    toPower = 4;
    return self;
}

- setPower:sender
{
    toPower = [sender intValueAt:0];
    [sender setIntValue:toPower at:0];
    return self;
}

- gohome:(float *)newX :(float *)newY :(float *)newDX :(float *)newDY :(int *)newDepth
{
    *newX = 0.0;
    *newY = 0.0;
    *newDX = 4;
    *newDY = 4;
    *newDepth = 150;
    return self;
}

- (int)colorindex:(double)Real :(double)Imaginary
{
 /*
  * Overwritten for MandelN set 
  */
    double   realCoord = Real, imaginaryCoord = Imaginary, tempReal, tempImaginary;
    register int i, j;

#ifdef DEBUG
    printf("\nReal %lf Imaginary %lf depth %d\n", Real, Imaginary, Depth);
#endif
    for (i = 0; i < Depth; i++)
    {
	tempReal = Real;
	tempImaginary = Imaginary;
	if (Real * Real + Imaginary * Imaginary > 4)
	{
	    return ((int)(chaosColors) * i / Depth);
	}
	for (j = 1; j < toPower; j++)
	/* must execute toPower - 1 times */
	    mulCoords(&Real, &Imaginary, &tempReal, &tempImaginary);
	Real += realCoord;
	Imaginary += imaginaryCoord;
    }
    return (chaosColors);
}

@end
