// A program that plots a picture of a function of two variables. // The name 'wallpapr.cc' is from Dewdney's Sceintific American // article on the "Wallpaper Program". You can have a lot of fun // with similar programs producing various patterns and pictures // Version3, started March 7th 2000 by RJB /* Algorithm For each row in turn For each column in turn Ouput a symbol to represent the value of a function at that point Repeat with next column output end of line Repeat with next row */ #include using namespace std; // added December 13th 2007 int F(int x, int y, int z)// The function to be displayed { return (x*x + y*y - z*z) * ( x - y ) * ( x + y) ; // or try the following: //return (x*x + y*y - z*z) ; } int main() { const int N = 20;//height and width of grid in characters const int H = N/2; // Largest(Highest) coordinate value const int L = 1+H-N; // Smallest(Lowest) cordinate value // The range L,L+1,...,0,1,...,H has exactly N integers // and 0 is as close to the middle as it can get. const int z=9; //height of the zero level in the surface int x, y; //coordinates of a point in the x>= L; y-- )//For each row in turn y=H, H-1, H-2, ...,L+1, L {//draw a row of picture elements(pixels) with the same y cordinate cout << "\t"; // output a "tab" character for( x = L; x <= H; x++ )//For each column in turn x=L,L+1, L+2, ... H-1, H {// draw the pixel (x,y) const int Fxyz = F(x,y,z); if( x == 0 and y == 0 ) cout << "0"; else if( Fxyz > 0 ) cout <<"+"; else if( Fxyz == 0 ) cout <<"."; else // Fxyz < 0 cout<<"-"; } cout << endl; //end of the line } //end of the grid return 0; }