home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / ACE / Prgs / Gfx / 7seg.b next >
Text File  |  1994-12-14  |  3KB  |  159 lines

  1. {*
  2. ** 7-segment digit string display.
  3. **
  4. ** Author: David J Benn
  5. **   Date: 2nd,3rd,13th December 1994
  6. **
  7. **      1
  8. **     ____
  9. **    2 |    | 3
  10. **        |____|
  11. **      | 4  |
  12. **    5    |____| 6
  13. **
  14. **      7
  15. **
  16. ** Values passed to DrawSegment (see below) are based upon the
  17. ** following grid:
  18. **
  19. **    0 1 2 3 4 5 6
  20. **    0 xxxxxxxxxxxxx
  21. **    1 xxxxxxxxxxxxx
  22. **    2 xx       xx
  23. **    3 xxxxxxxxxxxxx
  24. **    4 xxxxxxxxxxxxx
  25. **    5 xx       xx
  26. **    6 xxxxxxxxxxxxx
  27. **    7 xxxxxxxxxxxxx
  28. **
  29. ** Modify xScale and yScale CONSTs to change the size
  30. ** and shape of the digits, eg.
  31. **
  32. **    xScale    yScale
  33. **    ------  ------
  34. **    25    17    
  35. **    15    10
  36. **    5    3
  37. **    2    1
  38. *}
  39.  
  40. CONST xScale = 15, yScale = 10
  41. CONST digitWidth = 6, gap = 1
  42. CONST true=-1&, false=0&
  43.  
  44. SHORTINT xOff,yOff,colr
  45.  
  46. DIM SHORTINT digit(9,7)
  47.  
  48. {*
  49. ** Store 7-segment configuration for each digit (1=ON, 0=OFF).
  50. ** More patterns can easily be added here, eg. for hex. digits.
  51. *}
  52. FOR i=0 TO 9
  53.   FOR j=1 TO 7
  54.     READ digit(i,j)
  55.   NEXT
  56. NEXT
  57.  
  58. {*
  59. **   1 2 3 4 5 6 7     <- segments
  60. *}
  61. DATA 1,1,1,0,1,1,1    '..0
  62. DATA 0,0,1,0,0,1,0    '..1
  63. DATA 1,0,1,1,1,0,1    '..2
  64. DATA 1,0,1,1,0,1,1    '..3
  65. DATA 0,1,1,1,0,1,0    '..4
  66. DATA 1,1,0,1,0,1,1    '..5
  67. DATA 0,1,0,1,1,1,1    '..6
  68. DATA 1,0,1,0,0,1,0    '..7
  69. DATA 1,1,1,1,1,1,1    '..8
  70. DATA 1,1,1,1,0,1,0    '..9
  71.  
  72. SUB DrawSegment(SHORTINT x1,SHORTINT y1,SHORTINT x2,SHORTINT y2)
  73. SHARED xOff,yOff,colr
  74.   '..Render a single segment.
  75.   LINE (xOff+x1*xScale,yOff+y1*yScale)- ~
  76.        (xOff+x2*xScale,yOff+y2*yScale),colr,bf
  77. END SUB
  78.  
  79. SUB PlotDigit(SHORTINT n)
  80. SHARED digit,xOff
  81.   '..Render a whole digit one segment at a time.
  82.   FOR i=1 TO 7
  83.     IF digit(n,i) = 1 THEN
  84.       CASE
  85.         i = 1 : DrawSegment(0,0,6,1)
  86.         i = 2 : DrawSegment(0,0,1,4)
  87.         i = 3 : DrawSegment(5,0,6,4)
  88.         i = 4 : DrawSegment(0,3,6,4)
  89.         i = 5 : DrawSegment(0,3,1,7)
  90.         i = 6 : DrawSegment(5,3,6,7)
  91.         i = 7 : DrawSegment(0,6,6,7)
  92.       END CASE
  93.     END IF
  94.   NEXT
  95.   '..Advance to the next digit position.
  96.   xOff = xOff + digitWidth*xScale + gap*xScale
  97. END SUB
  98.  
  99. SUB DisplayNumber(STRING theNumber)
  100.   '..Render a string of digits.
  101.   FOR i=1 TO LEN(theNumber)
  102.     PlotDigit(VAL(MID$(theNumber,i,1)))
  103.   NEXT
  104. END SUB
  105.  
  106. {*
  107. ** Main: seconds display.
  108. *}
  109. SCREEN 1,640,200,3,2
  110. WINDOW 1,"Seconds",(0,0)-(640,200),31,1
  111.  
  112. MENU 1,0,1,"Project"
  113. MENU 1,1,1,"Quit","Q"
  114. ON MENU GOSUB handle_menu
  115. MENU ON
  116.  
  117. ON WINDOW GOSUB handle_window
  118. WINDOW ON
  119.  
  120. PALETTE 0,0,0,0
  121. PALETTE 1,1,1,1
  122. PALETTE 2,0,0,1
  123. PALETTE 3,0,1,0
  124. PALETTE 4,0,1,1
  125. PALETTE 5,1,0,0
  126. PALETTE 6,1,0,1
  127. PALETTE 7,1,1,0
  128.  
  129. '..Continuously display seconds.
  130. yOff=50
  131. finished = false
  132.  
  133. REPEAT
  134.   xOff = 190
  135.   colr = 7
  136.   sec$ = RIGHT$(TIME$,2)
  137.   DisplayNumber(sec$)
  138.   time0=TIMER
  139.   WHILE TIMER<time0+1:WEND
  140.   xOff = 190
  141.   colr = 0
  142.   DisplayNumber(sec$)
  143. UNTIL finished
  144.  
  145. WINDOW CLOSE 1
  146. SCREEN CLOSE 1
  147. STOP
  148.  
  149. {*
  150. ** Event handlers.
  151. *}
  152. handle_menu:
  153.   IF MENU(0) = 1 AND MENU(1) = 1 THEN finished = true
  154. RETURN
  155.  
  156. handle_window:
  157.   finished = true
  158. RETURN
  159.