From: <and...@us...> - 2011-08-04 08:58:59
|
Revision: 11851 http://plplot.svn.sourceforge.net/plplot/?rev=11851&view=rev Author: andrewross Date: 2011-08-04 08:58:52 +0000 (Thu, 04 Aug 2011) Log Message: ----------- Tweak C example 27. Update C++, f77 and f95 versions to include plarc demo. Modified Paths: -------------- trunk/examples/c/x27c.c trunk/examples/c++/x27.cc trunk/examples/f77/x27f.fm4 trunk/examples/f95/x27f.f90 Modified: trunk/examples/c/x27c.c =================================================================== --- trunk/examples/c/x27c.c 2011-08-04 08:23:43 UTC (rev 11850) +++ trunk/examples/c/x27c.c 2011-08-04 08:58:52 UTC (rev 11851) @@ -24,8 +24,6 @@ #include "plcdemos.h" -#define DEG_TO_RAD( x ) ( ( x ) * M_PI / 180.0 ) - // Function prototypes void cycloid( void ); @@ -227,7 +225,7 @@ void arcs() { #define NSEG 8 int i; - PLFLT theta, dtheta, thetarad; + PLFLT theta, dtheta; PLFLT a, b; theta = 0.0; @@ -244,11 +242,11 @@ // Draw several filled ellipses inside the circle at different // angles. a = 3.0; - b = a * tan( DEG_TO_RAD(dtheta)/2.0 ); + b = a * tan( (dtheta/180.0*M_PI)/2.0 ); theta = dtheta/2.0; for ( i = 0; i < NSEG; i++ ) { plcol0( 2 - i%2 ); - plarc( a*cos(DEG_TO_RAD(theta)), a*sin(DEG_TO_RAD(theta)), a, b, 0.0, 360.0, theta, 1); + plarc( a*cos(theta/180.0*M_PI), a*sin(theta/180.0*M_PI), a, b, 0.0, 360.0, theta, 1); theta = theta + dtheta; } Modified: trunk/examples/c++/x27.cc =================================================================== --- trunk/examples/c++/x27.cc 2011-08-04 08:23:43 UTC (rev 11850) +++ trunk/examples/c++/x27.cc 2011-08-04 08:58:52 UTC (rev 11851) @@ -32,13 +32,13 @@ using namespace std; #endif - class x27 { public: x27( int, const char ** ); void cycloid( void ); void spiro( PLFLT data[], int fill ); PLINT gcd( PLINT a, PLINT b ); + void arcs(); private: // Class data @@ -120,6 +120,12 @@ pls->vpor( 0.0, 1.0, 0.0, 1.0 ); spiro( ¶ms[i][0], fill ); } + + // Finally, an example to test out plarc capabilities + + arcs(); + + delete pls; } @@ -224,7 +230,38 @@ } } +void +x27::arcs() { +#define NSEG 8 + int i; + PLFLT theta, dtheta; + PLFLT a, b; + theta = 0.0; + dtheta = 360.0 / NSEG; + pls->env( -10.0, 10.0, -10.0, 10.0, 1, 0 ); + + // Plot segments of circle in different colors + for ( i = 0; i < NSEG; i++ ) { + pls->col0( i%2 + 1 ); + pls->arc(0.0, 0.0, 8.0, 8.0, theta, theta + dtheta, 0.0, 0); + theta = theta + dtheta; + } + + // Draw several filled ellipses inside the circle at different + // angles. + a = 3.0; + b = a * tan( (dtheta/180.0*M_PI)/2.0 ); + theta = dtheta/2.0; + for ( i = 0; i < NSEG; i++ ) { + pls->col0( 2 - i%2 ); + pls->arc( a*cos(theta/180.0*M_PI), a*sin(theta/180.0*M_PI), a, b, 0.0, 360.0, theta, 1); + theta = theta + dtheta; + } + +} + + int main( int argc, const char ** argv ) { x27 *x = new x27( argc, argv ); Modified: trunk/examples/f77/x27f.fm4 =================================================================== --- trunk/examples/f77/x27f.fm4 2011-08-04 08:23:43 UTC (rev 11850) +++ trunk/examples/f77/x27f.fm4 2011-08-04 08:58:52 UTC (rev 11851) @@ -102,6 +102,10 @@ call spiro( params(1,i), fill ) 130 continue +c Finally, an example to test out plarc capabilities + + call arcs() + call plend() end @@ -202,3 +206,41 @@ endif end + +c =============================================================== + + subroutine arcs() + + implicit none + include 'plplot_parameters.h' + integer NSEG + parameter ( NSEG = 8 ) + integer i; + real*8 theta, dtheta + real*8 a, b + + theta = 0.0d0 + dtheta = 360.0d0 / dble(NSEG) + call plenv( -10.0d0, 10.0d0, -10.0d0, 10.0d0, 1, 0 ) + +c Plot segments of circle in different colors + do i = 0, NSEG-1 + call plcol0( mod(i,2) + 1 ) + call plarc(0.0d0, 0.0d0, 8.0d0, 8.0d0, theta, theta + dtheta, + 1 0.0d0, 0) + theta = theta + dtheta + enddo + +c Draw several filled ellipses inside the circle at different +c angles. + a = 3.0d0 + b = a * tan( (dtheta/180.0d0*pi)/2.0d0 ) + theta = dtheta/2.0d0 + do i = 0, NSEG-1 + call plcol0( 2 - mod(i,2) ) + call plarc( a*cos(theta/180.0d0*pi), a*sin(theta/180.0d0*pi), + 1 a, b, 0.0d0, 360.0d0, theta, .true.) + theta = theta + dtheta; + enddo + + end Modified: trunk/examples/f95/x27f.f90 =================================================================== --- trunk/examples/f95/x27f.f90 2011-08-04 08:23:43 UTC (rev 11850) +++ trunk/examples/f95/x27f.f90 2011-08-04 08:58:52 UTC (rev 11851) @@ -101,6 +101,9 @@ call spiro( params(1,i), fill ) end do + ! Finally, an example to test out plarc capabilities + call arcs() + call plend() end program x27f @@ -205,3 +208,44 @@ endif end subroutine spiro + +! =============================================================== + +subroutine arcs( ) + + use plplot + implicit none + + integer NSEG + parameter ( NSEG = 8 ) + integer i; + real (kind=plflt) theta, dtheta + real (kind=plflt) a, b + + theta = 0.0_plflt + dtheta = 360.0_plflt / dble(NSEG) + call plenv( -10.0_plflt, 10.0_plflt, -10.0_plflt, 10.0_plflt, 1, 0 ) + + ! Plot segments of circle in different colors + do i = 0, NSEG-1 + call plcol0( mod(i,2) + 1 ) + call plarc(0.0_plflt, 0.0_plflt, 8.0_plflt, 8.0_plflt, theta, & + theta + dtheta, 0.0_plflt, 0) + theta = theta + dtheta + enddo + + ! Draw several filled ellipses inside the circle at different + ! angles. + a = 3.0_plflt + b = a * tan( (dtheta/180.0_plflt*PL_PI)/2.0_plflt ) + theta = dtheta/2.0_plflt + do i = 0, NSEG-1 + call plcol0( 2 - mod(i,2) ) + call plarc( a*cos(theta/180.0_plflt*PL_PI), & + a*sin(theta/180.0_plflt*PL_PI), & + a, b, 0.0_plflt, 360.0_plflt, theta, .true.) + theta = theta + dtheta; + enddo + +end subroutine arcs + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |