Author Topic: gl shaders in text mode...  (Read 6066 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #15 on: April 29, 2019, 02:01:34 am »
Fasters, with black characters. See row 106.

Code: QB64: [Select]
  1. 'upgrade for real text mod
  2.  
  3. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  4. 'continued by B+ with normal letter size :-))
  5.  
  6. CONST xmax = 800
  7. CONST ymax = 600
  8.  
  9. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  10. FOR i = 1 TO 25
  11.     b$ = ""
  12.     FOR j = 1 TO 100
  13.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  14.     NEXT
  15.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  16.  
  17.  
  18. balls = 20
  19. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  20. FOR i = 1 TO balls
  21.     r(i) = rand(10, 65)
  22.     x(i) = rand(r(i), xmax - r(i))
  23.     y(i) = rand(r(i), ymax - r(i))
  24.     c(i) = rand(1, 15)
  25.     dx(i) = rand(1, 5) * rdir
  26.     dy(i) = rand(1, 5) * rdir
  27.     rr(i) = rand(50, 255)
  28.     gg(i) = rand(50, 255)
  29.     bb(i) = rand(50, 255)
  30.  
  31.  
  32.  
  33. WHILE _KEYDOWN(27) = 0
  34.     Bplus = _NEWIMAGE(xmax, ymax, 32)
  35.     _DEST Bplus
  36.  
  37.  
  38.  
  39.     ' CLS , _RGB32(0, 0, 0)
  40.     FOR i = 1 TO balls
  41.         'ready for collision
  42.         a(i) = _ATAN2(dy(i), dx(i))
  43.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  44.         imoved = 0
  45.         FOR j = i + 1 TO balls
  46.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  47.                 imoved = 1
  48.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  49.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  50.                 'update new dx, dy for i and j balls
  51.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  52.                 power = (power1 + power2) / 2
  53.                 dx(i) = power * COS(a(i))
  54.                 dy(i) = power * SIN(a(i))
  55.                 dx(j) = power * COS(a(j))
  56.                 dy(j) = power * SIN(a(j))
  57.                 x(i) = x(i) + dx(i)
  58.                 y(i) = y(i) + dy(i)
  59.                 x(j) = x(j) + dx(j)
  60.                 y(j) = y(j) + dy(j)
  61.                 EXIT FOR
  62.             END IF
  63.         NEXT
  64.         IF imoved = 0 THEN
  65.             x(i) = x(i) + dx(i)
  66.             y(i) = y(i) + dy(i)
  67.         END IF
  68.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  69.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  70.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  71.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  72.  
  73.  
  74.         FOR rad = r(i) TO 0 STEP -1
  75.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 12)
  76.         NEXT
  77.     NEXT
  78.  
  79.     _SETALPHA 255, _RGBA32(0, 0, 0, 0), Bplus 'much better solution as previous FOR... NEXT loop
  80.  
  81.  
  82.     _SOURCE 0
  83.     _DEST 0 'redirecting to text screen
  84.  
  85.  
  86.     _DEST 0
  87.     Himage = _COPYIMAGE(Bplus, 33)
  88.     _PUTIMAGE (0, 0)-(800, 600), Himage, 0
  89.     Xtranslate = _WIDTH(Bplus) / 8
  90.     Ytranslate = _HEIGHT(Bplus) / 16
  91.  
  92.     FOR i = 1 TO 25
  93.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  94.         FOR l = 1 TO 80
  95.             gX = (Xtranslate + i) * 8
  96.             gY = (-Ytranslate + l) * 16
  97.  
  98.             _SOURCE Bplus
  99.             _DEST 0
  100.             Kolor~& = POINT(gX, gY)
  101.             COLOR 0, 0
  102.             IF Kolor~& <> _RGB32(0, 0, 0) THEN COLOR 0, _RGB(_RED32(Kolor~&), _GREEN32(Kolor~&), _BLUE32(Kolor~&)) 'RGB background for text screen
  103.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  104.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  105.  
  106.         NEXT
  107.     NEXT
  108.  
  109.     _DISPLAY
  110.     _LIMIT 20
  111.     _FREEIMAGE Himage
  112.     _FREEIMAGE Bplus
  113.  
  114. FUNCTION rand (lo, hi)
  115.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  116.  
  117. FUNCTION rdir ()
  118.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  119.  
  120. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  121.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  122.     DIM X AS INTEGER, Y AS INTEGER
  123.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  124.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  125.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  126.     WHILE X > Y
  127.         RadiusError = RadiusError + Y * 2 + 1
  128.         IF RadiusError >= 0 THEN
  129.             IF X <> Y + 1 THEN
  130.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  131.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  132.             END IF
  133.             X = X - 1
  134.             RadiusError = RadiusError - X * 2
  135.         END IF
  136.         Y = Y + 1
  137.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  138.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  139.     WEND
  140.  
  141. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  142.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  143.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #16 on: April 29, 2019, 02:49:57 am »
