#include<stdio.h> #include<gd.h> #define BLACK 0 #define RED 1 #define GREEN 2 #define BLUE 3 #define WHITE 4 #define WIDE 12 #define HIGH 12 #define WIDTH 16 int main(){ FILE*out; char outfile[]="/home/jlapham1/public_html/102pix.png"; gdImagePtr img; unsigned int color[5]; img = gdImageCreate(WIDE*WIDTH,HIGH*WIDTH); /* defining actual colors here, (red,green,blue) */ color[BLACK]=gdImageColorAllocate(img,0,0,0); color[RED]=gdImageColorAllocate(img,255,0,0); color[GREEN]=gdImageColorAllocate(img,0,255,0); color[BLUE]=gdImageColorAllocate(img,0,0,255); color[WHITE]=gdImageColorAllocate(img,255,255,255); int a,x,y,i,col,line,pixnum,pixnumleft; int pix[WIDE*HIGH];//the array for the picture int arrayGetTwo =0;//separate variable that essentially indexes the array with the following inner for loop //populating the array with values now for(i=0;i<HIGH;i++){ line = i;//the horizontal line number you are on pixnumleft=WIDE;//the number of pixels left in a line while(pixnumleft>0){ printf("Enter the next color.\nBlack=0,Red=1,Green=2,Blue=3,White=4 : "); scanf("%d",&col); printf("There are %u pixels left in line %u.\nEnter the number of pixels for color %u : ",pixnumleft,line,col); scanf("%d",&pixnum); for(a=0;a<pixnum;a++){ pix[arrayGetTwo]=col; arrayGetTwo ++; } pixnumleft=pixnumleft-pixnum; } } //pulling from the array and drawing the picture now int test;//vari that temp stores the color from the array int arrayGet;//vari for the number in the array int yinc = 0;//var for the width of y int xinc = 0;//var for the width of x int xinctwo;//incremented before the loop and is WIDTH larger than xinc int yinctwo = 0;//incremented befor the loop and is WIDTH larger than yinc for(y=0;y<HIGH;y++){ yinctwo = yinctwo + WIDTH; //debug line //printf("y is %u\n",y); xinctwo = 0; xinc = 0; for(x=0;x<WIDE;x++){ xinctwo = xinctwo + WIDTH; arrayGet = x+(y*WIDE); printf("arrayGet is %u\n",arrayGet); test = pix[arrayGet]; gdImageFilledRectangle(img,xinc,yinc,xinctwo,yinctwo,color[test]); /*debugging lines printf("xinc is %u\n",xinc); printf("xinctwo is %u\n",xinctwo); printf("yinc is %u\n",yinc); printf("yinctwo is %u\n",yinctwo); printf("test is %u\n",test);*/ xinc = xinc + WIDTH; } yinc = yinc + WIDTH; } out=fopen(outfile,"wb"); gdImagePngEx(img,out,-1); fclose(out); gdImageDestroy(img); return(0); }