Lab2_Q1

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; #include <iostream> #include <fstream> using namespace std; int main() { int xRes=256, yRes=256; int color = 255; float **xtable; // pointer to pointer[s] xtable = new float*[yRes]; // NOTE how we do this! for(int i=0;i<yRes;i++) { xtable[i] = new float[xRes]; // each row points to xRes elements ("columns") } for(int i=0;i<yRes;i++){ for(int j=0;j<xRes;j++){ xtable[i][j]=255; // store 255 for pixel data, "for now" } } ofstream pgmFile("myImg.pgm"); // output image file we're creating // header pgmFile << "P2" << endl; pgmFile << xRes << " " << yRes << endl; // how many columns, how many rows pgmFile << 255 << endl; // largest pixel value we'll be outputting (below) // pixel data for(int i=0;i<yRes;i++){ if(i%32 == 0){ if(color == 0){ color = 255; }else{ color = 0; } } for(int j=0;j<xRes;j++){ if(i%32 == 0){ if(color == 0){ color = 255; }else{ color = 0; } } xtable[i][j] = color; pgmFile << xtable[i][j] << " "; }// next column pgmFile << endl; }// next row // all done! pgmFile.close(); return 0; }// main()
Editor Settings
Theme
Key bindings
Full width
Lines