Author Topic: ASCII torch on a land of dark letters  (Read 4541 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
ASCII torch on a land of dark letters
« on: April 21, 2019, 08:00:39 pm »
Hi guys

going on with the little demo of a torch made by ASCII in graphic 32 bit
here the result (I have brougth up the SUB version that is my way to code, I am not so able with GOSUB):

Code: QB64: [Select]
  1. DIM SHARED A AS LONG, whites(1 TO 50) AS LONG, Black AS LONG, Black2 AS LONG
  2. DIM SHARED area(1 TO 25, 1 TO 62) AS STRING * 1, Lamp AS INTEGER
  3. DIM min AS INTEGER, max AS INTEGER, up AS INTEGER, down AS INTEGER
  4.  
  5.  
  6. Setup
  7. 'CalculateRows
  8. '30 rows and 62 columns
  9. col = 1
  10. row = 1
  11. min = 1
  12. max = 47
  13. up = 1
  14. down = 23
  15. Lamp = 1
  16.  
  17.  
  18.     IF _KEYDOWN(19200) THEN
  19.         LOCATE 27, 1: COLOR whites(1): PRINT "Left" + SPACE$(20)
  20.         IF col > min THEN col = col - 1
  21.     END IF
  22.     IF _KEYDOWN(19712) THEN
  23.         LOCATE 27, 1: COLOR whites(1): PRINT "Right" + SPACE$(20)
  24.         IF col < max THEN col = col + 1
  25.     END IF
  26.     IF _KEYDOWN(18432) THEN
  27.         LOCATE 27, 1: COLOR whites(1): PRINT "Up " + SPACE$(20)
  28.         IF row > up THEN row = row - 1
  29.     END IF
  30.     IF _KEYDOWN(20480) THEN
  31.         LOCATE 27, 1: COLOR whites(1): PRINT "Down" + SPACE$(20)
  32.         IF row < down THEN row = row + 1
  33.     END IF
  34.     IF _KEYDOWN(13) THEN
  35.         Lamp = Lamp + 1
  36.         IF Lamp > 3 THEN Lamp = 1
  37.         IF Lamp = 1 THEN
  38.             max = 47: down = 23
  39.         ELSEIF Lamp = 2 THEN
  40.             max = 62: down = 25
  41.         ELSEIF Lamp = 3 THEN
  42.             max = 58: down = 22
  43.         END IF
  44.         IF row > down THEN row = down
  45.         IF col > max THEN col = max
  46.         LOCATE 27, 1: COLOR whites(1): PRINT "Enter change shape of lamp     "
  47.     END IF
  48.     Arena
  49.     MoveLight row, col, 1, 16
  50.     LOCATE 26, 1: COLOR _RGB(255, 255, 55), Black: PRINT " press arrows to move light, enter change lamp, space to quit "
  51.     _LIMIT 12
  52.     CLS
  53.  
  54. FUNCTION MinMax (Min AS INTEGER, Max AS INTEGER)
  55.     IF Min > Max THEN SWAP Min, Max
  56.     MinMax = INT(RND * (Max - Min + 1)) + Min
  57.  
  58. SUB Arena
  59.     DIM x AS INTEGER, y AS INTEGER
  60.     LOCATE 1, 1
  61.     COLOR Black2, Black
  62.     FOR x = 1 TO 25 STEP 1
  63.         FOR y = 1 TO 62 STEP 1
  64.             PRINT area(x, y);
  65.         NEXT y
  66.     NEXT x
  67.  
  68. SUB MoveLight (row AS INTEGER, col AS INTEGER, min AS INTEGER, max AS INTEGER)
  69.     DIM t AS INTEGER, r AS INTEGER, c AS INTEGER
  70.  
  71.     LOCATE row, col
  72.     IF Lamp = 1 THEN
  73.         'rectangular light
  74.         FOR t = 1 TO 3 STEP 1
  75.             c = 9 'flag and color index
  76.             FOR r = min TO max
  77.                 IF (c > 1 AND Lamp = 1) THEN
  78.                     c = c - 1
  79.                 ELSEIF c = 1 THEN
  80.                     Lamp = 99
  81.                 ELSEIF (c > 0 AND c < 9 AND Lamp = 99) THEN
  82.                     c = c + 1
  83.                 END IF
  84.                 COLOR Black, whites(c)
  85.                 LOCATE row + t - 1, col + r - 1
  86.                 PRINT area(row + t - 1, col + r - 1)
  87.             NEXT r
  88.             Lamp = 1
  89.         NEXT t
  90.     ELSEIF Lamp = 2 THEN
  91.         'one square
  92.         COLOR Black, whites(1)
  93.         LOCATE row, col
  94.         PRINT area(row, col)
  95.     ELSEIF Lamp = 3 THEN
  96.         'crux
  97.         LOCATE row, col + 1
  98.         COLOR Black, whites(4)
  99.         PRINT area(row, col + 1); area(row, col + 2)
  100.         LOCATE row + 3, col + 1
  101.         PRINT area(row + 3, col + 1); area(row + 3, col + 2)
  102.         COLOR Black, whites(2)
  103.         LOCATE row + 1, col
  104.         FOR r = 1 TO 2
  105.             FOR t = 1 TO 4
  106.                 LOCATE row + r, col + t - 1
  107.                 PRINT area(row + r, col + t - 1)
  108.             NEXT t
  109.         NEXT r
  110.     END IF
  111.  
  112.  
  113.  
  114. SUB Setup
  115.     DIM counter AS INTEGER, x AS INTEGER
  116.     A = _NEWIMAGE(500, 500, 32)
  117.     IF A THEN SCREEN A ELSE PRINT "Error create SCREEN"
  118.     Black = _RGB(0, 0, 0)
  119.     Black2 = _RGB(0, 0, 50)
  120.     whites(1) = _RGB(255, 255, 255)
  121.     r = 255
  122.     b = 255
  123.     g = 255
  124.     counter = 1
  125.     FOR counter = 2 TO 10
  126.         r = r - INT(255 / 10)
  127.         b = b - INT(255 / 10)
  128.         g = g - INT(255 / 10)
  129.         whites(counter) = _RGB(r, g, b)
  130.     NEXT counter
  131.     FOR y = 1 TO 62 STEP 1
  132.         FOR x = 1 TO 25 STEP 1
  133.             c = MinMax(65, 90)
  134.             area(x, y) = CHR$(c)
  135.         NEXT x
  136.     NEXT y
  137.  
  138. SUB CalculateRows
  139.     LOCATE 1, 1: COLOR _RGB(0, 127, 127)
  140.     FOR x = 1 TO 80 STEP 1
  141.         IF x > -1 THEN PRINT LTRIM$(STR$(x MOD 10));
  142.     NEXT x
  143.     PRINT
  144.     FOR x = 1 TO 30 STEP 1
  145.         IF x > -1 THEN PRINT LTRIM$(STR$(x MOD 10))
  146.     NEXT x
  147.  
  148.     SLEEP
  149.  

Thanks to take a look

LOL:
PS I have loose just an hour fighting with SCREEN function because in a wrong way I was remembering that it has been fixed for 32 graphic mode! And the wiki say the same! Gasp... but further search in this forum brings to me the truth!
So frustated I have made an array of string and I have used it to store screen informations...
Programming isn't difficult, only it's  consuming time and coffee

FellippeHeitor

  • Guest
Re: ASCII torch on a land of dark letters
« Reply #1 on: April 21, 2019, 09:47:06 pm »
Looks good, Tempodi!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ASCII torch on a land of dark letters
« Reply #2 on: April 21, 2019, 10:26:39 pm »
Could use _Display in main loop, but inspired me to give it a try :)
Code: QB64: [Select]
  1. _TITLE "text over search light, move mouse wheel" 'started 2019-04-21 B+
  2.  
  3. CONST xmax = 800
  4. CONST ymax = 600
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. DIM txt(1 TO 37) AS STRING, v(1 TO 37)
  7. FOR i = 1 TO 37
  8.     b$ = ""
  9.     FOR j = 1 TO 100
  10.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  11.     NEXT
  12.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  13. r = 100
  14. COLOR _RGB32(40, 20, 10), _RGBA32(0, 0, 0, 40)
  15. WHILE _KEYDOWN(27) = 0
  16.     CLS
  17.         r = r + _MOUSEWHEEL
  18.     LOOP
  19.     mx = _MOUSEX: my = _MOUSEY
  20.     FOR i = r TO 0 STEP -1
  21.         fcirc mx, my, i, _RGB((r - i) ^ 1.2 / r * 255, (r - i) / r * 255, (r - i) / r * 255)
  22.     NEXT
  23.     FOR i = 1 TO 37
  24.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  25.         LOCATE i, 1: PRINT MID$(txt(i), 1, 100);
  26.     NEXT
  27.     _DISPLAY
  28.     _LIMIT 5
  29.  
  30. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  31.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  32.     DIM X AS INTEGER, Y AS INTEGER
  33.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  34.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  35.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  36.     WHILE X > Y
  37.         RadiusError = RadiusError + Y * 2 + 1
  38.         IF RadiusError >= 0 THEN
  39.             IF X <> Y + 1 THEN
  40.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  41.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  42.             END IF
  43.             X = X - 1
  44.             RadiusError = RadiusError - X * 2
  45.         END IF
  46.         Y = Y + 1
  47.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  48.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  49.     WEND
  50.  
  51.  
« Last Edit: April 21, 2019, 10:31:57 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: ASCII torch on a land of dark letters
« Reply #3 on: April 22, 2019, 09:50:02 am »
Thanks for feedback

Hey Bplus wonderful math underlayer!
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: ASCII torch on a land of dark letters
« Reply #4 on: April 22, 2019, 03:23:13 pm »
Argh, that's just annoying.

DO BETTER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: ASCII torch on a land of dark letters
« Reply #5 on: April 25, 2019, 05:11:34 pm »
@Pete
ok I need to imagine what and to have some time to write code... after I can show you something better!!!

@Bplus
your characters' background let me think to Matrix  :-)
Programming isn't difficult, only it's  consuming time and coffee

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: ASCII torch on a land of dark letters
« Reply #6 on: April 30, 2019, 07:53:24 am »
This approach could make a decent game map highlighter, I'm thinking. You guys are cool.

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: ASCII torch on a land of dark letters
« Reply #7 on: April 30, 2019, 10:24:36 am »
TempodiBasic, I'm following all your torch on letters posts. Very cool effect. I'd use it if I needed it. Well done.
QB64 is the best!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: ASCII torch on a land of dark letters
« Reply #8 on: April 30, 2019, 04:12:36 pm »
Nice work, TempodiBasic.