Pseudo Code for Contour Plot





Given two positive numbers, x and y, it is not always easy to predict which
is larger, x^y or y^x. We see that 2^3 < 3^2, 2^4 = 4^2, and 3^4 > 4^3. This
problem caused me to want a contour map of z = x^y - y^x. In the process of
writing and checking out a program to generate this map, I became more
interested in the beauty of the pattern being generated than in the original
problem.

     The pseudo code for the program is:

     BEGIN
       Draw box around edge of screen
       FOR all y pixels YG in box from top DO BEGIN
         Y:= (MaxYPix - YG) * Scale;
         FOR all x pixels XG in box from left DO BEGIN
           X:= XG * Scale;
           Z:= Y^X - X^Y;
           IF Z <= -10.0 THEN Z:= -Z;      { For large |Z|, use }
           IF Z >=  10.0 THEN Z:= Log(Z);  {   log base 10 scale }
           IF Z <   0    THEN Z:= 0.5 - Z; { Plot < 0 opposite of > 0 }
           ZG:= TRUNC(2.0 * Z) MOD 2;      { Contour line every Z = 1/2 n }
           IF ZG = 1 THEN
             plot a dot at (XG, YG);
         END;
       END;
     END.

Return to Plot
Return to Harry's Home Page


This page accessed times since October 20, 2004.
Page created by: hjsmithh@sbcglobal.net
Changes last made on Saturday, 14-May-05 12:44:46 PDT

1