Programmer's Reference

Creating stipples using bitmaps

To carry the example further, the bitmap in the previous example could be used to create a stipple drawing pattern. The pattern (a brick pattern) is created as a bitmap. This bitmap is set as the stipple pattern in a graphics context using the setStipple: method. The fill style, FillOpaqueStippled, and the stipple origin offsets (x: 1 y: 2) are also set by sending the appropriate messages to the graphics context. The graphics context is then used to draw a filled rectangle.

| bits bitmap |
bits := #[
    2r11111111 2r00000001 2r00000001 2r00000001
    2r11111111 2r00010000 2r00010000 2r00010000].
bitmap := CgWindow default
    createBitmapFromData: bits
    width: 8
    height: 8.
 
CgGC default
    setFillStyle: FillOpaqueStippled;
    setTSOrigin: 1 tsYOrigin: 2;
    setStipple: bitmap;
    setForeground: CgWindow default blackPixel;
    setBackground: CgWindow default whitePixel.
 
CgWindow default
    fillRectangle: CgGC default
    x: 50
    y: 50
    width: 100
    height: 100.
CgGC default setFillStyle: FillSolid.
bitmap freePixmap.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]