int main(int argc, char **argv) { //declare image short width = 256; short height = 256; TGAImage *img = new TGAImage(width,height); //declare a temporary color variable Colour c; //Loop through image and set all pixels to red for(int x=0; x<width; x++) for(int y=0; y<width; y++) { c.r = 255; c.g = y; //gradient c.b = x; //gradient c.a = 255; img->setPixel(c,x,y); } //draw a diagonal line for(int x=0; x<width; x++) { int y = x; c.r = 0; c.g = 0; c.b = 0; c.a = 255; double x1 = cos(PI/3) - y * sin(PI/3); int x2 = abs(x1); //printf("%f\n", x1); //printf("%d\n", x2); double y1 = cos(PI/3) + x * sin(PI/3); int y2 = abs(y1); img->setPixel(c,(int)x2,(int)y2); // y = -x; // img->setPixel(c,x,y); } //write the image to disk string filename = "./test.tga"; img->WriteImage(filename); return 0; }
void writeTGA(int ***map0, int ***map1, int ***map2, int ***map3, int fileNumber, int I, int J) { TGAImage *tgaimage = new TGAImage(I*2, J*2); Colour human; human.r = 0; human.g = 255; human.b = 0; human.a = 255; Colour empty; empty.r = 0; empty.g = 0; empty.b = 0; empty.a = 255; Colour exposed; exposed.r = 0; exposed.g = 0; exposed.b = 255; exposed.a = 255; Colour zombie; zombie.r = 255; zombie.g = 0; zombie.b = 0; zombie.a = 255; char filename[30]; int num_human, num_exposed, num_zombie; num_human = num_exposed = num_zombie = 0; ofstream out; out.open("stat.csv", ios::app); for (int i = 1; i < I + 1; ++i) { for (int j = 1; j < J + 1; ++j) { if (map0[i][j][TYPE] == HUMAN){ tgaimage->setPixel(human, i-1, j-1); num_human++; } else if (map0[i][j][TYPE] == EXPOSED) { tgaimage->setPixel(exposed, i-1, j-1); num_exposed++; } else if (map0[i][j][TYPE] == ZOMBIE) { tgaimage->setPixel(zombie, i-1, j-1); num_zombie++; } else if (map0[i][j][TYPE] == EMPTY) { tgaimage->setPixel(empty, i-1, j-1); } } for (int j = 1; j < J + 1; ++j) { if (map1[i][j][TYPE] == HUMAN) { tgaimage->setPixel(human, i-1, J+j-1); num_human++; } else if (map1[i][j][TYPE] == EXPOSED) { tgaimage->setPixel(exposed, i-1, J+j-1); num_exposed++; } else if (map1[i][j][TYPE] == ZOMBIE){ tgaimage->setPixel(zombie, i-1, J+j-1); num_zombie++; } else if (map1[i][j][TYPE] == EMPTY) { tgaimage->setPixel(empty, i-1, J+j-1); } } } for (int i = 1; i < I+1; ++i) { for (int j = 1; j < J + 1; ++j) { if (map2[i][j][TYPE] == HUMAN){ tgaimage->setPixel(human, I+i-1, j-1); num_human++; } else if (map2[i][j][TYPE] == EXPOSED) { tgaimage->setPixel(exposed, I+i-1, j-1); num_exposed++; } else if (map2[i][j][TYPE] == ZOMBIE) { tgaimage->setPixel(zombie, I+i-1, j-1); num_zombie++; } else if (map2[i][j][TYPE] == EMPTY) { tgaimage->setPixel(empty, I+i-1, j-1); } } for (int j = 1; j < J + 1; ++j) { if (map3[i][j][TYPE] == HUMAN) { tgaimage->setPixel(human, I+i-1, J+j-1); num_human++; } else if (map3[i][j][TYPE] == EXPOSED){ tgaimage->setPixel(exposed, I+i-1, J+j-1); num_exposed++; } else if (map3[i][j][TYPE] == ZOMBIE) { tgaimage->setPixel(zombie, I+i-1, J+j-1); num_zombie++; } else if (map3[i][j][TYPE] == EMPTY) { tgaimage->setPixel(empty, I+i-1, J+j-1); } } } out << num_exposed<< ",\t" <<num_human << ",\t" << num_zombie <<"\n"; sprintf(filename, "%d%s", fileNumber, ".tga"); tgaimage->WriteImage(filename); out.close(); }