home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 15 / CDACTUAL15.iso / cdactual / w95 / povray / 5X7LED.ZIP / 5X7LED.INC
Encoding:
Text File  |  1996-12-15  |  7.2 KB  |  249 lines

  1. //
  2. // 5 x 7 LED font for POVRay 3.0
  3. // version 1.1
  4. // 
  5. // Written by Michael D Johnson
  6. // Donated to public domain
  7. // 
  8. // You can reach me at
  9. //   mdjohnson@voyager.net
  10. //   http://quark.vpplus.com/~redbeard
  11. //
  12. // Newest version of this file can be found at
  13. //   http://quark.vpplus.com/~redbeard/raytrace/POVRay-Utils.html
  14. // 
  15. // Usage:
  16. //   This file will build objects consisting of a string converted to
  17. //   a 5 x 7 LED readout type font.  The result is a single object which
  18. //   you can use like:
  19. //     #declare Message =
  20. //     object
  21. //     {
  22. //          // Set variables
  23. //          #include "5x7led.inc"
  24. //     }
  25. // 
  26. // Variables:
  27. //  Message    none    String to convert
  28. //  Spacing    [1/5]    This is the amount of space (in fraction of character
  29. //             width) to leave between each character.
  30. //  Color    [spcl]    This is the color of an ON LED.  An off color is a
  31. //             dimmed version.  This only needs to be set if you
  32. //             choose not to use TextureOn and TextureOff.  Defaults
  33. //             to a greenish color.
  34. // TextureOn    none    Texture of an on LED
  35. // TextureOff    none    Texture of an off LED
  36. // LEDType    [0]    0 = round, 1 = square.  Uses 0 for Mode = 0
  37. // UseLights    [0]    0 = no light sources.  1 = Each on LED has a
  38. //            light_source.  I do not recommend
  39. //             using this.  I have not even bothered trying to do
  40. //             a complete trace (takes WAY too long)
  41. // Mode        [1]    Object type.  0 = blob, 1 = union, 2 = merge.  If
  42. //             Mode = 0, LEDType is set to 0.
  43. // LEDSize    [0.8]    Relative size of an LED.  1 makes the each LED fill
  44. //             its cell.
  45. // 
  46. //   The entire printable 7-bit ASCII character set has been implemented.
  47. // 
  48. // To run the demo, change the line #declare _5x7led_inc_ = 0 to = 1
  49. // 
  50. // History
  51. // -------
  52. // 12/10/96    Added LED sizing, blob support, fixed addresses, and
  53. //         reformatted comments
  54. //  6/08/96    Initial release
  55. // 
  56.  
  57.  
  58. #include "colors.inc"
  59.  
  60. #ifndef (_5x7led_inc_)
  61.   #declare _5x7led_inc_ = 0
  62. #end
  63.  
  64. #if (_5x7led_inc_)
  65.   #declare _5x7led_inc_ = 0
  66.   #declare Color = rgb <0.1, 0.7, 0.5>
  67.   #declare TextureOn =
  68.   texture
  69.   {
  70.       pigment { Color }
  71.       finish { diffuse 0.3 ambient 0.8 }
  72.   }
  73.   #declare TextureOff =
  74.   texture
  75.   {
  76.       pigment { Color * 0.5 }
  77.       finish { diffuse 0.3 ambient 0.2 }
  78.   }
  79.   #declare I = 0
  80.   #while (I < 4)
  81.     #switch (I)
  82.       #case (0) #declare Message = "   Hello, Folks!   " #break
  83.       #case (1) #declare Message = " This is a test of " #break
  84.       #case (2) #declare Message = "5x7led.inc Strings." #break
  85.       #case (3) #declare Message = "Thanks a whole lot." #break
  86.     #end
  87.     object
  88.     {
  89.     #include "5x7led.inc"
  90.     translate (8 / 5 * 2 - I * 8 / 5) * y
  91.     }
  92.     #declare I = I + 1
  93.   #end
  94.   light_source { <100, 100, -100> White }
  95.   camera
  96.   {
  97.       location <(_CPos + 1) / 2, -3, -_CPos * 0.8 >
  98.       look_at <(_CPos + 1) / 2, 0.7, 0>
  99.   }
  100.  
  101. #else
  102.  
  103.   #ifndef (Spacing)   #declare Spacing = 1/5 #end
  104.   #ifndef (UseLights) #declare UseLights = 0 #end
  105.   #ifndef (LEDType)   #declare LEDType = 0 #end
  106.   #ifndef (Mode)      #declare Mode = 1 #end
  107.   #ifndef (LEDSize)   #declare LEDSize = 0.8 #end
  108.   
  109.   #if (Mode = 0) #declare LEDType = 0 #end
  110.  
  111.   #ifndef (TextureOn)
  112.     #ifndef (Color)
  113.       #declare Color = rgbf <0.1, 0.7, 0.5, UseLights * 0.9>
  114.     #end
  115.     #declare _5x7led_TOn =
  116.     texture
  117.     {
  118.     pigment { Color }
  119.     finish { diffuse 0.3 ambient 0.8 }
  120.     }
  121.     #declare _5x7led_TOff =
  122.     texture
  123.     {
  124.     pigment { Color * 0.3 }
  125.     finish { diffuse 0.3 ambient 0.2 }
  126.     }
  127.   #else
  128.     #declare _5x7led_TOn  = texture { TextureOn  }
  129.     #declare _5x7led_TOff = texture { TextureOff }
  130.   #end
  131.   
  132.   #declare _5x7led_FontListNum =
  133.   concat("4AHHHA4", "464444E", "EH8421V", "EHGCGHE", "8CAV888", "V11FGGF",
  134.      "C21FHHE", "VG88444", "EHHEHHE", "EHHUG86")
  135.   #declare _5x7led_FontListSym1 =
  136.   concat("0000000", "4444404", "AA00000", "0AVAVA0", "4U5EKF4", "JJ842PP",
  137.      "6912L9M", "4200000", "8422248", "2488842", "4LE4EL4", "044V440",
  138.      "0000042", "000V000", "0000004", "GG84211")
  139.   #declare _5x7led_FontListSym2 =
  140.   concat("0040004", "0040042", "0842480", "00V0V00", "0248420", "EHG8404", 
  141.      "EHHTLP2")
  142.   #declare _5x7led_FontListSym3 =
  143.   concat("E22222E", "11248GG", "E88888E", "4AH0000", "000000V", "4800000")
  144.   #declare _5x7led_FontListSym4 =
  145.   concat("8442448", "4444444", "2448442", "00GE100")
  146.   #declare _5x7led_FontListUpper =
  147.   concat("4AHVHHH", "FHHFHHF", "U11111U", "FHHHHHF", "V11711V", "V117111", 
  148.      "U11THHE", "HHHVHHH", "V44444V", "GGGGGHE", "H95359H", "111111V",
  149.      "HRLHHHH", "HJLPHHH", "EHHHHHE", "FHHF111", "EHHHL9M", "FHHF59H", 
  150.      "U11EGGF", "V444444", "HHHHHHE", "HHHHAA4", "HHHHLRH", "HHA4AHH",
  151.      "HHA4444", "VG8421V")
  152.   #declare _5x7led_FontListLower =
  153.   concat("00EHHPM", "11FHHHF", "00E111E", "GGUHHHU", "00EHV1E", "CI27222", 
  154.      "00UHUGE", "111FHHH", "4044444", "8088886", "1195359", "4444444", 
  155.      "00BLLLL", "00DJHHH", "00EHHHE", "00FHF11", "00E9E8G", "00DJ111", 
  156.      "00U1EGF", "02F222C", "00HHHPM", "00HHAA4", "00HHLLA", "00HA4AH", 
  157.      "00HHUGE", "00V842V")
  158.   
  159.   
  160.   #switch (Mode)
  161.     #case (1) union #break
  162.     #case (0) blob #break
  163.     #case (2) merge #break
  164.   #else #error "Illegal value for Mode"
  165.   #end
  166.   {
  167.       #if (Mode = 0) threshold 0.5 #end
  168.       #declare _C = 1
  169.       #while (_C <= strlen(Message))
  170.     #declare _CPos = (_C - 1) * (1 + Spacing)
  171.     #declare _Char = substr(Message, _C, 1)
  172.     #declare _CharI = asc(_Char)
  173.     #switch(_CharI)
  174.       #range (32, 47)
  175.         #declare _CharI = _CharI - 32
  176.         #declare _CharS = _5x7led_FontListSym1
  177.       #break
  178.       #range (48, 57) 
  179.         #declare _CharI = _CharI - 48
  180.         #declare _CharS = _5x7led_FontListNum
  181.       #break
  182.       #range (58, 64)
  183.         #declare _CharI = _CharI - 58
  184.         #declare _CharS = _5x7led_FontListSym2
  185.       #break
  186.       #range (65, 90)
  187.         #declare _CharI = _CharI - 65
  188.         #declare _CharS = _5x7led_FontListUpper
  189.       #break
  190.       #range (91, 96)
  191.         #declare _CharI = _CharI - 91
  192.         #declare _CharS = _5x7led_FontListSym3
  193.       #break
  194.       #range (97, 122)
  195.         #declare _CharI = _CharI - 97
  196.         #declare _CharS = _5x7led_FontListLower
  197.       #break
  198.       #range (123, 126)
  199.         #declare _CharI = _CharI - 123
  200.         #declare _CharS = _5x7led_FontListSym4
  201.       #break
  202.     #else
  203.       #error concat("5x7led.inc: Unsupported character '", _Char, "'\n")
  204.     #end
  205.     #declare _CharS = substr(_CharS, _CharI * 7 + 1, 7)
  206.     #declare _I = 0
  207.     #while (_I < 7)
  208.       #declare _RVal = asc(substr(_CharS, _I + 1, 1)) - 48
  209.       #declare _RVal = ((_RVal > 9) ? _RVal - 7 : _RVal)
  210.       #declare _J = 0
  211.       #while (_J < 5)
  212.         #declare _Trans = <_J * 1/5 + 1/10 + _CPos,
  213.         (6 - _I) * 1/5 + 1/10, 0>
  214.         #if (LEDType = 0)
  215.           sphere
  216.         #else
  217.           box
  218.         #end
  219.         {
  220.         #if (LEDType = 0)
  221.           _Trans, 1/5 * LEDSize / 2
  222.           #if (Mode = 0), 1 #end
  223.         #else
  224.           -1, 1 scale 1/5 * LEDSize / 2 translate _Trans
  225.         #end
  226.         texture
  227.         {
  228.             #if (mod(_RVal, 2))
  229.               _5x7led_TOn
  230.             #else
  231.               _5x7led_TOff
  232.             #end
  233.         }
  234.         }
  235.         #if ((UseLights != 0) & (mod(_RVal, 2)))
  236.           light_source { _Trans White }
  237.         #end
  238.         #declare _RVal = int(_RVal / 2)
  239.         #declare _J = _J + 1
  240.       #end
  241.       #declare _I = _I + 1
  242.     #end
  243.     #declare _C = _C + 1
  244.       #end
  245.       #if (Mode = 0) texture { _5x7led_TOff } #end
  246.   }
  247.   
  248. #end
  249.