Personal C Sharp         by    famsoft.org

Home | Demonstrative Examples | PC# Methods | PC# Reference | Links
Drawings I
                                                                           You are welcomed to use our site for your web search.
                                                                    See the fine products advertised at the bottom of each page too.

                                 DEMONSTRATIVE EXAMPLES
                                 ======================

                                   EXAMPLES ON DRAWING
                                   ===================

Before we see the examples, we need to explain some drawing basics.

CARTISIAN AND POLAR COORDINATES:

As you already know, when we define location of an object we base it on the location of
object's center relative to form's center instead of basing it on the location of top
left corner of the object relative to top left corner of the form. This makes drawing
simpler and more scientific.

When we have been working with "Controls", (j,k,i,o) used to mean (Horizontal position,
Vertical position, Width and height) respectively. Here we'll use the same symbols except
that we need to increase precision, so we'll use the float var's (jf,kf,lf,of) instead.
Again, (lf) replaces (if) since (if) is a C# keyword.


                         kf                                     jf (Radius)
                         |                                  |   /
                 -ve jf  |  +ve jf                          |  /
                 +ve kf  |  +ve kf                          | /
                         |                                  |/)kf (Angle)
           --------------+------------- jf     -------------+-------------
                         |                                  |
                 -ve jf  |  +ve jf                          |
                 -ve kf  |  -ve kf                          |
                         |                                  |
                      kb = false                         kb = true;
                      (Cartisian)                         (Polar)

For drawings, we can define locations using Cartisian or polar coordinates. Whenever you
like to use polar coordinates to define a location, supply:

jf=Radius, kf=Angle between radius and horizontal axis, kb=true (indicating that you are
using Polar Coordinates)

Angles are positive when rotations are anti-clockwise which is the mathematical standard.
To simplify things further, angles are measured in degrees (0:360)
=========================================================================================

EXAMPLE 1: We need to plot the X,Y axis then:

a) Draw, using Cartisian coordinates a square with sides=100 pixels and center location
on the negative side of the X-axis, 150 pixels away from the center of the form.

b) Then, draw, using Polar coordinates, a circle with diameter=100 and center at the same
location as the square.

Use different colors for each drawing.
=========================================================================================

public class a : pcs {                        // Always remember to make your ".cs" file
                                              // name matchs the class name.
  public override void init() {
    base.init();                              // Always remember, this should be the last
  }                                           // statement in method init()
  public override void run() {
    jf=-250;kf=0;lf=250;of=0;gm("cld");       // Draw line bet. points (-250,0) & (250,0)
    jf=0;kf=150;lf=0;of=-150;gm("cld");       // Draw line bet. points (0,150) & (0,-150)

    os="X";jf=265;kf=0;gm("ctd");             // Draw letter "X" beside X-axis
    os="Y";jf=0;kf=165;gm("ctd");             // Draw letter "Y" above Y-axis

    cls="r0";gm("sps");                       // Set pen color=red,solid pen
    jf=-150;kf=0;lf=of=100;gm("crd");         // Location=(-150,0), width=height=100,
                                              // Create rect & draw.
    cls="b0";gm("sps");                       // Set pen color=blue,solid pen
    jf=150;kf=180;kb=true;lf=of=100;gm("ced");// Radius=150,angle=180,polar coor,
                                              // width=height=100,Create ellipse & draw
  }
}
=========================================================================================
TUTORIAL: Some drawings have been demonstrated when we created graphical menues in
the past section which covered "Controls". The only new items here are the drawing of a
line and the use of polar coordinates.

In general, here are the variables which are required for creating shapes:
 
jf,kf: If Cartisian Coordinates are used (kb=false), they mean Horizontal, vertical
       position of object's center relative to form's center.
       If Polar coordinates are used (kb=true), (jf) is the length of a line which
       connects objects center with form's center and kb is the angle between that line
       and the X-axis.
lf,of: The width and height of the object respectively.

EXCEPTION: If the object was a "line", (jf,kf)=position of line's start point and
           (lf,of)=position of line's end point.

kb:    Used to identify polar coordinates. When we set (kb=true), we mean that (jf,kf)
       we are supplying represent radius and angle instead of horiz, vert positions.

jd,kd: Arches require two more parameters and we use jd,kd for them. jd is the start
       angle and kd is the extent angle.

