#pragma windows // this command is needed to create a window #include #include #include <\DBOS\graphics.h> // These libraries must be included #include // to use graphics functions void Plot_2D_Array(int *); // Function to plot grey-scale graph int main(void) { FILE *fp; int data[128][128]; // Data held as 128 x 128 array of ints int *pointer; // declare pointer to variable of type int int time,wavelength,ctrl; fp=fopen("light.dat","r"); for (time=0;time<128;time++) // load data into 2D array { for (wavelength=0;wavelength<128;wavelength++) fscanf(fp,"%d",&data[time][wavelength]); } fclose(fp); // The following line uses the Salford compiler's // ClearWin+ winio() function to open a window that // is then used to display graphics. // The winio() function may be supplied with a very large // number of parameters that control the layout, appearance // and function of the window. We will only need to use a few of // those parameters for the programs in the Computing II module. // // The parameters needed to open a simple graphics window are: // %gr - this provides a rectangular area for graphics // In this case 128 x 128 pixels // [black] paints the area black // %lw a parameter that is needed to enable the window // to be closed; when the window is closed "ctrl" is // set to zero winio("%gr[black]%lw",128,128,&ctrl); pointer=&data[0][0]; // the variable "pointer" points to the data array Plot_2D_Array(pointer); // pass the data array to the Plot_2D_Array function } void Plot_2D_Array(int *array) { short i,rows,cols; // The following loop sets up the colour palette // It is possible to create any colour by mixing // red, green and blue. Using the set_video_dac() function // we can mix red, green and blue as we please to create // a range of colours. // The format is: set_video_dac(index, red, green, blue) // where index, red, green and blue all have values between 0 and 255 // So to assign colour no. 255 as white we use: // set_video_dac(255,255,255,255); // The following loop sets up a grey scale with black having // colour index 0 and white having colour index 255 for (i=0;i<256;i++) set_video_dac(i,i,i,i); // The following loop colours the pixels on the screen using // the set_pixel() function. // set_pixel() has the following arguments: // set_pixel(x co-ordinate, y co-ordinate, colour) // Each pixel is given a shade of grey dependent // on the value in "array" for (rows=0;rows<128;rows++) { for (cols=0;cols<128;cols++) set_pixel(cols,rows, *(array+cols+(128*rows))); } return; }