Or this...

Code: QB64: [Select]
  1. 'upgrade for real text mod
  2.  
  3. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  4. 'continued by B+ with normal letter size :-))
  5.  
  6. CONST xmax = 800
  7. CONST ymax = 600
  8.  
  9. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  10. FOR i = 1 TO 25
  11.     b$ = ""
  12.     FOR j = 1 TO 100
  13.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  14.     NEXT
  15.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  16.  
  17.  
  18. balls = 20
  19. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  20. FOR i = 1 TO balls
  21.     r(i) = rand(10, 65)
  22.     x(i) = rand(r(i), xmax - r(i))
  23.     y(i) = rand(r(i), ymax - r(i))
  24.     c(i) = rand(1, 15)
  25.     dx(i) = rand(1, 5) * rdir
  26.     dy(i) = rand(1, 5) * rdir
  27.     rr(i) = rand(50, 255)
  28.     gg(i) = rand(50, 255)
  29.     bb(i) = rand(50, 255)
  30.  
  31.  
  32.  
  33. WHILE _KEYDOWN(27) = 0
  34.     Bplus = _NEWIMAGE(xmax, ymax, 32)
  35.     _DEST Bplus
  36.  
  37.  
  38.  
  39.     ' CLS , _RGB32(0, 0, 0)
  40.     FOR i = 1 TO balls
  41.         'ready for collision
  42.         a(i) = _ATAN2(dy(i), dx(i))
  43.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  44.         imoved = 0
  45.         FOR j = i + 1 TO balls
  46.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  47.                 imoved = 1
  48.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  49.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  50.                 'update new dx, dy for i and j balls
  51.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  52.                 power = (power1 + power2) / 2
  53.                 dx(i) = power * COS(a(i))
  54.                 dy(i) = power * SIN(a(i))
  55.                 dx(j) = power * COS(a(j))
  56.                 dy(j) = power * SIN(a(j))
  57.                 x(i) = x(i) + dx(i)
  58.                 y(i) = y(i) + dy(i)
  59.                 x(j) = x(j) + dx(j)
  60.                 y(j) = y(j) + dy(j)
  61.                 EXIT FOR
  62.             END IF
  63.         NEXT
  64.         IF imoved = 0 THEN
  65.             x(i) = x(i) + dx(i)
  66.             y(i) = y(i) + dy(i)
  67.         END IF
  68.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  69.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  70.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  71.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  72.  
  73.  
  74.         FOR rad = r(i) TO 0 STEP -1
  75.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 12)
  76.         NEXT
  77.     NEXT
  78.  
  79.     _SETALPHA 155, _RGBA32(0, 0, 0, 0), Bplus 'much better solution as previous FOR... NEXT loop
  80.  
  81.  
  82.     _SOURCE 0
  83.     _DEST 0 'redirecting to text screen
  84.  
  85.  
  86.     _DEST 0
  87.     Himage = _COPYIMAGE(Bplus, 33)
  88.     _PUTIMAGE (0, 0)-(800, 600), Himage, 0
  89.     Xtranslate = (_WIDTH(Bplus) / 80) / 8
  90.     Ytranslate = (_HEIGHT(Bplus) / 25) / 16
  91.  
  92.  
  93.     FOR B = 1 TO balls
  94.         RadiusX = r(B) / 2 / 8
  95.         RadiusY = r(B) / 2 / 16
  96.         FOR i = 1 TO 25
  97.             txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  98.             FOR l = 1 TO 80
  99.  
  100.  
  101.                 gX = (Xtranslate + l - RadiusX + 1) * 8
  102.                 gY = (Ytranslate + i - RadiusY) * 16
  103.  
  104.                 _SOURCE Bplus
  105.                 _DEST 0
  106.                 COLOR 0
  107.                 FOR fy = gY TO gY + 16
  108.                     FOR fx = gX TO gX + 8
  109.                         Kolor~& = POINT(gX, gY)
  110.                         IF _ALPHA32(Kolor~&) < 255 THEN COLOR 0, _RGB(_RED32(Kolor~&), _GREEN32(Kolor~&), _BLUE32(Kolor~&)): GOTO ENDFOR 'RGB background for text screen
  111.                     NEXT
  112.                 NEXT
  113.                 ENDFOR:
  114.                 LOCATE i, l: PRINT MID$(txt(i), l, 1);
  115.                 LOCATE i, l: PRINT MID$(txt(i), l, 1);
  116.             NEXT
  117.         NEXT
  118.     NEXT
  119.     _DISPLAY
  120.     _LIMIT 20
  121.     _FREEIMAGE Himage
  122.     _FREEIMAGE Bplus
  123.  
  124. FUNCTION rand (lo, hi)
  125.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  126.  
  127. FUNCTION rdir ()
  128.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  129.  
  130. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  131.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  132.     DIM X AS INTEGER, Y AS INTEGER
  133.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  134.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  135.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  136.     WHILE X > Y
  137.         RadiusError = RadiusError + Y * 2 + 1
  138.         IF RadiusError >= 0 THEN
  139.             IF X <> Y + 1 THEN
  140.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  141.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  142.             END IF
  143.             X = X - 1
  144.             RadiusError = RadiusError - X * 2
  145.         END IF
  146.         Y = Y + 1
  147.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  148.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  149.     WEND
  150.  
  151. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  152.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  153.  

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: gl shaders in text mode...
« Reply #17 on: April 29, 2019, 05:55:08 am »
This is all great stuff.... thanks guys... :)   AWESOME many thanks.....
« Last Edit: April 29, 2019, 06:02:59 am by PMACKAY »
MackyWhite

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #18 on: April 29, 2019, 10:54:53 am »
Here is odd variation that keeps colors but only in the letters!
Code: QB64: [Select]
  1. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  2. 'continued by B+ with normal letter size :-))
  3. ' 2019-04-29 another variation
  4.  
  5. 'this really text mode??? ;-))
  6.  
  7. CONST xmax = 640
  8. CONST ymax = 400
  9.  
  10. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  11. FOR i = 1 TO 25
  12.     b$ = ""
  13.     FOR j = 1 TO 100
  14.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  15.     NEXT
  16.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  17. balls = 20
  18. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  19. FOR i = 1 TO balls
  20.     r(i) = rand(10, 65)
  21.     x(i) = rand(r(i), xmax - r(i))
  22.     y(i) = rand(r(i), ymax - r(i))
  23.     c(i) = rand(1, 15)
  24.     dx(i) = rand(1, 5) * rdir
  25.     dy(i) = rand(1, 5) * rdir
  26.     rr(i) = rand(50, 255)
  27.     gg(i) = rand(50, 255)
  28.     bb(i) = rand(50, 255)
  29. Bplus = _NEWIMAGE(xmax, ymax, 32)
  30. WHILE _KEYDOWN(27) = 0
  31.     _DEST Bplus
  32.     CLS
  33.     FOR i = 1 TO balls
  34.         'ready for collision
  35.         a(i) = _ATAN2(dy(i), dx(i))
  36.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  37.         imoved = 0
  38.         FOR j = i + 1 TO balls
  39.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) - 20 THEN
  40.                 imoved = 1
  41.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  42.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  43.                 'update new dx, dy for i and j balls
  44.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  45.                 power = (power1 + power2) / 2
  46.                 dx(i) = power * COS(a(i))
  47.                 dy(i) = power * SIN(a(i))
  48.                 dx(j) = power * COS(a(j))
  49.                 dy(j) = power * SIN(a(j))
  50.                 x(i) = x(i) + dx(i)
  51.                 y(i) = y(i) + dy(i)
  52.                 x(j) = x(j) + dx(j)
  53.                 y(j) = y(j) + dy(j)
  54.                 EXIT FOR
  55.             END IF
  56.         NEXT
  57.         IF imoved = 0 THEN
  58.             x(i) = x(i) + dx(i)
  59.             y(i) = y(i) + dy(i)
  60.         END IF
  61.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  62.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  63.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  64.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  65.         FOR rad = r(i) TO 0 STEP -1
  66.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 10)
  67.         NEXT
  68.     NEXT
  69.  
  70.     COLOR 0 '<<< doesn't matter what color but need something?
  71.     FOR i = 1 TO 25
  72.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  73.         LOCATE i, 1: PRINT MID$(txt(i), 1, 80);
  74.     NEXT
  75.  
  76.     _DEST 0 'redirecting to text screen
  77.  
  78.     Himage = _COPYIMAGE(Bplus, 33)
  79.     _PUTIMAGE (0, 0)-(xmax, ymax), Himage, 0
  80.     _DISPLAY
  81.     _LIMIT 15
  82.     _FREEIMAGE Himage
  83.  
  84. FUNCTION rand (lo, hi)
  85.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  86.  
  87. FUNCTION rdir ()
  88.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  89.  
  90. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  91.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  92.     DIM X AS INTEGER, Y AS INTEGER
  93.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  94.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  95.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  96.     WHILE X > Y
  97.         RadiusError = RadiusError + Y * 2 + 1
  98.         IF RadiusError >= 0 THEN
  99.             IF X <> Y + 1 THEN
  100.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  101.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  102.             END IF
  103.             X = X - 1
  104.             RadiusError = RadiusError - X * 2
  105.         END IF
  106.         Y = Y + 1
  107.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  108.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  109.     WEND
  110.  
  111.  
 [ You are not allowed to view this attachment ]  