SHEAR AND ROTATION: There are two additional features which we can get when creating a
shape object. We can get the shape object sheared horizontally and/or vertically. We can
also get it rotated at any angle we choose.

id,od: Horizontal and Vertical Shear Factors.
ad:    Rotation angle.

IMPORTANT REMARK: You already know that all "i,j,k" based variables (GUV's) are always
reset at the completion of any method. This is why when you like your object to be drawn
at the center you can just assign no values to (jf,kf) since you are certain that their
values are zeros to start with.

Now, you see that method gm() is using more var's than just the GUV's. You may be worried
about var's like (od) and (ad) We assure you that method gm() resets them too. Here are
all the var's method gm() resets in addition to the GUV's:

   o=0;of=0;od=0;ob=false;ad=0;

This should be enough for this example. Explanation of how to set pen and brush colors
is left for another example.
=========================================================================================

EXAMPLE 1: We need to plot the X,Y axis then:

a) Draw, using Cartisian coordinates a square with sides=100 pixels and center location
on the negative side of the X-axis, 150 pixels away from the center of the form.

b) Then, draw, using Polar coordinates, a circle with diameter=100 and center at the same
location as the square.

Use different colors for each drawing.
=========================================================================================

public class a : pcs {                        // Always remember to make your ".cs"
                                              // matchs the class name.
  public override void init() {
    base.init();                              // Always remember, this should be the last
  }                                           // statement in method init()
  public override void run() {
    jf=-250;kf=0;lf=250;of=0;gm("cld");       // Draw line bet. points (-250,0) & (250,0)
    jf=0;kf=150;lf=0;of=-150;gm("cld");       // Draw line bet. points (0,150) & (0,-150)

    os="X";jf=265;kf=0;gm("ctd");             // Draw letter "X" beside X-axis
    os="Y";jf=0;kf=165;gm("ctd");             // Draw letter "Y" above Y-axis

    cls="r0";gm("sps");                       // Set pen color=red,solid pen
    jf=-150;kf=0;lf=of=100;gm("crd");         // Location=(-150,0), width=height=100,
                                              // Create rect & draw.
    cls="b0";gm("sps");                       // Set pen color=blue,solid pen
    jf=150;kf=180;kb=true;lf=of=100;gm("ced");// Radius=150,angle=180,polar coor,
                                              // width=height=100,Create ellipse & draw
  }
}
=========================================================================================
TUTORIAL: Some drawings have been demonstrated when we created graphical menues in
the past section which covered "Controls". The only new items here are the drawing of a
line and the use of polar coordinates.

In general, here are the variables which are required for creating shapes:
 
jf,kf: If Cartisian Coordinates are used (kb=false), they mean Horizontal, vertical
       position of object's center relative to form's center.
       If Polar coordinates are used (kb=true), (jf) is the length of a line which
       connects objects center with form's center and kb is the angle between that line
       and the X-axis.
lf,of: The width and height of the object respectively.

EXCEPTION: If the object was a "line", (jf,kf)=position of line's start point and
           (lf,of)=position of line's end point.

kb:    Used to identify polar coordinates. When we set (kb=true), we mean that (jf,kf)
       we are supplying represent radius and angle instead of horiz, vert positions.

jd,kd: Arches require two more parameters and we use jd,kd for them. jd is the start
       angle and kd is the extent angle.

SHEAR AND ROTATION: There are two additional features which we can get when creating a
shape object. We can get the shape object sheared horizontally and/or vertically. We can
also get it rotated at any angle we choose.

id,od: Horizontal and Vertical Shear Factors.
ad:    Rotation angle.

