[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

RANDEXT Implementation

The RANDEXT performs that same housekeeping tasks (determining size, saving data segment, clearing playground) that all other extensions do.

The first two subfunctions in RANDEXT make extensive use of the C standard library rand() function to get random numbers (the random number generator is seeded with the current time when Cogsys starts up). Like the trigonmetric functions detailed in the CIRCEXT implementation (see section CIRCEXT Implementation), the rand() function needs access to the original data segment. The following macro makes it easy to get a random number `r' at any time in the code:

 
#define getrandom() asm mov ds, oldseg; r= rand(); asm mov ds, myseg

To draw the 64x64 square, a simple for loop is used. For each pixel, a random number is selectd; if the selcted number is below the cutoff (RAND_MAX*fillratio), the pixel is white, else black.

 
q = (int) ( (float) RAND_MAX * fillratio);
for (j=0; j<64; j++)
  {
    for (i=0; i<64; i++)
      {
        getrandom();
        A[(j+68)*320 + 128 + i] = WHITE * (r < q);
      }
  }

Subfunction 2 differs only the way it handles the distribution. Subfunction 2 exploits the fact that the argument buffer is not cleared betwen subsequent extension calls from a single %I run, and uses the argument buffer to store an array of fillratios that is calculated on the first run. (see section Passed Arguments) Remember that each call of the extension is told how many pictures were requested total, and which one is currently being drawn. When subfunction 2 notices that the first picture is being drawn, it sets up the fillratio distribution.

The actual details of the distribution creation are involved but not unrelated to extension and picture drawing. The algorithm is commented in the extension source file, `randext.c'.

Subfunctions 3, 4, and 5 use a similar loop for drawing pixels of specified colors in the picture.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Usman Muzaffar on June, 28 2000 using texi2html