DMM Varkon® Tutorial
A Beginner's Guide to the Varkon Parametric Modeling and CAD Application Development System
By David M. MacMillan


12.4. Square 2D Grid

The following MBS drawing module plots a square two-dimensional grid. The lines of the grid are drawn by pens of width 0 (i.e., as thin as possible). A diagonal line is provided to emphasize the squareness of the grid. The grid's lines are numbered by their X and Y coordinates.

The calling syntax is:

grid2d (delta, n);

! grid2d.MBS   
! 
! Draw a square 2-d grid
!

global drawing module grid2d(
   float delta;   ! distance between lines
   int   n        ! number of lines, including both sides
   );

   float  hx1, hy1;  ! horizontal lines
   float  hx2, hy2;  !
   vector hstart, hstop;
   float  vx1, vy1;  ! vertical lines
   float  vx2, vy2;  !
   vector vstart, vstop;
   int    ix;
   vector xtextpos, ytextpos;

beginmodule

  hx1 := 0;
  hy1 := 0;
  hx2 := hx1 + (delta * (n - 1));
  hy2 := 0;

  vx1 := 0;
  vy1 := 0;
  vx2 := 0;
  vy2 := vy1 + (delta * (n - 1));
  

  for ix := 0 to (n -1) do

     hstart := vec (hx1, hy1);
     hstop  := vec (hx2, hy2);
     lin_free (#1, hstart, hstop: width=0);

     vstart := vec (vx1, vy1);
     vstop  := vec (vx2, vy2);
     lin_free (#2, vstart, vstop: width=0);

     xtextpos := vec (vx1 - 1, -2);
     text (#3, xtextpos, 0, str((ix * delta), 2, 1): tsize=1);

     ytextpos := vec (-5, hy1);
     text (#4, ytextpos, 0, str((ix * delta), 2, 1): tsize=1);

     hy1 := hy1 + delta;
     hy2 := hy2 + delta;

     vx1 := vx1 + delta;
     vx2 := vx2 + delta;

  endfor;

  hstart := vec (0, 0);
  hstop  := vec (vx2 - delta, hy2 - delta);
  lin_free (#5, hstart, hstop: width=0);

endmodule

To invoke this module to display a grid of delta 10 from 0 through 100 (11 lines horizontal, 11 vertical) use, for instance, an active module containing:

GLOBAL DRAWING MODULE test2d();
BEGINMODULE
  part(#1,grid2d(10, 11));
ENDMODULE

grid2d


Legal Matters

With the exception of any material noted as being in the public domain, the text, images, and encoding of this document are copyright © 1998 by David M. MacMillan.

The author has no relationship with Microform AB, and this Tutorial is neither a product of nor endorsed by Microform AB.

"Varkon" is a registered trademark of Microform AB, Sweden.

This document is licensed for private, noncommercial, nonprofit viewing by individuals on the World Wide Web. Any other use or copying, including but not limited to republication in printed or electronic media, modification or the creation of derivative works, and any use for profit, is prohibited.

This writing is distributed in the hope that it will be useful, but "as-is," without any warranty of any kind, expressed or implied; without even the implied warranty of merchantability or fitness for a particular purpose.

In no event will the author(s) or editor(s) of this document be liable to you or to any other party for damages, including any general, special, incidental or consequential damages arising out of your use of or inability to use this document or the information contained in it, even if you have been advised of the possibility of such damages.

In no event will the author(s) or editor(s) of this document be liable to you or to any other party for any injury, death, disfigurement, or other personal damage arising out of your use of or inability to use this document or the information contained in it, even if you have been advised of the possibility of such injury, death, disfigurement, or other personal damage.

All trademarks or registered trademarks used in this document are the properties of their respective owners and (with the possible exception of any marks owned by the author(s) or editor(s) of this document) are used here for purposes of identification only. A trademark catalog page lists the marks known to be used on these web pages. Please e-mail dmm@lemur.com if you believe that the recognition of a trademark has been overlooked.


Version 1.4, 1998/06/17. Feedback to dmm@lemur.com
http://www.database.com/~lemur/vk-grid2d.html


Go to the: