Author Topic: Re: Screen 0 as LED  (Read 1126 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Screen 0 as LED
« on: September 03, 2018, 11:32:32 am »
Cool! I like the marching robot.
In order to understand recursion, one must first understand recursion.

FellippeHeitor

  • Guest
Re: Screen 0 as LED
« Reply #1 on: September 03, 2018, 11:45:53 am »
Wait, wait, wait... "Buddy the Robot"? Is that Norby's last name? Norby Buddy the Robot?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Screen 0 as LED
« Reply #2 on: September 04, 2018, 08:35:05 am »
That is fun!

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: Screen 0 as LED
« Reply #3 on: September 04, 2018, 12:16:10 pm »
I liked it too:
modified to be self-contained for inclusion in QB64 Demos, perhaps.
Code: QB64: [Select]
  1.  
  2. _TITLE "Screen 0 as LED"
  3.  
  4. CONST ROUND = 0, SQUARE = 1
  5.  
  6. TYPE Sign
  7.     Screen AS LONG ' the Sign screen to show on screen
  8.     Image AS LONG '  the Sign image to work on in the background
  9.     Mask AS LONG '   the Sign mask to place over the Sign image
  10.  
  11. DIM SHARED Sign AS Sign
  12.  
  13. MAKELED 640, 400, 2, ROUND
  14.  
  15. DIM SHARED Parts(46) AS STRING
  16. 'OPEN "Robot.dat" FOR INPUT AS #1
  17.  
  18. FOR p = 1 TO 45
  19.     READ Parts(p)
  20.  
  21.  
  22.  
  23. Start = Main
  24.  
  25.     DIM Touch AS STRING
  26.  
  27.     DIM Title AS STRING
  28.     Title = SPACE$(80) + "Screen 0 as LED using code from Terry Ritchie's LED Maker. "
  29.  
  30.     tPos = 1
  31.     WHILE NOT Quit
  32.         _DEST Sign.Image
  33.         COLOR _RGB(0, 255, 255)
  34.  
  35.         LOCATE 1, 1
  36.         PRINT MID$(Title, tPos, 80);
  37.  
  38.         AnimBot
  39.  
  40.         _DEST 0
  41.         _PUTIMAGE , Sign.Image
  42.         _PUTIMAGE , Sign.Mask
  43.  
  44.         tPos = tPos + 1
  45.         IF tPos > LEN(Title) THEN tPos = 1
  46.  
  47.         Touch = INKEY$
  48.         IF Touch = CHR$(27) THEN SYSTEM
  49.  
  50.         _DISPLAY
  51.         _LIMIT 10
  52.     WEND
  53.  
  54. SUB AnimBot
  55.     ' Save Arm and Leg Positions
  56.     SHARED arm
  57.     SHARED leg
  58.  
  59.     DIM temp AS STRING
  60.  
  61.     ' Get Arm and Leg Positions
  62.     temp = MID$("0010203020100102030201", 2 * arm + 1, 2)
  63.  
  64.     b1 = VAL(LEFT$(temp, 1))
  65.     b2 = VAL(RIGHT$(temp, 1))
  66.  
  67.     ' Show Buddy the Robot
  68.     Buddy 20, 1, 1, 1, b1, b2, b2, b1
  69.  
  70.     ' Increase his Arm and Leg Positions
  71.     arm = arm + 1: IF arm > 10 THEN arm = 0
  72.     leg = leg + 1: IF leg > 10 THEN leg = 0
  73.  
  74. SUB MAKELED (w AS INTEGER, h AS INTEGER, pSize AS INTEGER, pShape AS INTEGER)
  75.     DIM x AS INTEGER
  76.     DIM y AS INTEGER
  77.  
  78.     DIM c AS INTEGER
  79.     c = 8
  80.  
  81.     DIM LEDPixel AS LONG
  82.     DIM OriginalDest AS LONG
  83.     OriginalDest = _DEST
  84.  
  85.     Sign.Screen = _NEWIMAGE(w * pSize, h * pSize, 32)
  86.     Sign.Image = _NEWIMAGE(w, h, 32)
  87.     Sign.Mask = _COPYIMAGE(Sign.Screen)
  88.     LEDPixel = _NEWIMAGE(pSize, pSize, 32)
  89.  
  90.     _DEST LEDPixel
  91.     LINE (0, 0)-(pSize - 1, pSize - 1), _RGB32(c, c, c), BF
  92.  
  93.     SELECT CASE pShape
  94.         CASE ROUND
  95.             CIRCLE (pSize \ 2, pSize \ 2), pSize \ 2 - 1, _RGB32(0, 0, 2)
  96.             PAINT (pSize \ 2, pSize \ 2), _RGB32(0, 0, 1), _RGB32(0, 0, 2)
  97.  
  98.         CASE SQUARE
  99.             LINE (1, 1)-(pSize - 1, pSize - 1), _RGB32(0, 0, 2), B
  100.             LINE (2, 2)-(pSize - 2, pSize - 2), _RGB32(0, 0, 1), BF
  101.     END SELECT
  102.  
  103.     _DEST Sign.Mask
  104.     FOR x = 0 TO w * pSize - 1 STEP pSize
  105.         FOR y = 0 TO h * pSize - 1 STEP pSize
  106.             _PUTIMAGE (x, y), LEDPixel&
  107.         NEXT y
  108.     NEXT x
  109.  
  110.     FOR x = 0 TO w * pSize - 1 STEP pSize * 8
  111.         LINE (x, 0)-(x, h * pSize - 1), _RGB32(c, c, c)
  112.     NEXT x
  113.  
  114.     FOR y = 0 TO h * pSize - 1 STEP pSize * 8
  115.         LINE (0, y)-(w * pSize - 1, y), _RGB32(c, c, c)
  116.     NEXT y
  117.  
  118.     _SETALPHA 0, _RGB32(0, 0, 1)
  119.     _SETALPHA 63, _RGB32(0, 0, 2)
  120.  
  121.     _DEST OriginalDest
  122.     _FREEIMAGE LEDPixel
  123.  
  124. SUB Scroll (Text AS STRING)
  125.     DIM Touch AS STRING
  126.  
  127.     DIM Title AS STRING
  128.     Title = SPACE$(16) + "Multi-Line LED "
  129.  
  130.     DIM tPos AS INTEGER
  131.     textPos = 1
  132.     titlePos = 1
  133.  
  134.     WHILE tPos < LEN(Text)
  135.         _DEST Sign.Image
  136.         COLOR _RGB32(255, 215, 32)
  137.  
  138.         LOCATE 1, 1
  139.         PRINT MID$(Title, titlePos, 16);
  140.  
  141.         LOCATE 2, 1
  142.         PRINT MID$(Text, textPos, 16);
  143.  
  144.         _DEST 0
  145.         _PUTIMAGE , Sign.Image
  146.         _PUTIMAGE , Sign.Mask
  147.  
  148.         textPos = textPos + 1
  149.         titlePos = titlePos + 1
  150.         IF titlePos > 31 THEN titlePos = 1
  151.  
  152.         Touch = INKEY$
  153.         IF Touch = CHR$(27) THEN SYSTEM
  154.  
  155.         _DISPLAY
  156.         _LIMIT 6
  157.     WEND
  158.  
  159. SUB Buddy (botX, botY, headV, bodyV, ArmV1, ArmV2, LegV1, LegV2)
  160.     COLOR _RGB(255, 218, 185)
  161.  
  162.     ' Head
  163.     FOR head = 1 TO 6
  164.         LOCATE botY + (head - 1), botX + 8
  165.         PRINT MID$(Parts(head), 24 * headV + 1, 24);
  166.     NEXT
  167.  
  168.     ' Body
  169.     FOR body = 7 TO 19
  170.         LOCATE botY + (body - 1), botX + 7
  171.         PRINT MID$(Parts(body), 26 * bodyV + 1, 26);
  172.     NEXT
  173.  
  174.     ' Arms
  175.     FOR arm = 20 TO 29
  176.         ' Left Arm
  177.         LOCATE botY + (arm - 13), botX
  178.         PRINT MID$(Parts(arm), 7 * ArmV1 + 1, 7);
  179.  
  180.         ' Right Arm
  181.         LOCATE botY + (arm - 13), botX + 33
  182.         PRINT MID$(Parts(arm + 10), 7 * ArmV2 + 1, 7);
  183.     NEXT
  184.  
  185.     ' Legs
  186.     FOR leg = 40 TO 45
  187.         ' Left Leg
  188.         LOCATE botY + (leg - 21), botX + 10
  189.         PRINT MID$(Parts(leg), 10 * LegV1 + 1, 10);
  190.  
  191.         ' Right Leg
  192.         LOCATE botY + (leg - 21), botX + 20
  193.         PRINT MID$(Parts(leg), 10 * LegV2 + 1, 10);
  194.     NEXT
  195.  
  196.     ' Eyes
  197.     COLOR _RGB(135, 206, 235)
  198.     LOCATE botY + 1, botX + 15: PRINT "0";
  199.     LOCATE botY + 1, botX + 24: PRINT "0";
  200.  
  201. DATA "     .---.    .---.          .---.    .---."
  202. DATA "    |     |__|     |        (((0)))--(((0)))"
  203. DATA " _.'                `._  _.'_`---'_/\_`---'_`._"
  204. DATA "|_:                  :_||_:   ____________   :_|"
  205. DATA "  |                  |    |   \__________/   |"
  206. DATA "  |__________________|    |__________________|"
  207. DATA "__..-'              `-..____..-'              `-..____..-'              `-..__"
  208. DATA " |                      |  | .------------------. |  | .------------------. |"
  209. DATA " |                      |  | |\________________/| |  | |\________________/| |"
  210. DATA " |                      |  | ||   __  __  __   || |  | ||                || |"
  211. DATA ".|                      |..| ||  '--''--''--'  || |..| ||                || |."
  212. DATA " |                      |  | ||  .----------.  || |  | ||                || |"
  213. DATA " |                      |  | ||  `----------'  || |  | ||                || |"
  214. DATA " |                      |  | ||   _        _   || |  | ||                || |"
  215. DATA " |                      |  | ||  (_)  ()  (_)  || |  | ||                || |"
  216. DATA " |                      |  | ||________________|| |  | ||________________|| |"
  217. DATA " |                      |  | |/________________\| |  | |/________________\| |"
  218. DATA " |______________________|  |______________________|  |______________________|"
  219. DATA " `\____________________/'  `\____________________/'  `\____________________/'"
  220. DATA "    .-|    .-|    .-|    .-|"
  221. DATA "  ./ :|  ./ :|  ./ :|  ./ :|"
  222. DATA " /`.\:| /`.\:| /`.\:| /`.\:|"
  223. DATA "|`-._\:|`-._\:|`-._\:|`-._\:"
  224. DATA ":    : |    | |    | :.--.:"
  225. DATA "|    | |    | :.--.: (`-'|)"
  226. DATA "|    | :.--.: (`-'|)  `--'"
  227. DATA ":.--.: (`-'|)  `--'"
  228. DATA "(`-'|)  `--'"
  229. DATA " `--'"
  230. DATA "|-.    |-.    |-.    |-."
  231. DATA "|: \.  |: \.  |: \.  |: \."
  232. DATA "|:/,'\ |:/,'\ |:/,'\ |:/,'\"
  233. DATA ":/_.-'::/_.-'::/_.-'::/_.-':"
  234. DATA " :    : |    | |    | :,--.:"
  235. DATA " |    | |    | :,--.: (|`-')"
  236. DATA " |    | :,--.: (|`-')  `--'"
  237. DATA " :,--.: (|`-')  `--'"
  238. DATA " (|`-')  `--'"
  239. DATA "  `--'"
  240. DATA " (______)  (______)  (______)  (______)"
  241. DATA " (______)  (______)  (______) |        |"
  242. DATA " (______)  (______) |        |`--------'"
  243. DATA " (______) |        |`--------'"
  244. DATA "|        |`--------'"
  245. DATA "`--------'"
  246.  

Thanks to Terry and [banned user] for the entertainment.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Screen 0 as LED
« Reply #4 on: September 04, 2018, 01:39:04 pm »
A quick toss of my hat into the LED emulation game:

Code: QB64: [Select]
  1. DEFLNG A-Z
  2.  
  3.  
  4. CONST W = 800, H = 600
  5. DIM SHARED WorkScreen
  6. DisplayScreen = _NEWIMAGE(W, H, 32)
  7. SCREEN DisplayScreen
  8.  
  9.  
  10.  
  11. size = 10 'A nice size to start testing with
  12. message$ = "Testing the code" 'A default message.  Feel free to change it.
  13. kolor = _RGB32(255, 255, 0) 'And the color of our LED
  14.  
  15. GenerateWorkscreen size, message$, kolor
  16.  
  17.     CLS
  18.     _LIMIT 30
  19.     k = _KEYHIT
  20.     DisplayWorkscreen StartX, StartY
  21.     SELECT CASE k
  22.         CASE 19200 'left
  23.             StartX = StartX - size: IF StartX < 0 THEN StartX = 0
  24.         CASE 19712 'right
  25.             StartX = StartX + size
  26.             IF StartX > _WIDTH(WorkScreen) - _WIDTH THEN StartX = _WIDTH(WorkScreen) - _WIDTH
  27.             IF StartX < 0 THEN StartX = 0
  28.         CASE 18432 'up
  29.             size = size + 1
  30.             GenerateWorkscreen size, message$, kolor
  31.         CASE 20480 'down
  32.             size = size - 1: IF size < 1 THEN size = 1
  33.             GenerateWorkscreen size, message$, kolor
  34.         CASE 27, 32
  35.             SYSTEM
  36.     END SELECT
  37.  
  38.     _DISPLAY
  39.  
  40. SUB DisplayWorkscreen (StartX, StartY)
  41.     _PUTIMAGE (0, 0)-(_WIDTH - 1, _HEIGHT - 1), WorkScreen, Displayscreen, (StartX, StartY)-STEP(_WIDTH - 1, _HEIGHT - 1)
  42.  
  43.  
  44. SUB GenerateWorkscreen (size, message$, kolor)
  45.     d = _DEST: s = _SOURCE 'play nice code
  46.     IF WorkScreen THEN _FREEIMAGE WorkScreen
  47.     WorkScreen = _NEWIMAGE(size * _FONTWIDTH * LEN(message$), size * _FONTHEIGHT, 32)
  48.     'create ASCII characters
  49.     AW = _FONTWIDTH * LEN(message$): AH = _FONTHEIGHT
  50.     ASCII = _NEWIMAGE(AW, AH, 32)
  51.     _DEST ASCII: _SOURCE ASCII
  52.     COLOR -1, 0
  53.     PRINT message$;
  54.     _DEST WorkScreen
  55.     FOR x = 0 TO AW - 1
  56.         FOR y = 0 TO AH - 1
  57.             IF POINT(x, y) THEN CircleFill x * size, y * size, size / 2 - 1, kolor
  58.         NEXT
  59.     NEXT
  60.     _FREEIMAGE ASCII
  61.     _DEST d: _SOURCE s 'to play nice with other routines
  62.  
  63. SUB CircleFill (CX AS LONG, CY AS LONG, R AS LONG, C AS LONG)
  64.     DIM Radius AS LONG, RadiusError AS LONG
  65.     DIM X AS LONG, Y AS LONG
  66.  
  67.     Radius = ABS(R)
  68.     RadiusError = -Radius
  69.     X = Radius
  70.     Y = 0
  71.  
  72.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  73.  
  74.     ' Draw the middle span here so we don't draw it twice in the main loop,
  75.     ' which would be a problem with blending turned on.
  76.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  77.  
  78.     WHILE X > Y
  79.         RadiusError = RadiusError + Y * 2 + 1
  80.         IF RadiusError >= 0 THEN
  81.             IF X <> Y + 1 THEN
  82.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  83.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  84.             END IF
  85.             X = X - 1
  86.             RadiusError = RadiusError - X * 2
  87.         END IF
  88.         Y = Y + 1
  89.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  90.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  91.     WEND
  92.  

Three import variables which you can change to play around with things:

size = 10 'A nice size to start testing with
message$ = "Testing the code" 'A default message.  Feel free to change it.
kolor = _RGB32(255, 255, 0) 'And the color of our LED

And a few basic controls:
UP/DOWN arrow keys will increase/decrease the size of the LEDs.
LEFT/RIGHT will scroll the screen so you can view any portion of the message which is currently off-screen.
SPACE/ESC will end the program

**********************

With just a little modification, one could make this an automatic scrolling routine, make the lights blink/flicker, or use it for multi-line displays (like with Buddy)...   The sky's the limit!!
« Last Edit: September 04, 2018, 01:46:31 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!