File: xthick27a.adb.cmake

package info (click to toggle)
plplot 5.9.5-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 32,964 kB
  • ctags: 11,898
  • sloc: ansic: 71,866; xml: 25,294; cpp: 13,070; tcl: 10,310; f90: 5,963; perl: 5,661; python: 5,068; java: 4,944; ml: 4,057; sh: 1,754; php: 267; makefile: 198; lisp: 75; fortran: 64; sed: 5
file content (148 lines) | stat: -rw-r--r-- 4,823 bytes parent folder | download
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
-- $Id: xthick27a.adb.cmake 9378 2009-01-23 09:13:27Z jbauck $

-- Drawing "spirograph" curves - epitrochoids, cycolids, roulettes

-- Copyright (C) 2008 Jerry Bauck

-- This file is part of PLplot.

-- PLplot is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Library Public License as published
-- by the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.

-- PLplot is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU Library General Public License for more details.

-- You should have received a copy of the GNU Library General Public License
-- along with PLplot; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

with
    Ada.Numerics.Long_Elementary_Functions,
    PLplot_Auxiliary,
    PLplot;
use
    Ada.Numerics.Long_Elementary_Functions,
    PLplot_Auxiliary,
    PLplot;

@Ada_Is_2007_With_and_Use_Numerics@

------------------------------------------------------------------------------
-- Generates two kinds of plots:
--   - construction of a cycloid (animated)
--   - series of epitrochoids and hypotrochoids
------------------------------------------------------------------------------

procedure xthick27a is
    -- R, r, p, N
    params : Real_Matrix(0 .. 8, 0 .. 3) := 
      ((21.0,  7.0,  7.0,  3.0),
       (21.0,  7.0, 10.0,  3.0),
       (21.0, -7.0, 10.0,  3.0),
       (20.0,  3.0,  7.0, 20.0),
       (20.0,  3.0, 10.0, 20.0),
       (20.0, -3.0, 10.0, 20.0),
       (20.0, 13.0,  7.0, 20.0),
       (20.0, 13.0, 20.0, 20.0),
       (20.0,-13.0, 20.0, 20.0));

    procedure spiro(params : Real_Matrix; row : Integer) is
        NPNT : constant Integer := 20000;
        xcoord, ycoord : Real_Vector(0 .. 20000);
        windings : Integer;
        steps    : Integer;
        phi      : Long_Float;
        phiw     : Long_Float;
        dphi     : Long_Float;
        xmin     : Long_Float;
        xmax     : Long_Float;
        ymin     : Long_Float;
        ymax     : Long_Float;
        scale    : Long_Float;
    begin
        -- Fill the coordinates
        windings := Integer(params(row, 3));
        steps    := NPNT / windings;
        dphi     := 8.0 * arccos(-1.0) / Long_Float(steps);

        xmin := 0.0; -- This initialisation is safe!
        xmax := 0.0;
        ymin := 0.0;
        ymax := 0.0;

        for i in 0 .. windings * steps loop
            phi       := Long_Float(i) * dphi;
            phiw      := (params(row, 0) - params(row, 1)) / params(row, 1) * phi;
            xcoord(i) := (params(row, 0) - params(row, 1)) * cos(phi) + params(row, 2) * cos(phiw);
            ycoord(i) := (params(row, 0) - params(row, 1)) * sin(phi) - params(row, 2) * sin(phiw);

            if xmin > xcoord(i) then xmin := xcoord(i); end if;
            if xmax < xcoord(i) then xmax := xcoord(i); end if;
            if ymin > ycoord(i) then ymin := ycoord(i); end if;
            if ymax < ycoord(i) then ymax := ycoord(i); end if;
        end loop;

        if xmax - xmin > ymax - ymin then
            scale := xmax - xmin;
        else
            scale := ymax - ymin;
        end if;

        xmin := - 0.65 * scale;
        xmax :=   0.65 * scale;
        ymin := - 0.65 * scale;
        ymax :=   0.65 * scale;

        Set_Viewport_World(xmin, xmax, ymin, ymax);
        Set_Pen_Color(Red);
        declare
            xcoord_local, ycoord_local : Real_Vector(0 .. steps * windings);
        begin
            xcoord_local := xcoord(0 .. steps * windings);
            ycoord_local := ycoord(0 .. steps * windings);
            Draw_Curve(xcoord_local, ycoord_local);
        end;
    end spiro;


    procedure cycloid is
    begin
        null; -- TODO
    end cycloid;

begin
    -- Parse and process command line arguments
    Parse_Command_Line_Arguments(Parse_Full);

    -- Initialize plplot
    Initialize_PLplot;

    -- Illustrate the construction of a cycloid
    cycloid;

    -- Loop over the various curves.
    -- First an overview, then all curves one by one
    Set_Number_Of_Subpages(3, 3) ; -- Three by three window

    for i in params'range(1) loop
        Advance_To_Subpage(Next_Subpage);
        Set_Viewport_Normalized( 0.0, 1.0, 0.0, 1.0 );
        spiro(params, i);
    end loop;

    Advance_To_Subpage(Next_Subpage) ;
    Set_Number_Of_Subpages(1, 1) ; -- One window per curve

    for i in params'range(1) loop
        Advance_To_Subpage(Next_Subpage) ;
        Set_Viewport_Normalized( 0.0, 1.0, 0.0, 1.0 ) ;
        spiro(params, i);
    end loop;

    -- Don't forget to call End_PLplot to finish off!
    End_PLplot;
end xthick27a;