Assignment #5 Library Extensions

There are several optional features of the libraries for assignment 5. These are entirely optional, but are there for those who want to experiment with them.

Pool

The draw_img_adv function

The function draw_img_adv can be used instead of draw_img. The draw_img_adv function accepts more arguments which can be used to customize the appearance of the frames. It has the following prototype:

void draw_img_adv( ball balls[NBALLS] , int generation,
                   colour colours[NBALLS] , double pocket_rad,
                   char* path);

The first two arguments match those in draw_img. The others can be used as follows:

colours
This array can be used to indicate the colour that each ball should be drawn in. Each element in the array is a colour structure. The structure is defined as follows:
typedef struct {byte r,g,b;} colour;

[A byte is an unsigned integer type.] The components, r, g and b indicate the values of each of red green and blue in the colour. You can look at a colour chart to get some colour values. The numbers on the colour chart indicate the RGB values in that order.

If you specify an array here, ball i will be drawn in colour colours[i]. If you don't want to change the colours, specify NULL here.

pocket_rad
If you'd like pockets drawn on the table, you can specify their radius here. The value is up to you, but I've used BALLDIAM/4*3 for this and it looks about right.

If you don't want any pockets drawn, just indicate 0 here.

path
If you give an argument here, the image files will be written to that directory. If you find you're filling up your disk quota, you can have the images go into a temporary directory that doesn't count towards your quota.

For example, you might first make a directory with the Unix command mkdir /tmp/userid and then specify "/tmp/userid" for the path argument.

If you don't want to change the path, use "" for this argument.

By specifying the default values for any of these arguments, you will get the default behaviour. In fact, the draw_img function is defined like this:

void draw_img( ball balls[NBALLS] , int generation ) {
  draw_img_adv(balls, generation, NULL, 0, "");
}

Compiler constants

You can also change the resulting image by setting any of these compiler constants. If you don't set them, they will stay at their default values.

IMGWIDTH, IMGHEIGHT
The width and height of the image, in pixels. The default values are 200 and 100.
FELT_R, FELT_G, FELT_B
These values specify the colour of the table's felt. Colours are specified using RGB values as in the colour chart. The default is a medium green.
BANK_R, BANK_G, BANK_B
These values specify the colour of the table's banks. Colours are specified using RGB values as in the colour chart. The default is a dark green.
POCKET_R, POCKET_G, POCKET_B
These values specify the colour of the pockets. Colours are specified using RGB values as in the colour chart. The default is black.

Pop

The draw_img_adv function

The function draw_img_adv can be used instead of draw_img. The draw_img_adv function accepts more arguments which can be used to customize the way the images are drawn. It has the following prototype:

void draw_img_adv(region pop[WIDTH][HEIGHT], int generation, char* path);

The first two arguments match those in draw_img. The last one us used as follows:

path
If you give an argument here, the image files will be written to that directory. If you find you're filling up your disk quota, you can have the images go into a temporary directory that doesn't count towards your quota.

For example, you might first make a directory with the Unix command mkdir /tmp/userid and then specify "/tmp/userid" for the path argument.

If you don't want to change the path, use "" for this argument.

Actually, the draw_img function is defined like this:

void draw_img(region pop[WIDTH][HEIGHT], int generation) {
  draw_img_adv( pop, generation, "");
}

Compiler constants

You can also change the resulting image by setting any of these compiler constants. If you don't set them, they will stay at their default values.

CELLHEIGHT, CELLWIDTH
The height and width of each cell, in pixels, including the border.
COLOURFACTOR
This is the maximum number of dots drawn in each square for each species, it is 30 by default. If the population density for one of the species is 1, this many dots will be placed in the region.
BG_R, BG_G, BG_B
These values specify the colour of the background. Colours are specified using RGB values as in the colour chart. The default is black.
PREY_R, PREY_G, PREY_B
These values specify the colour of the prey dots. Colours are specified using RGB values as in the colour chart. The default is green.
PRED_R, PRED_G, PRED_B
These values specify the colour of the predator dots. Colours are specified using RGB values as in the colour chart. The default is purple.
GRID_R, GRID_G, GRID_B
These values specify the colour of the grid lines. Colours are specified using RGB values as in the colour chart. The default is white.

If you're going to set any of the CELLHEIGHT, CELLWIDTH or COLOURFACTOR constants, you should make sure the dots you've specified will fit in the region. This relationship should always be true:

COLOURFACTOR < (CELLHEIGHT-1)*(CELLWIDTH-1)/2

Copyright © Greg Baker, last modified 2003-06-26.