AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
drawPolygon (Object obj, Array xpoints, Array ypoints [, int count]) yoix.graphics
drawPolygon (Object obj, Number x0, Number y0, Number x1, Number y1, ...)  
 
Draws a polygon in obj, which must be an Image or a drawable component (i.e., a Swing or AWT component, like a JCanvas, JFrame, or Canvas, that supports a paint function), that connects points whose x and y coordinates are supplied as numbers in the xpoints and ypoints arrays. The number of points in the polygon can be specified by the optional count argument, which must be less than or equal to the number of elements in both xpoints and ypoints. When count is omitted drawPolygon chooses a value that is the minimum of the size of the xpoints and ypoints arrays. The Yoix implementation of drawPolygon also accepts x and y coordinates of the points in the polygon as arguments.

The polygon is always closed by a line segment that connects the first and last points. The polygon is drawn in the foreground color selected by the Graphics object associated with obj.
 
 Example:   The program,
import yoix.*.*;

Star(double xcenter, double ycenter) {
    return(
        new Array {
            xcenter + 0, ycenter + -50,
            xcenter + 29, ycenter + 40,
            xcenter + -47, ycenter + -15,
            xcenter + 47, ycenter + -15,
            xcenter + -29, ycenter + 40,
        }
    );
}

JFrame frame = {
    Array layout = {
        new JCanvas {
            Color background = Color.black;

            Graphics graphics = {
                Color foreground = Color.red;
            };

            paint(clip) {
                drawPolygon(this, unroll(Star(72, 72*2)));
            }
        },
    };
};

frame.visible = TRUE;
sleep(5);
exit(0);
defines a paint function in a canvas that draws a five pointed star in red that is centered 1 inch from the left and 2 inches from the top of the canvas. The x and y coordinates of the star are returned in an array by the function named Star. The polygon is drawn by unrolling those coordinates using the unroll built-in and handing them to drawPolygon.
 
 See Also:   clearRect, copyArea, drawArc, drawImage, drawLine, drawOval, drawPolyline, drawRect, drawRoundRect, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, pointInPolygon, pointInRect, rectContainsRect, rectIntersectionRect, rectIntersectsRect, rectUnionRect, stringBounds, stringWidth

 

Yoix is a registered trademark of AT&T Inc.