File: x25d.d

package info (click to toggle)
plplot 5.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,280 kB
  • ctags: 13,512
  • sloc: ansic: 83,001; xml: 27,081; ada: 18,878; cpp: 15,966; tcl: 11,651; python: 7,075; f90: 7,058; ml: 6,974; java: 6,665; perl: 5,029; sh: 2,210; makefile: 199; lisp: 75; sed: 25; fortran: 7
file content (104 lines) | stat: -rw-r--r-- 3,514 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// $Id: x25d.d 12393 2013-06-27 19:49:07Z andrewross $
//
//      Filling and clipping polygons.
//

import plplot;
import std.string;


//--------------------------------------------------------------------------
// main
//
// Test program for filling polygons and proper clipping
//--------------------------------------------------------------------------

int main( char[][] args )
{
    // Parse and process command line arguments
    plparseopts( args, PL_PARSE_FULL );

    // Initialize plplot
    plssub( 3, 3 );
    plinit();

    static PLFLT[2][9] xextreme = [ [-120.0, 120.0],
                                    [-120.0, 120.0],
                                    [-120.0, 120.0],
                                    [ -80.0, 80.0],
                                    [-220.0, -120.0],
                                    [ -20.0, 20.0],
                                    [ -20.0, 20.0],
                                    [ -80.0, 80.0],
                                    [  20.0, 120.0] ];

    static PLFLT[2][9] yextreme = [ [-120.0, 120.0],
                                    [  20.0, 120.0],
                                    [ -20.0, 120.0],
                                    [ -20.0, 120.0],
                                    [-120.0, 120.0],
                                    [-120.0, 120.0],
                                    [ -20.0, 20.0],
                                    [ -80.0, 80.0],
                                    [-120.0, 120.0] ];

    PLFLT[] x0, y0;
    for ( int k = 0; k < 2; k++ )
    {
        for ( int j = 0; j < 4; j++ )
        {
            switch ( j )
            {
            case 0:
                x0.length = 4;
                y0.length = 4;
                // Polygon 1: a diamond
                x0[] = [   0.0, -100.0, 0.0, 100.0 ];
                y0[] = [-100.0, 0.0, 100.0, 0.0 ];
                break;
            case 1:
                // Polygon 1: a diamond - reverse direction
                x0[] = [ 100.0, 0.0, -100.0, 0.0 ];
                y0[] = [   0.0, 100.0, 0.0, -100.0 ];
                break;
            case 2:
                // Polygon 2: a square with punctures
                x0.length = 10;
                y0.length = 10;
                x0[]      = [ -100.0, -100.0, 80.0, -100.0, -100.0, -80.0, 0.0, 80.0, 100.0, 100.0 ];
                y0[]      = [ -100.0, -80.0, 0.0, 80.0, 100.0, 100.0, 80.0, 100.0, 100.0, -100.0 ];
                break;
            case 3:
                // Polygon 2: a square with punctures - reversed direction
                x0[] = [  100.0, 100.0, 80.0, 0.0, -80.0, -100.0, -100.0, 80.0, -100.0, -100.0 ];
                y0[] = [ -100.0, 100.0, 100.0, 80.0, 100.0, 100.0, 80.0, 0.0, -80.0, -100.0 ];
                break;
            default:
                break;
            }

            for ( int i = 0; i < 9; i++ )
            {
                pladv( 0 );
                plvsta();
                plwind( xextreme[i][0], xextreme[i][1], yextreme[i][0], yextreme[i][1] );

                plcol0( 2 );
                plbox( "bc", 1.0, 0, "bcnv", 10.0, 0 );
                plcol0( 1 );
                plpsty( 0 );
                if ( k == 0 )
                    plfill( x0, y0 );
                else
                    plgradient( x0, y0, 45. );
                plcol0( 2 );
                pllsty( 1 );
                plline( x0, y0 );
            }
        }
    }

    // Don't forget to call plend() to finish off!
    plend();
    return 0;
}