Question: in C + + : You will use this code as a basis for your modifications for the addition of the Grid mode and Scale

in C++: You will use this code as a basis for your modifications for the addition of the Grid mode and Scale mode.
Mandelbrot Program Specifications
The structs
You will use the following struct definitions and declaration in your program to create and manipulate your image:
pixel_t
struct pixel_t {
unsigned short red;
unsigned short green;
unsigned short blue;
};
Members:
Pixel RGB color triplet
image_t
struct image_t {
static const unsigned short MAX_PIX_GRAD =160;
static const unsigned short MAX_DIMENSION =1024;
unsigned short width;
unsigned short height;
gradient_t map[MAX_PIX_GRAD];
pixel_t data[MAX_DIMENSION][MAX_DIMENSION];
};
Members:
MAX_PIX_GRAD: maximum size of array that holds the RGB colors from the file color_gradient.txt. There are 160 colors in the file.
MAX_DIMENSION: Sets the maximum size of an image to display.
width and height: Dimensions of the image entered by the user in the command line.
MAP[]: Array of type gradient_t that stores the values of the gradient color palette read in from the file color_gradient.txt.
data[][]: Array of type pixel_t that holds the pixel color map for the image.
gradient_t
struct gradient_t {
unsigned short red_grad;
unsigned short green_grad;
unsigned short blue_grad;
};
Members:
RGB color triplet for the gradient color palette.
scale_t
struct scale_t {
double xmin;
double xmax;
double ymin;
double ymax;
};
Members:
x and y coordinates for the grid pattern.
Declaring a struct data type.
The statement below declares the new struct identifier image of type image_t
image_t image; // Image file struct declaration.
Included Functions:
Function 1- generate_mandelbrot()
This function is responsible for populating the image pixel array. It sets up and calls the mandelbrot() function and is returned the number of iterations for the point in the complex plane being calculated. This is also a pixel location in the image. It calls the get_color() function to assign an RGB triplet for that pixel and that is based on the number of colors entered in the command line. The maximum number of colors is 160. This color triplet is then stored in the image map. This continues for every pixel location in the image. There is a fair amount of explanation in the code comments, so make sure you read them.
void generate_mandelbrot(image_t& image, const bool GRID_SELECT)
Function 2- mandelbrot()
This function is called and receives the complex number c from generate_mandelbrot() and returns the number of iterations for that point.
unsigned short mandelbrot(const complex& c);
Function 3- get_color
This function is called by generate_mandelbrot() and is passed the number of iterations for a point and calculates and sets the RGB colors for that pixel based on the number of iterations and the number of colors selected, from the available palette(file), for that image.
void get_color(unsigned short iterations, unsigned short& red, unsigned short& green,
unsigned short& blue, image_t& image)
Function 4- read_gradient_file()
Stores the RGB triples for the color gradient file. This is currently 160 RGB colors.
void read_gradient_file(image_t& image);
Function 5- get_xy()
Deterimines the real and imaginary axis (x and y) range. This is where the scaling logic resides. Your objective is to add this logic to the program. The scaling is set to the default in the sample (full Mandelbrot image) program.
void get_xy(scale_t& scale, const bool SCALE_SEL)
Default parameters in the sample run:
The sample program sets the coordinate size for the Mandelbrot calculations as constants. You will need to change these to variables when you add the scaling feature. There is a table of scaling values provided in the file scale.txt. You will use this for the scaling feature.
Sample program values:
xmin =-2.0
xmax =1.0
ymin =-1.5
ymax =1.5
The max iterations of the Mandelbrot function is set to 160 to match the maximum number of colors in the color gradient file. You can add more if you want later.
Inputs:
Command Line Arguments are used.
Included in the sample program.
argc - An integer that represents the number of arguments to be passed.
argv[]- An array of string arguments. (Actually, an array of pointers that point to the character arrays that hold the strings redirected from the command line).
Color gradient palette file.
Included in the sample program.
Contains 160 colors that are used to represent the value of iterations within the Mandelbrot image. The first number is used as an index to read the set into an array of type gradient_t
Copy this from:
/home/shared/cs135/jpristas/pa09b/color_gradient.txt
160
486127
7810204
1036204
10110204
101492
 in C++: You will use this code as a basis for

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!