home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / EXAMPLES / FDISTRT.FOR < prev    next >
Text File  |  2000-02-11  |  2KB  |  127 lines

  1. c
  2. c Demonstrate how to use non-square viewports, the associated
  3. c distortion caused and how to fix it.
  4. c
  5.     program fdistrt
  6.  
  7.     integer BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE
  8.     parameter(BLACK = 0)
  9.     parameter(RED = 1)
  10.     parameter(GREEN = 2)
  11.     parameter(YELLOW = 3)
  12.     parameter(BLUE = 4)
  13.     parameter(MAGENTA = 5)
  14.     parameter(CYAN = 6)
  15.     parameter(WHITE = 7)
  16.     character device*50, buf*120
  17.     real    xfact, yfact
  18.  
  19.     print*,'Enter output device:'
  20.     read(*,'(a)') device
  21.  
  22.     call vinit(device)
  23.  
  24.     call color(BLACK)
  25.     call clear
  26.  
  27. c Make the viewport the same size as the screen/window.
  28. c
  29.     call getfactors(xfact, yfact)
  30.     call viewport(-1.0, xfact, -1.0, yfact)
  31.  
  32. c
  33. c Draw a square. (Looks like a rectangle, if the viewport
  34. c wasn't "accidentally" square)
  35. c
  36.     call color(1)
  37.     call rect(-0.5, -0.5, 0.5, 0.5)
  38.  
  39. c Tell them what it is.
  40. c
  41.     call move2(-1.0, 0.9)
  42.     write(buf,'(''Distorted square (viewport(-1, '',
  43.      +     F7.3, '', -1, '', F7.3, ''))'')') xfact, yfact
  44.     call drawstr(buf)
  45.  
  46.     call getkey
  47.  
  48. c
  49. c Fix up the distortion (The actual formula to fix
  50. c the distortion is (viewport.xmax * (1 + xfact) / 2.0),
  51. c and similar for the y axis.
  52. c
  53.     call ortho2(-1.0, xfact, -1.0, yfact)
  54.  
  55. c
  56. c Draw another square (Really is square this time)
  57. c
  58.     call color(3)
  59.     call rect(-0.5, -0.5, 0.5, 0.5)
  60.  
  61. c Tell them what it is.
  62. c
  63.     call move2(-1.0, -0.9)
  64.     write(buf,'(''Fixed up square with ortho2(-1, '',
  65.      +     F7.3, '', -1, '', F7.3, '')'')') xfact, yfact
  66.     call drawstr(buf)
  67.  
  68.     call getkey
  69.  
  70. c
  71. c Do it with world coords going from 0 - 5, 0 - 5.
  72. c Reset square viewport.
  73. c
  74.  
  75.     call color(0)
  76.     call clear
  77.  
  78.     call viewport(-1.0, 1.0, -1.0, 1.0)
  79.     call ortho2(0.0, 5.0, 0.0, 5.0)
  80.     call textsize(0.1, 0.1)
  81.  
  82. c
  83. c Square from 1 to 3. (Really is square)
  84. c
  85.  
  86.     call color(2)
  87.     call rect(1.0, 1.0, 3.0, 3.0)
  88.  
  89.     call move2(0.0, 4.5)
  90.     call drawstr('Square from 0 - 3, 0 - 3')
  91.  
  92.     call getkey
  93.  
  94. c
  95. c Distort it with a non-square viewport.
  96. c
  97.     call viewport(-1.0, xfact, -1.0, yfact)
  98.  
  99.     call color(4)
  100.     call rect(1.0, 1.0, 3.0, 3.0)
  101.  
  102.     call move2(0.0, 0.5)
  103.     call drawstr('Distorted square from 0 - 3, 0 - 3')
  104.  
  105.     call getkey
  106.  
  107. c Fix the distortion.
  108.     call ortho2(0.0, 5.0 * (1.0 + xfact) / 2.0, 0.0,
  109.      +                   5.0 * (1.0 + yfact) / 2.0)
  110.     
  111.     call color(5)
  112.     call rect(1.0, 1.0, 3.0, 3.0)
  113.  
  114.     call move2(0.0, 2.5)
  115.     call drawstr('Fixed up  square from 0 - 3, 0 - 3')
  116.  
  117.     call getkey
  118.  
  119.     call vexit
  120.  
  121.     end
  122.