The generation of binary and grayscale masks used in the fabrication of diffractive optical elements is usually performed using a proprietary piece of software or a computer-aided drafting package. Once the pattern is computed or designed, it must be output to a plotting or imaging system that will produce a reticle plate. This article describes a number of short Mathematica modules that can be used to generate binary and grayscale patterns in a PostScript-compatible format. Approaches to ensure that the patterns are directly related to the function of the element and the design wavelength are discussed. A procedure to preserve the scale of the graphic output when it is transferred to another application is given. Examples of surfaces for a 100 mm effective focal length lens and an Alvarez surface are given.