home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / graphics.e < prev    next >
Text File  |  1994-01-12  |  5KB  |  199 lines

  1.         -------------------------------------
  2.         -- Graphics & Sound: MSDOS version --
  3.         -------------------------------------
  4.  
  5. --    GRAPHICS MODES --  argument to graphics_mode()
  6.  
  7. --   -1  restore to original default mode
  8. --    0  40 x 25 text, 16 grey
  9. --    1  40 x 25 text, 16/8 color
  10. --    2  80 x 25 text, 16 grey
  11. --    3  80 x 25 text, 16/8 color
  12. --    4  320 x 200, 4 color
  13. --    5  320 x 200, 4 grey
  14. --    6  640 x 200, BW
  15. --    7  80 x 25 text, BW
  16. --   11  720 x 350, BW
  17. --   13  320 x 200, 16 color
  18. --   14  640 x 200, 16 color
  19. --   15  640 x 350, BW
  20. --   16  640 x 350, 4 or 16 color
  21. --   17  640 x 480, BW
  22. --   18  640 x 480, 16 color
  23. --   19  320 x 200, 256 color
  24. --  256  640 x 400, 256 color
  25. --  257  640 x 480, 256 color
  26. --  258  800 x 600, 16 color
  27. --  259  800 x 600, 256 color
  28. --  260  1024 x 768, 16 color
  29. --  261  1024 x 768, 256 color
  30.  
  31. -- COLOR values -- for characters and pixels
  32. --
  33. --   0   black          8   gray
  34. --   1   blue           9   light blue
  35. --   2   green         10   light green
  36. --   3   cyan          11   light cyan  
  37. --   4   red           12   light red
  38. --   5   magenta       13   light magenta
  39. --   6   brown         14   yellow
  40. --   7   white         15   bright white
  41.  
  42. --   add 16 to get blinking text
  43.  
  44. -- machine() commands
  45. constant M_SOUND          = 1,
  46.      M_LINE           = 2,
  47.      M_PALETTE        = 3,
  48.      M_PIXEL          = 4,
  49.      M_GRAPHICS_MODE  = 5,
  50.      M_CURSOR         = 6,
  51.      M_WRAP           = 7,
  52.      M_SCROLL         = 8,
  53.      M_SET_T_COLOR    = 9,
  54.      M_SET_B_COLOR    = 10,
  55.      M_POLYGON        = 11,
  56.      M_TEXTROWS       = 12,
  57.      M_VIDEO_CONFIG   = 13,
  58.      M_ELLIPSE        = 18,
  59.      M_GET_PIXEL      = 21
  60.  
  61. type mode(integer x)
  62.     return (x >= -3 and x <= 19) or (x >= 256 and x <= 261)
  63. end type
  64.  
  65. type color(integer x)
  66.     return x >= 0 and x <= 255
  67. end type
  68.  
  69. type boolean(integer x)
  70.     return x = 0 or x = 1
  71. end type
  72.  
  73. type positive_int(integer x)
  74.     return x >= 1
  75. end type
  76.  
  77. type point(sequence x)
  78.     return length(x) = 2
  79. end type
  80.  
  81. type point_sequence(sequence x)
  82.     return length(x) >= 2
  83. end type
  84.  
  85. global procedure draw_line(color c, point_sequence xyarray)
  86. -- draw a line connecting the 2 or more points
  87. -- in xyarray: {{x1, y1}, {x2, y2}, ...}
  88. -- using a certain color 
  89. -- (the width parameter of v1.0 has been dropped)
  90.     machine_proc(M_LINE, {c, 0, xyarray})
  91. end procedure
  92.  
  93. global procedure polygon(color c,
  94.              boolean fill,
  95.              point_sequence xyarray)
  96. -- draw a polygon using a certain color
  97. -- fill the area if fill is TRUE
  98. -- 3 or more vertices are given in xyarray
  99. -- (the width parameter of v1.0 has been dropped)
  100.     machine_proc(M_POLYGON, {c, fill, xyarray})
  101. end procedure
  102.  
  103. global procedure ellipse(color c, boolean fill, point p1, point p2)
  104. -- draw an ellipse with a certain color that fits in the
  105. -- rectangle defined by diagonal points p1 and p2, i.e. 
  106. -- {x1, y1} and {x2, y2}. The ellipse may be filled or just an outline.   
  107.     machine_proc(M_ELLIPSE, {c, fill, p1, p2})
  108. end procedure
  109.  
  110. global procedure pixel(color c, point p)
  111. -- set a pixel to a certain color
  112.     machine_proc(M_PIXEL, {c, p})
  113. end procedure
  114.  
  115. global function get_pixel(point p)
  116. -- read color number of a pixel on the screen
  117.     return machine_func(M_GET_PIXEL, p)
  118. end function
  119.  
  120. global function graphics_mode(mode m)
  121. -- try to set up a new graphics mode
  122. -- return 0 if successful, non-zero if failed
  123.    return machine_func(M_GRAPHICS_MODE, m)
  124. end function
  125.  
  126. global constant VC_COLOR = 1,
  127.         VC_MODE  = 2,
  128.         VC_LINES = 3,
  129.         VC_COLUMNS = 4,
  130.         VC_XPIXELS = 5,
  131.         VC_YPIXELS = 6,
  132.         VC_NCOLORS = 7
  133. global function video_config()
  134. -- return sequence of information on video configuration
  135. -- {color?, mode, text lines, text columns, xpixels, ypixels, #colors}
  136.     return machine_func(M_VIDEO_CONFIG, 0)
  137. end function
  138.  
  139. -- cursor styles:
  140. global constant NO_CURSOR  = 8192,
  141.      UNDERLINE_CURSOR  = 1543,
  142.      BLOCK_CURSOR      = 7,
  143.      HALF_BLOCK_CURSOR = 1031
  144.  
  145. global procedure cursor(integer style)
  146. -- choose a cursor style
  147.     machine_proc(M_CURSOR, style)
  148. end procedure
  149.  
  150. global function text_rows(positive_int rows)
  151.     return machine_func(M_TEXTROWS, rows)
  152. end function
  153.  
  154. global procedure wrap(boolean on)
  155. -- on = 1: characters will wrap at end of long line
  156. -- on = 0: lines will be truncated
  157.     machine_proc(M_WRAP, on)
  158. end procedure
  159.  
  160. global procedure scroll(integer amount)
  161. -- amount > 0: scroll the screen up by amount lines
  162. -- amount < 0: scroll down by amount lines
  163.     machine_proc(M_SCROLL, amount)
  164. end procedure
  165.  
  166. global procedure text_color(color c)
  167. -- set the foreground text color to c - text or graphics modes
  168. -- add 16 to get blinking
  169.     machine_proc(M_SET_T_COLOR, c)
  170. end procedure
  171.  
  172. global procedure bk_color(color c)
  173. -- set the background color to c - text or graphics modes
  174.     machine_proc(M_SET_B_COLOR, c)
  175. end procedure
  176.  
  177. type mixture(sequence s)
  178.     return length(s) = 3 -- {red, green, blue}
  179. end type
  180.  
  181. global function palette(color c, mixture s)
  182. -- choose a new mix of {red, green, blue} to be shown on the screen for
  183. -- color number c. Returns previous mixture as {red, green, blue}.
  184.     return machine_func(M_PALETTE, {c, s})
  185. end function
  186.  
  187. -- Sound Effects --
  188.  
  189. type frequency(integer x)
  190.     return x >= 0
  191. end type
  192.  
  193. global procedure sound(frequency f)
  194. -- turn on speaker at frequency f
  195. -- turn off speaker if f is 0
  196.     machine_proc(M_SOUND, f)
  197. end procedure
  198.  
  199.