« Last Edit: April 29, 2019, 10:56:23 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #19 on: April 29, 2019, 01:04:08 pm »
Hi Bplus (Sphere King),

It looks nice, but the text is printed on the graphics screen and uses 32-bit color. To your question on line 73 about color: Because you have a black font on a black background inside a 32-bit image, the font is not visible. Since the COLOR 0 in 32-bit mode returns the same as _RGBA32 (0,0,0,0), then the font is transparent (this cannot be achieved if you put the text on SCREEN 0) and the sphere changes his background color, so then is visible.

It's definitely very nice.
« Last Edit: April 29, 2019, 01:12:02 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #20 on: April 29, 2019, 03:21:53 pm »
OHHH! The font is transparent. Yeah because in 32 bit... Same if I have COLOR 9 almost transparent... that's why it didn't make a difference but why I did need COLOR something (very low), forgot I was in 32 bit mode, got it. Thanks Petr
« Last Edit: April 29, 2019, 03:22:58 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #21 on: April 29, 2019, 03:31:09 pm »
OK now it is same as graphics mode (I think):
Code: QB64: [Select]
  1. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  2. 'continued by B+ with normal letter size :-))
  3. ' 2019-04-29 another variation
  4. ' 2019-04-29 now same as graphics mode!!! Thanks Petr!!!
  5.  
  6.  
  7. 'this really text mode??? ;-))
  8.  
  9. CONST xmax = 640
  10. CONST ymax = 400
  11.  
  12. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  13. FOR i = 1 TO 25
  14.     b$ = ""
  15.     FOR j = 1 TO 100
  16.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  17.     NEXT
  18.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  19. balls = 15
  20. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  21. FOR i = 1 TO balls
  22.     r(i) = rand(10, 65)
  23.     x(i) = rand(r(i), xmax - r(i))
  24.     y(i) = rand(r(i), ymax - r(i))
  25.     c(i) = rand(1, 15)
  26.     dx(i) = rand(1, 5) * rdir
  27.     dy(i) = rand(1, 5) * rdir
  28.     rr(i) = rand(150, 255)
  29.     gg(i) = rand(150, 255)
  30.     bb(i) = rand(150, 255)
  31. Bplus = _NEWIMAGE(xmax, ymax, 32)
  32. WHILE _KEYDOWN(27) = 0
  33.     _DEST Bplus
  34.     CLS
  35.     FOR i = 1 TO balls
  36.         'ready for collision
  37.         a(i) = _ATAN2(dy(i), dx(i))
  38.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  39.         imoved = 0
  40.         FOR j = i + 1 TO balls
  41.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  42.                 imoved = 1
  43.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  44.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  45.                 'update new dx, dy for i and j balls
  46.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  47.                 power = (power1 + power2) / 2
  48.                 dx(i) = power * COS(a(i))
  49.                 dy(i) = power * SIN(a(i))
  50.                 dx(j) = power * COS(a(j))
  51.                 dy(j) = power * SIN(a(j))
  52.                 x(i) = x(i) + dx(i)
  53.                 y(i) = y(i) + dy(i)
  54.                 x(j) = x(j) + dx(j)
  55.                 y(j) = y(j) + dy(j)
  56.                 EXIT FOR
  57.             END IF
  58.         NEXT
  59.         IF imoved = 0 THEN
  60.             x(i) = x(i) + dx(i)
  61.             y(i) = y(i) + dy(i)
  62.         END IF
  63.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  64.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  65.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  66.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  67.         FOR rad = r(i) TO 0 STEP -1
  68.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 20)
  69.         NEXT
  70.     NEXT
  71.  
  72.     COLOR , _RGBA(0, 0, 0, 0)
  73.     FOR i = 1 TO 25
  74.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  75.         FOR l = 1 TO 80
  76.             IF i MOD 2 THEN midInk 60, 0, 0, 0, 0, 60, l / 80 ELSE midInk 0, 0, 60, 60, 0, 0, l / 80
  77.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  78.         NEXT
  79.     NEXT
  80.  
  81.     _DEST 0 'redirecting to text screen
  82.  
  83.     Himage = _COPYIMAGE(Bplus, 33)
  84.     _PUTIMAGE (0, 0)-(xmax, ymax), Himage, 0
  85.     _DISPLAY
  86.     _LIMIT 10
  87.     _FREEIMAGE Himage
  88.  
  89. FUNCTION rand (lo, hi)
  90.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  91.  
  92. FUNCTION rdir ()
  93.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  94.  
  95. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  96.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  97.     DIM X AS INTEGER, Y AS INTEGER
  98.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  99.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  100.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  101.     WHILE X > Y
  102.         RadiusError = RadiusError + Y * 2 + 1
  103.         IF RadiusError >= 0 THEN
  104.             IF X <> Y + 1 THEN
  105.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  106.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  107.             END IF
  108.             X = X - 1
  109.             RadiusError = RadiusError - X * 2
  110.         END IF
  111.         Y = Y + 1
  112.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  113.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  114.     WEND
  115.  
  116. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  117.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  118.  
  119.  

EDIT: added the midInk effect with barely seen letters

 
« Last Edit: April 29, 2019, 04:03:56 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #22 on: April 30, 2019, 04:04:35 pm »
Hi. This is again 32bit mode, copyed to SCREEN 0 as background image when done :-D (none _DEST to text screen before print with LOCATE.) MidInk is maybe possible using also on text screen, but not with _RGB32, but _RGB. :-D

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: gl shaders in text mode...
« Reply #23 on: May 03, 2019, 01:34:49 am »
My fav bplus is « Last Edit: April 29, 2019, 10:56:23 AM »


Awesome stuff (love the way it looks)
MackyWhite