PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/v5_9_6_debian/examples/c/x02c.c

#
C | 154 lines | 73 code | 32 blank | 49 comment | 4 complexity | 86917af4a0cdf4c9d00b2b84eb256a0e MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, Apache-2.0, GPL-2.0
  1. /* $Id: x02c.c 10543 2009-10-21 22:07:16Z airwin $
  2. *
  3. * Multiple window and color map 0 demo.
  4. */
  5. #include "plcdemos.h"
  6. /*--------------------------------------------------------------------------*\
  7. * main
  8. *
  9. * Demonstrates multiple windows and color map 0 palette, both default and
  10. * user-modified.
  11. \*--------------------------------------------------------------------------*/
  12. void demo1();
  13. void demo2();
  14. void draw_windows( int nw, int cmap0_offset );
  15. int
  16. main( int argc, const char *argv[] )
  17. {
  18. /* Parse and process command line arguments */
  19. (void) plparseopts( &argc, argv, PL_PARSE_FULL );
  20. /* Initialize plplot */
  21. plinit();
  22. /* Run demos */
  23. demo1();
  24. demo2();
  25. plend();
  26. exit( 0 );
  27. }
  28. /*--------------------------------------------------------------------------*\
  29. * demo1
  30. *
  31. * Demonstrates multiple windows and default color map 0 palette.
  32. \*--------------------------------------------------------------------------*/
  33. void demo1()
  34. {
  35. plbop();
  36. /* Divide screen into 16 regions */
  37. plssub( 4, 4 );
  38. draw_windows( 16, 0 );
  39. pleop();
  40. }
  41. /*--------------------------------------------------------------------------*\
  42. * demo2
  43. *
  44. * Demonstrates multiple windows, user-modified color map 0 palette, and
  45. * HLS -> RGB translation.
  46. \*--------------------------------------------------------------------------*/
  47. void demo2()
  48. {
  49. /* Set up cmap0 */
  50. /* Use 100 custom colors in addition to base 16 */
  51. PLINT r[116], g[116], b[116];
  52. /* Min & max lightness values */
  53. PLFLT lmin = 0.15, lmax = 0.85;
  54. int i;
  55. plbop();
  56. /* Divide screen into 100 regions */
  57. plssub( 10, 10 );
  58. for ( i = 0; i <= 99; i++ )
  59. {
  60. PLFLT h, l, s;
  61. PLFLT r1, g1, b1;
  62. /* Bounds on HLS, from plhlsrgb() commentary --
  63. * hue [0., 360.] degrees
  64. * lightness [0., 1.] magnitude
  65. * saturation [0., 1.] magnitude
  66. */
  67. /* Vary hue uniformly from left to right */
  68. h = ( 360. / 10. ) * ( i % 10 );
  69. /* Vary lightness uniformly from top to bottom, between min & max */
  70. l = lmin + ( lmax - lmin ) * ( i / 10 ) / 9.;
  71. /* Use max saturation */
  72. s = 1.0;
  73. plhlsrgb( h, l, s, &r1, &g1, &b1 );
  74. /*printf("%3d %15.9f %15.9f %15.9f %15.9f %15.9f %15.9f\n",
  75. * i+16,h,l,s,r1,g1,b1); */
  76. /* Use 255.001 to avoid close truncation decisions in this example. */
  77. r[i + 16] = (PLINT) ( r1 * 255.001 );
  78. g[i + 16] = (PLINT) ( g1 * 255.001 );
  79. b[i + 16] = (PLINT) ( b1 * 255.001 );
  80. }
  81. /* Load default cmap0 colors into our custom set */
  82. for ( i = 0; i <= 15; i++ )
  83. plgcol0( i, &r[i], &g[i], &b[i] );
  84. /* for (i = 0; i < 116; i++)
  85. * printf("%3d %3d %3d %3d \n", i, r[i], g[i], b[i]); */
  86. /* Now set cmap0 all at once (faster, since fewer driver calls) */
  87. plscmap0( r, g, b, 116 );
  88. draw_windows( 100, 16 );
  89. pleop();
  90. }
  91. /*--------------------------------------------------------------------------*\
  92. * draw_windows
  93. *
  94. * Draws a set of numbered boxes with colors according to cmap0 entry.
  95. \*--------------------------------------------------------------------------*/
  96. void draw_windows( int nw, int cmap0_offset )
  97. {
  98. int i, j;
  99. PLFLT vmin, vmax;
  100. char text[3];
  101. plschr( 0.0, 3.5 );
  102. plfont( 4 );
  103. for ( i = 0; i < nw; i++ )
  104. {
  105. plcol0( i + cmap0_offset );
  106. sprintf( text, "%d", i );
  107. pladv( 0 );
  108. vmin = 0.1;
  109. vmax = 0.9;
  110. for ( j = 0; j <= 2; j++ )
  111. {
  112. plwid( j + 1 );
  113. plvpor( vmin, vmax, vmin, vmax );
  114. plwind( 0.0, 1.0, 0.0, 1.0 );
  115. plbox( "bc", 0.0, 0, "bc", 0.0, 0 );
  116. vmin = vmin + 0.1;
  117. vmax = vmax - 0.1;
  118. }
  119. plwid( 1 );
  120. plptex( 0.5, 0.5, 1.0, 0.0, 0.5, text );
  121. }
  122. }