IMPORTANT REMARK: You already know that all "i,j,k" based variables (GUV's) are always
reset at the completion of any method. This is why when you like your object to be drawn
at the center you can just assign no values to (jf,kf) since you are certain that their
values are zeros to start with.

Now, you see that method gm() is using more var's than just the GUV's. You may be worried
about var's like (od) and (ad) We assure you that method gm() resets them too. Here are
all the var's method gm() resets in addition to the GUV's:

   o=0;of=0;od=0;ob=false;ad=0;

This should be enough for this example. Explanation of how to set pen and brush colors
are left for another example.
=========================================================================================

 

demo21.jpg

              Example 1: Drawing simple shapes using Cartisian and Polar coordinates
 You may download the executable file for Example 1 at: http://mysite.verizon.net/vze1l4h6/examples/D1.exe

EXAMPLE 2: If you are wondering why we need polar coordinates, some applications can
be significally simplified with them. Here is a pattern which could be hard to draw using
Cartisian coordinates.
=========================================================================================
public class a : pcs {
  public override void init() {
    base.init();
  }
  public override void run() {
    lf=of=200;gm("ced");                      // Draw a circle, diam=200 pixels
    for (float a=0;a<360;a+=60) {             // make a=angle values between 0,300
      kb=true;jf=100;kf=a;lf=of=200;          // using polar coord draw arches with center
      jd=(double)a+120;kd=120;                // at radius=100, angle=a, start angle=a+120
      gm("cad");                              // Extent angle=120
    }
  }
}
=========================================================================================
TUTORIAL:
What are we drawing on?
What we have is the form surface on which we can install controls. We can also paint its
background with any color or tile it with a background image. We can also draw on it
except that we don't like to do so for a reason which we'll explain shortly.
On top of the form is a transparent bitmap image which we draw on. Since the bitmap
image is transparent, everything the form contains shows through it and combines with the
drawings.
In order to maximize simplicity, all our programs are included into method run(). Whenever
the Form's size is minimized, then restored back to original size, C# redraws for us
all controls and background paint or image on the form, but it does not redraw anything
else which we could have drawn directly on the form. PC# redraws the bitmap image with all
the drawings on its surface, so we get everything to show up again.
A second advantage of using the bitmap image is that it allows us to save our drawings
into a file with ease and reliability. We'll see an example on that shortly.
=========================================================================================

demo22.jpg

            Example 2: Demonestrates how using Polar coordinates simplifies some drawings
You may download the executable file for Example 2 at: http://mysite.verizon.net/vze1l4h6/examples/D2.exe

EXAMPLE 3: Now, we'll see a demonstration of what you can do with "Shear" and "Rotation".
           This is the easiest way to draw a diamond shaped object or a parallelogram.
=========================================================================================
public class a : pcs {
  public override void init() {
    base.init();
  }
  public override void run() {
    lf=260;of=100;id=-1;od=0;gm("crd");        // Draw a rect with horiz shear factor=-1
    cls="b05";gm("sps");                       // Create solid blue pin
    lf=of=60;ad=45;gm("crf");                  // Create, fill a square, rotated 45 degrs
    cls="r0";gm("sps");                        // Change color to red
    lf=of=200;id=0;od=-1;gm("ced");            // Draw a circle with vert shear factor=-1
  }
}
=========================================================================================
TUTORIAL:
Shear Factors (id,od):
To learn the effect of shearing, assume we have a Rectangle and like to convert it into
a Parallelogram by rotating and stretching either its vertical sides or its horizontal
sides by an angle (a)
The table below shows the possible asignments of the shear factors and the resulting Shape
in each case:
        id       od      Transformation result
        ------   ------  ------------------------------------------------
        tan(a)   0       The vertical sides rotate anti-clockwise by (a)
       -tan(a)   0       The vertical sides rotate clockwise by (a)
        0        tan(a)  The horizontal sides rotate clockwise by (a)
        0       -tan(a)  The horizontal sides rotate anti-clockwise by (a)
A combination of shearing, and rotation can make you able to get the necessary
parallelogram for your application.
=========================================================================================

demo23.jpg

               Example 3: Demonstrates using Shear and Rotation can help us drawing some shapes
You may download the executable file for Example 3 at: http://mysite.verizon.net/vze1l4h6/examples/D3.exe

EXAMPLE 4: Now, let us get into business, we need to draw both sides of an ace of diamond
card using gradiant paint to decorate its back side.
=========================================================================================
public class a : pcs {
  public override void init() {
    base.init();
  }
  public override void run() {
    //----------------------------- Card's Front side --------------------------------
    jf=-150;kf=0;lf=224;of=300;gm("crd");   // Draw card outline rectangle
    cls="r0";gm("sps");                     // Set color to pure red, solid pen/brush
    fns="trp24";                            // Set font:TimesRoman, plain size=24
    os="A";jf=-242;kf=130;gm("ctf");        // Draw the text "A" at top left
    os="A";jf=-58;kf=-130;ad=180;gm("ctf"); // Draw same rotated 180 degrees
                                            // at bottom right corner.
    jf=-150;kf=0;lf=of=30;ad=45;gm("crf");  // Fill a 30X30 square at card's center
                                            // rotated 45 degrees.
    jf=-242;kf=110;lf=of=15;ad=45;gm("crf");// Same but smaller at top left corner
    jf=-58;kf=-110;lf=of=15;ad=45;gm("crf");// and at bottom right corner
    //----------------------------- Card's Back side --------------------------------
    cls="S9";gm("sps");                     // set color back to black solid
    jf=+150;kf=0;lf=224;of=300;gm("crd");   // Draw card outline rectangle
    cls="r0";i=5;gm("sps");                 // Set pen color to red, size=5, solid
    jf=150;kf=0;lf=209;of=285;gm("crd");    // Draw a rectangular frame.
    jf=150;kf=0;lf=199;of=275;gm("cr");     // Create inner rectangle without drawing
   
    cls="b0s9";ad=-90;gm("spl");            // Set color to linear gradient changing
                                            // from blue to white at an angle of 90 deg
                                            // covering (gpp)'s bounding area.
    gm("grf");                              // Render (gpp) and fill with color
    JF=new float[]{150,50,250,150};         // Create Gen Path with points defined in
    KF=new float[]{138,-138,-138,138};      // JF[],KF[], Point Count=4. Don't draw it.
    oi=4;gm("cp");
    cls="b0s9";ad=90;gm("spl");             // Create linear gradient color covering the
                                            // new (gpp) object and changing colors at
                                            // opposite direction
    gm("grf");                              // Render (gpp) and fill with color
  }
}
=========================================================================================
TUTORIAL: The only new items in this example are the gradient paint and the GraphicsPath
object. The rest should be easy to understand. Next example will be intirely on the
GraphicsPath. So we are only going to discuss "Gradient Paint".
To set gradient paint, you need to create the object without drawing, then call method
gm() with your wanted color assigned to (cls) at the correct mode for the gradient paint
type you choose. At the end, you fill the object with the paint.
The color code string (cls) should contain two color codes, the start color followed with
the end color.  When the gradient paint is applied, color will be changing gradually from
the start color to the end one over the object's surface.
There are two types of gradient paint:
(1) Linear: You select this type by calling gm("spl"). In addition to supplying the color
code string, you can also supply the angle at which you like the gradient paint to be
applied at in (ad)
(2) Radial: You select this type by calling gm("spr"). The start color will be applied to
the center of the object and will be gradually changing to the end color as it comes
closer to object's outlines.
=========================================================================================

demo24.jpg

Example 4: Rotation, gradient paint and the use of GraphicsPath have helped in drawing the card
You may download the executable file for Example 4 at: http://mysite.verizon.net/vze1l4h6/examples/D4.exe

EXAMPLE 5: Drawing the diamond shape has been easy. How about drawing an "ace of hearts"?
=========================================================================================
public class a : pcs {
  public override void init() {
    base.init();
  }
  public override void run() {
    cls="S9";gm("sps");                    // Set color to black.
    lf=224;of=300;gm("crd");               // Draw card outline rectangle
    cls="r0";gm("sps");                    // Set color to pure red.
    fns="trp24";                           // Set font:TimesRoman,plain, size=24
    os="A";jf=-92;kf=135;gm("ctf");        // Draw the text "A" at top left corner
    os="A";jf=92;kf=-135;ad=180;gm("ctf"); // Draw same rotated 180 deg at bottom right
    createHeart();                         // Run local method to create the heart (gpp)
                                           // It comes large in size, centered into form
    GraphicsPath gpp1=(GraphicsPath)gpp.Clone();            // Make a copy of (gpp)
    GraphicsPath gpp2=(GraphicsPath)gpp.Clone();            // Make a second copy of (gpp)
    //--------------------------- Drawing the center heart ------------------------------
    jd=kd=0.125;kf=9;gm("stu");            // Create a unit Affine Transform to scale
                                           // (gpp) to 1/8th without location change
    gm("gtf");                             // Xfrm then render-fill (gpp)
    //----------------------------- Drawing Corner hearts -------------------------------
    gpp=gpp1;                              // Make (gpp) refer to 1st copy of object
    jd=kd=0.05;jf=-97;kf=123;gm("stu");    // Create Affine Xfrms to scale to 5% and move
    gm("gtf");                             // it to corner then render & fill (gpp)
    gpp=gpp2;                              // Make (gpp) refer to 1st copy of object
    jd=kd=0.05;jf=88;kf=-109;ad=180;gm("stu");
    gm("gtf");                             // Do the same at other corner except that the
  }                                        // Xform also rotates it 180 deg's this time
    //--------------------------- Creating the Heart object -----------------------------
  void createHeart(){                      // This method creates a large size heart
    JF[0]=0;KF[0]=0;OF[0]=0.1f;            // symbol located at Form's center, using
    JF[1]=10;KF[1]=30;OF[1]=0.1f;          // the "GraphicsPath".
    JF[2]=30;KF[2]=60;OF[2]=0.1f;
    JF[3]=60;KF[3]=70;OF[3]=0.1f;          // To get the data, you sketch the heart on
    JF[4]=100;KF[4]=60;OF[4]=0.1f;         // paper first and obtain the x,y coordinates
    JF[5]=130;KF[5]=30;OF[5]=0.1f;         // of points on it's outline.
    JF[6]=150;KF[6]=0;OF[6]=0.1f;
    JF[7]=150;KF[7]=-30;OF[7]=0.1f;        // Get as many points as you can for the curved
    JF[8]=135;KF[8]=-60;OF[8]=0.01f;       // sections and only the start & end points for
    JF[9]=100;KF[9]=-100;OF[9]=0.01f;      // "straight line" sections.
    JF[10]=0;KF[10]=-230;OF[10]=0.01f;
    JF[11]=-100;KF[11]=-100;OF[11]=0.01f;  // JF[], KF[] are the x,y coordinates for the
    JF[12]=-135;KF[12]=-60;OF[12]=0.01f;   // points. OF[] = tension. For a straight lines
    JF[13]=-150;KF[13]=-30;OF[13]=0.1f;    // OF[]=0  At sections where you like the curve
    JF[14]=-150;KF[14]=0;OF[14]=0.1f;      // not to bend too much or in other words to
    JF[15]=-130;KF[15]=30;OF[15]=0.1f;     // be close to a straight line, assign small
    JF[16]=-100;KF[16]=60;OF[16]=0.1f;     // value to the tension.
    JF[17]=-60;KF[17]=70;OF[17]=0.1f;
    JF[18]=-30;KF[18]=60;OF[18]=0.1f;
    JF[19]=-10;KF[19]=30;OF[19]=0.1f;
    JF[20]=0;KF[20]=0;OF[20]=0;            // Make sure to make your start point also your
                                           // end point since it's a closed figure.
    oi=21;gm("cp");                        // total rows=21, create path
  }

=========================================================================================
TUTORIAL: The comments supplied with the code actually explained it all. However, we
need to clear a point here. All shape objects we are using (including text objects) are
GraphicsPath objects. So what was new in this example?
We needed to unify all shape objects in order to simplify working with them. The
GraphicsPath is an objects which you can add any shape object to. So, we have used this
feature to unify them all. Whenever you call method gm() to create any shape, the method
creates a new GraphicsPath, adds the shape you wanted to it and makes (gpp) a reference
to that object. The new object represents your shape since it is the only item it
contains.
In this example, we needed to add some lines and curves to make a closed figure. So, we
used the same GraphicsPath feature to do the job. So all shape objects, simple or complex
are represented by the same object type.
=========================================================================================

demo25.jpg

              Example 5: Shows how to use the GraphicsPath object to create and draw curved shapes
You may download the executable file for Example 5 at: http://mysite.verizon.net/vze1l4h6/examples/D5.exe

EXAMPLE 6: In this example, we are going to see how we can give our drawings 3-D look
using 4 different methods.
=========================================================================================
public class a : pcs {                     // Always remember, class name = file name
  public override void init() {
    base.init();                           // Should be last statement in init()
  }
  public override void run() {
    cls="b7";cm("fcb");                    // Make Foem's background color light blue
    //----------------------------- Radial Gradient Paint ------------------------------
    jf=-300;lf=of=150;gm("ce");            // Create a circle
    cls="s9g0";gm("spr");                  // Create radial gradient brush for the circle
    gm("grf");                             // Render-fill the circle object.
    //----------------------------- Linear Gradient Paint ------------------------------
    jf=-100;lf=of=150;gm("ce");            // Create another circle next to previous one
    cls="s9r0";ad=0;gm("spl");             // Create linear gradient brush for the circle
    gm("grf");                             // Render-fill the circle object.
    //-------------------------- Special Effects - Reflection ---------------------------
    lf=of=150;gm("ce");                    // Create a circle at center
    jf=100;of=5;cls="b0";ks="r";gm("grs"); // Render with sp effects-reflection at locatn
                                           // (100,0), brightness factor=5,blue color
    //----------------------------- Special Effects - Depth -----------------------------
    lf=of=150;gm("ce");                    // Create a circle at center
    cls="s9s0";jf=300;id=20;ad=30;ks="d";gm("grs");
                                           // Render with sp effects-depth at location
                                           // (300,0), Shear angle=30, Depth=20 pixels
    //------------------------------ Displaying the Text --------------------------------
    ss="                        ";         // String of spaces
    fns="trb16";cls="S9";gm("sps");kf=-110;// Font, Color and location = (0,-110)
    os="Gradient Paint"+ss+"Gradient Paint"+ss+"Special Effects"+ss+"Special Effects";
    gm("ctf");                             // Create text object and draw-fill.
    kf=-130;
    os="Radial"+ss+"             Linear"+ss+"           Reflection"+ss+"           Depth";
    gm("ctf");                             // Draw-fill second line.
  }
}
=========================================================================================
TUTORIAL:
(1) To create the gradient paint, we create the shape object first at the location we want
then make the brush which fits the object. When we use the special effects, we create the
object at Form's center then call gm("grs") and supply where we want the object to be.
So, if we want to display more than one copy of the object with special effects at
different locations, we'll still need only one object to create.
(2) The special effects are very useful, so we are going to have two more demonstration
examples on them.
=========================================================================================

demo26.jpg

                                            Example 6: Shows how to add 3D look to your drawings
You may download the executable file for Example 6 at: http://mysite.verizon.net/vze1l4h6/examples/D6.exe

EXAMPLE 7: Here is an example on Special Effects - Depth. It shows how to display text
into large size letters with 3-D look.
=========================================================================================
public class a : pcs {                     // Always remember, class name = file name
  public override void init() {
    base.init();                           // Should be last statement in init()
  }
  public override void run() {
    cm("fwc");float wf=of;                 // Get Form's Client width and height,
    cm("fhc");float hf=of;                 // Store them for future use
    cls="b2";gm("sps");                    // Prepare light blue paint
    lf=wf;of=hf;gm("crf");                 // Fill form's background with it.
    fns="trp260";                          // Set the font to TimesRoman, plain,260
    xs="PC#";                              // The string to be drawn with sp effects.
    float pos=-250;                        // Horiz position of each char to be drawn
    char[] C=xs.ToCharArray();             // Scan the string
    for (int i=0;i<xs.Length;i++) {        // Read the string characters one by one
      os=""+C[i];gm("ct");                 // Get the shape object for each char
      cls="s9s0";jf=pos;kf=0;id=20;        // cls=brightest-darkest colors, location,depth
      ad=30;ks="d";gm("grs");              // ad=Shear angle, ks="d" means select "depth"
      pos+=200;                            // Make each 2 chars 200 pixels apart
    }
  }
}
=========================================================================================

demo27.jpg

                                                        Example 7: Using special Effects - Depth
You may download the executable file for Example 7 at: http://mysite.verizon.net/vze1l4h6/examples/D7.exe

EXAMPLE 8: And here is an example on Special Effects - Reflection. It shows how to draw
a piece of jewelry.
=========================================================================================
public class a : pcs {                     // Always remember, class name = file name
  public override void init() {
    base.init();                           // Should be last statement in init()
  }
  public override void run() {
    lf=of=170;gm("ce");                    // Create the circular gold plate
    cls="o5y5";gm("spl");                  // Prepare linear gradient brush for it
    gm("grf");                             // then render-fill the gold plate.
    lf=6;of=50;gm("c=");                   // Create hexagon shape object at center.
    cls="r0";ks="r";gm("grs");             // Draw the object using sp effects-refl at
    jf=45;cls="b0";ks="r";gm("grs");       // center in red, then repeat 6 times using
    jf=-45;cls="b0";ks="r";gm("grs");      // different colors and different locations
    jf=22;kf=40;cls="g0";ks="r";gm("grs");
    jf=-22;kf=40;cls="m0";ks="r";gm("grs");
    jf=22;kf=-40;cls="m0";ks="r";gm("grs");
    jf=-22;kf=-40;cls="g0";ks="r";gm("grs");
    lf=of=25;gm("ce");                     // Create a circle at center (pearl)
    for (int x=0;x<20;x++) {               // Draw it 20 times using sp effects-reflection
      jf=80;kf=18*x;kb=true;               // at locations around the plate. Polar coord's
      cls="p0";ks="r";gm("grs");           // are used for specifying locations
    }
  }
}
=========================================================================================
TUTORIAL: There is nothing new about this example, however we'll explain here how
graphics related objects are created and used.

The present object:

For simplicity and memory management, PC# works with only one object of each type at a
time. When you call gm("cr") to create a rectangle for example, (gpp), the "present
GraphicsPath object reference" will become a reference of the GraphicsPath object which
contains the rectangle. Any operation you do next will be performed on the rectangle since
it becomes the one and only GraphicsPath object available.

This situation stays on until you create another shape, then the (gpp) becomes a reference
to the new GraphicsPath object and the object which contains the rectangle will have no
reference, so C#'s garbage collection thread will dispose it and free the resources it
occupies.

Now, you may like to say "If I like to operate on the rectangle again, how can I do it?
The answer is that you should create another reference to the rect object before you
create the new object. Here is a code example:

lf=of=100;gm("cr");                        // Create a square
// Do some operations on the square
GraphicsPath square = gpp;                 // Create another reference to the square object
lf=of=150;gm("ce");                        // Now create a circle
// Do some operations on the circle
gpp=square;                                // make (gpp) a reference to the old object
// Do more operations on the square

Objects available for graphics:

At any moment only one of each of the following objects are available:

grp: Present Graphics object. This object represents the surface on which all graphics are
     drawn. At the start it is the "default graphical output device" (bio) which is a
     transparent bitmap object of the same size as the form. Your program can change the
     device (grp) refers to at any moment by calling gm("sdx") where x can be 'b' meaning
     "present bitmap object", 'p' meaning printer or 'd' to return back to the default.
gra: The Form's graphics object. It is the underlayment where all controls are on.
     Anything drawn to this surface will show through the transparent object above it,
     represented by (grp) Each time you draw an object on the default device bitmap (bio),
     the default bitmap object is automatically redrawn to (gra) This auto-display feature
     can be stopped by gm("dn") and you can then redraw the object whenever you want
     with gm("d")
gpp: GraphicsPath object. Before your program creates any of this object type, gpp refers
     to a null object.
bip: Bitmap object. You can either create a fully transparent new bitmap object using
     method gm("bn") or create one from an image file. You can make (bip) your graphical
     output device to draw on it then you can return to the default graphical device and
     draw (bic) on it at any location you like. This method is handy for drawing shadows.
     Before your program creates any of this object type, bip refers to a null object.
bio: A fully transparent Bitmap object which is the default graphical device. See "grp"
     and "gra" for more. You do not create this object.
spp: Solid Pen object. Before your program creates any of this object type, (spp) is
     for for a black pin of width=1 pixel.
sbp: Solid Brush object. Before your program creates any of this object type, (sbp) is
     for a black brush of width=1 pixel.
lgp: Linear gradient paint bush object. Before your program creates any of this object type,
     lgp refers to a null object.
rgp: Radial gradient paint bush object. Before your program creates any of this object type,
     rgp refers to a null object.
tbp: Texture paint bush object. Before your program creates any of this object type,
     tbp refers to a null object.
utp: Unit's Affine transform. A general transform for shapes and bitmap transformation.
     Before your program creates any of this object type, utp refers to null object.
ptp: Printer's Affine transform. A transform for printing purpose.
     Before your program creates any of this object type, ptp refers to null object.
=========================================================================================

demo28.jpg

                                             Example 8: Using Special Effects - Reflection
You may download the executable file for Example 8 at: http://mysite.verizon.net/vze1l4h6/examples/D8.exe