Author Topic: reduce numbers of: for. next  (Read 4131 times)

0 Members and 1 Guest are viewing this topic.

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
reduce numbers of: for. next
« on: January 01, 2021, 08:33:28 pm »
Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(920, 740, 256)
  3. _DELAY .25
  4.  
  5. 'Moldura...
  6. LINE (0, 0)-(929, 719), 11, B 'Moldura inteira
  7. LINE (1, 1)-(928, 718), 11, B
  8. LINE (2, 2)-(927, 717), 11, B
  9. LINE (3, 3)-(926, 716), 11, B
  10. LINE (4, 4)-(925, 715), 11, B
  11.  
  12. LINE (927, 40)-(2, 40), 11, B 'Linha Horizontal
  13. LINE (927, 41)-(2, 41), 11, B
  14. 'LINE (817, 45)-(2, 45), 11, B
  15.  
  16. 'Mostra Data
  17. d$ = MID$(DATE$, 1, 3)
  18. c$ = MID$(DATE$, 4, 3)
  19. e$ = MID$(DATE$, 7, 4)
  20. f$ = c$ + d$ + e$
  21. COLOR 11: LOCATE 2, 40: PRINT "* * * Repeated dozens  * * *"
  22. LOCATE 2, 4: PRINT f$: COLOR 7
  23. '----------------------------------------------------------------------------
  24.  
  25.  
  26. DIM n(1 TO 3000) AS STRING * 41 ' Is this variable declared correctly?
  27. DIM nt(1 TO 3000) AS STRING * 41 ' Is this variable declared correctly?
  28. DIM total AS _INTEGER64 ' Is this variable declared correctly?
  29. DIM ei AS _INTEGER64 ' Is this variable declared correctly?
  30. DIM v AS _INTEGER64 ' Is this variable declared correctly?
  31. DIM b AS _INTEGER64 ' Is this variable declared correctly?
  32. DIM r AS _INTEGER64 ' Is this variable declared correctly?
  33. DIM t AS _INTEGER64 ' Is this variable declared correctly?
  34.  
  35. 'Is there a need to declare all variables used in Qbasic 64?
  36.  
  37.  
  38. OPEN "complete.txt" FOR INPUT AS #1
  39. total = LOF(1) \ 41
  40. COLOR 15: LOCATE 4, 3: PRINT "Number of records =>"; total: COLOR 7
  41. FOR t = 1 TO total
  42.     LINE INPUT #1, n$(t)
  43.  
  44.  
  45. FOR r = 1 TO total '   Put the number 11 in order
  46.     FOR ei = 1 TO total - 1
  47.         IF VAL(MID$(n$(ei), 14, 3)) > VAL(MID$(n$(ei + 1), 14, 3)) THEN
  48.             SWAP n$(ei), n$(ei + 1)
  49.         END IF
  50.     NEXT ei
  51.  
  52. v = 5
  53. FOR b = total TO total - 38 STEP -1 ' Sort by highest number of times
  54.     v = v + 1
  55.     COLOR 15: LOCATE v, 3: PRINT LEFT$(n$(b), 4); " => ";: COLOR 11: PRINT ; MID$(n$(b), 9, 8);: COLOR 29: PRINT " - Times"
  56.  
  57. FOR r = 1 TO total 'Put the number 12 in order
  58.     FOR ei = 1 TO total - 1
  59.         IF VAL(MID$(n$(ei), 23, 2)) > VAL(MID$(n$(ei + 1), 23, 2)) THEN
  60.             SWAP n$(ei), n$(ei + 1)
  61.         END IF
  62.     NEXT ei
  63.  
  64. v = 5
  65. FOR b = total TO total - 38 STEP -1 'Sort by highest number of times
  66.     v = v + 1
  67.     COLOR 15: LOCATE v, 31: PRINT LEFT$(n$(b), 4); " => ";: COLOR 12: PRINT MID$(n$(b), 18, 7);: COLOR 29: PRINT " - Times"
  68.  
  69. FOR r = 1 TO total 'Put the number 13 in order
  70.     FOR ei = 1 TO total - 1
  71.         IF VAL(MID$(n$(ei), 31, 2)) > VAL(MID$(n$(ei + 1), 31, 2)) THEN
  72.             SWAP n$(ei), n$(ei + 1)
  73.         END IF
  74.     NEXT ei
  75.  
  76. v = 5
  77. FOR b = total TO total - 38 STEP -1 'Sort by highest number of times
  78.     v = v + 1
  79.     COLOR 15: LOCATE v, 58: PRINT LEFT$(n$(b), 4); " => ";: COLOR 13: PRINT MID$(n$(b), 26, 7);: COLOR 29: PRINT " - Times"
  80.  
  81. FOR r = 1 TO total 'Put the number 14 in order
  82.     FOR ei = 1 TO total
  83.         IF VAL(MID$(n$(ei), 39, 2)) > VAL(MID$(n$(ei + 1), 39, 2)) THEN
  84.             SWAP n$(ei), n$(ei + 1)
  85.         END IF
  86.     NEXT ei
  87.  
  88. v = 5
  89. FOR b = total TO total - 38 STEP -1 'Sort by highest number of times
  90.     v = v + 1
  91.     COLOR 15: LOCATE v, 85: PRINT LEFT$(n$(b), 4); " => ";: COLOR 14: PRINT MID$(n$(b), 34, 6);: COLOR 29: PRINT " - Times"

Hi Bplus,
Happy New Year to you and everyone on the forum.

I come again to ask you an idea without sub. To to decrease the number of for ... next of the code that I made.
They are making the code slow. for excess of repeating the same thing.

I want to remind you that this code is similar to another one that you solved .: https://www.qb64.org/forum/index.php?topic=3209.msg124899#msg124899

I don't want association but to leave it faster.

In the file complete.txt, there are 2120 lines. Each line has 4 numbers from 11 to 14.

Each number has a result. This result is the repetition of times of himself.

Here is an example of the complete.txt file.

0001 => 11 = 208 12 = 38 13 = 04 14 = 0
0002 => 11 = 181 12 = 35 13 = 06 14 = 0
0003 => 11 = 178 12 = 41 13 = 02 14 = 0
0004 => 11 = 188 12 = 41 13 = 03 14 = 0

I believe, that this time, it is more explained for a better understanding.

Carlos.
Exemplo.jpg
* Exemplo.jpg (Filesize: 485.21 KB, Dimensions: 1039x1055, Views: 217)
* Colocar todo em ordem.txt (Filesize: 3.21 KB, Downloads: 128)
* complete.txt (Filesize: 84.88 KB, Downloads: 123)
« Last Edit: January 01, 2021, 09:35:04 pm by carloscordeiro »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: reduce numbers of: for. next
« Reply #1 on: January 01, 2021, 10:15:05 pm »
Hi Carlos, happy New Year!

I am still working on a version of TTT that ARB got me wondering about. I'll be back to this tomorrow, maybe really late tonight.

Maybe someone else can work it out before me :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: reduce numbers of: for. next
« Reply #2 on: January 02, 2021, 02:09:08 am »
Quote
I come again to ask you an idea without sub.

Sorry, if you want kick-butt time you need a proper sort routine! Here is that!

Code: QB64: [Select]
  1. _TITLE "carlos Qbasic 64 mod bplus 2021-01-02  Any key to page down the whole table!"
  2. SCREEN _NEWIMAGE(930, 600, 32)
  3. _DELAY .25
  4.  
  5. 'Is there a need to declare all variables used in Qbasic 64?   >>>> don't have to  unless use OPTION _EXPLICT,  but good form!
  6.  
  7. DEFLNG A-Z '   make everything long unless $ for string
  8. TYPE record
  9.     index AS LONG
  10.     value AS LONG
  11. REDIM n11(1 TO 2120) AS record, n12(1 TO 2120) AS record, n13(1 TO 2120) AS record, n14(1 TO 2120) AS record
  12. OPEN "complete.txt" FOR INPUT AS #1
  13. total = LOF(1) \ 41
  14. FOR t = 1 TO 2120
  15.     LINE INPUT #1, fline$
  16.     n11(t).index = t: n11(t).value = VAL(MID$(fline$, 14, 3))
  17.     n12(t).index = t: n12(t).value = VAL(MID$(fline$, 23, 2))
  18.     n13(t).index = t: n13(t).value = VAL(MID$(fline$, 31, 2))
  19.     n14(t).index = t: n14(t).value = VAL(MID$(fline$, 39, 2))
  20. QuickSort 1, 2120, n11()
  21. QuickSort 1, 2120, n12()
  22. QuickSort 1, 2120, n13()
  23. QuickSort 1, 2120, n14()
  24. GOSUB drawFrame
  25. FOR i = 1 TO 2120
  26.     COLOR &HFFCCCCCC
  27.     LOCATE , 3: PRINT RIGHT$(SPC(4) + STR$(i), 4);
  28.     COLOR &HFFAAAAFF
  29.     LOCATE , 15: PRINT "N11: "; RIGHT$(SPC(4) + STR$(n11(i).index), 4); " = "; RIGHT$(SPC(3) + STR$(n11(i).value), 3);
  30.     COLOR &HFFFF0000
  31.     LOCATE , 40
  32.     PRINT "N12: "; RIGHT$(SPC(4) + STR$(n12(i).index), 4); " = "; RIGHT$(SPC(3) + STR$(n12(i).value), 3);
  33.     COLOR &HFFFFFF00
  34.     LOCATE , 65
  35.     PRINT "N13: "; RIGHT$(SPC(4) + STR$(n13(i).index), 4); " = "; RIGHT$(SPC(3) + STR$(n13(i).value), 3);
  36.     COLOR &HFF8800FF
  37.     LOCATE , 90
  38.     PRINT "N14: "; RIGHT$(SPC(4) + STR$(n14(i).index), 4); " = "; RIGHT$(SPC(3) + STR$(n14(i).value), 3)
  39.     IF i MOD 25 = 24 THEN SLEEP: CLS: GOSUB drawFrame
  40.  
  41. drawFrame:
  42. 'Moldura...
  43. LINE (0, 0)-(929, 599), &HFFCCCCCC, B 'Moldura inteira
  44. LINE (1, 1)-(928, 598), &HFFCCCCCC, B
  45. LINE (2, 2)-(927, 597), &HFFCCCCCC, B
  46. LINE (3, 3)-(926, 596), &HFFCCCCCC, B
  47. LINE (4, 4)-(925, 595), &HFFCCCCCC, B
  48.  
  49. LINE (927, 40)-(2, 40), &HFFCCCCCC, B 'Linha Horizontal
  50. LINE (927, 41)-(2, 41), &HFFCCCCCC, B
  51.  
  52. 'Mostra Data
  53. d$ = MID$(DATE$, 1, 3)
  54. c$ = MID$(DATE$, 4, 3)
  55. e$ = MID$(DATE$, 7, 4)
  56. f$ = c$ + d$ + e$
  57. COLOR &HFFCCCCCC: LOCATE 2, 40: PRINT "* * * Repeated dozens  * * *"
  58. LOCATE 2, 4: PRINT f$
  59. LOCATE 4, 3: PRINT "Number of records =>"; total
  60.  
  61. SUB QuickSort (start AS LONG, finish AS LONG, array() AS record)
  62.     DIM Hi AS LONG, Lo AS LONG, Middle AS SINGLE
  63.     Hi = finish: Lo = start
  64.     Middle = array((Lo + Hi) / 2).value 'find middle of array
  65.     DO
  66.         DO WHILE array(Lo).value > Middle: Lo = Lo + 1: LOOP
  67.         DO WHILE array(Hi).value < Middle: Hi = Hi - 1: LOOP
  68.         IF Lo <= Hi THEN
  69.             SWAP array(Lo), array(Hi)
  70.             Lo = Lo + 1: Hi = Hi - 1
  71.         END IF
  72.     LOOP UNTIL Lo > Hi
  73.     IF Hi > start THEN CALL QuickSort(start, Hi, array())
  74.     IF Lo < finish THEN CALL QuickSort(Lo, finish, array())
  75.  
  76.  
  77.  

 
carlos mod of qb64.PNG


EDIT: fixed alignment of numbers
« Last Edit: January 02, 2021, 02:24:38 am by bplus »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: reduce numbers of: for. next
« Reply #3 on: January 02, 2021, 06:20:57 pm »
Hi Bplus
I am very old to work with routines.
I always liked simple code ...
Your code is excellent, very fast compared to mine, full of FOR ... NEXT.
I saw many lines in your classification routine that I can take advantage of in another way, without many FOR.NEXT.
Since I registered in this forum, I have learned and enjoyed many lines of your codes and also Mr. SMcNeill codes, in the first posts.
Again, thanks for replying

Carlos
« Last Edit: January 02, 2021, 07:01:27 pm by carloscordeiro »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: reduce numbers of: for. next
« Reply #4 on: January 06, 2021, 08:44:07 pm »
Hi Bplus
good evening

I was able to create a code without SUB, copying several lines of its routine classification code.

I want to point out that you are very skilled at creating code.
I really like the lines you create.

I put a timer to compare the execution time. I was wondering if my code's time was approaching with yours.

Of course, that was just out of curiosity.

Nowhere has mine come close to yours in terms of execution time.
However, it is much better than the first one I did, full of FOR ... NEXT.

I want to end with a question:
Why did the COLOR statement change the value to hexadecimal?

Carlos
Code: QB64: [Select]
  1. _TITLE "Qbasic 64  Version Version without SUB, copied several lines of the Bplus friend code."
  2. SCREEN _NEWIMAGE(930, 600, 32)
  3. _DELAY .25
  4. REDIM n11(0 TO 1, 1 TO 2120)
  5. REDIM n12(0 TO 1, 1 TO 2120)
  6. REDIM n13(0 TO 1, 1 TO 2120)
  7. REDIM n14(0 TO 1, 1 TO 2120)
  8.  
  9. td# = TIMER(.001)
  10. PRINT td#
  11.  
  12. OPEN "complete.txt" FOR INPUT AS #1
  13. total = LOF(1) \ 41
  14. FOR t = 1 TO 2120
  15.     LINE INPUT #1, fline$
  16.     n11(0, t) = t: n11(1, t) = VAL(MID$(fline$, 14, 3))
  17.     n12(0, t) = t: n12(1, t) = VAL(MID$(fline$, 23, 2))
  18.     n13(0, t) = t: n13(1, t) = VAL(MID$(fline$, 31, 2))
  19.     n14(0, t) = t: n14(1, t) = VAL(MID$(fline$, 39, 2))
  20.  
  21. GOSUB drawFrame
  22.  
  23. FOR i = 1 TO 2119
  24.     FOR j = i + 1 TO 2120
  25.         IF n11(1, i) < n11(1, j) THEN
  26.             SWAP n11(0, j), n11(0, i)
  27.             SWAP n11(1, j), n11(1, i)
  28.         END IF
  29.         IF n12(1, i) < n12(1, j) THEN
  30.             SWAP n12(0, j), n12(0, i)
  31.             SWAP n12(1, j), n12(1, i)
  32.         END IF
  33.         IF n13(1, i) < n13(1, j) THEN
  34.             SWAP n13(0, j), n13(0, i)
  35.             SWAP n13(1, j), n13(1, i)
  36.         END IF
  37.         IF n14(1, i) < n14(1, j) THEN
  38.             SWAP n14(0, j), n14(0, i)
  39.             SWAP n14(1, j), n14(1, i)
  40.         END IF
  41.     NEXT
  42.  
  43. FOR i = 1 TO 2120
  44.     COLOR &HFFCCCCCC
  45.     LOCATE , 3: PRINT RIGHT$(SPC(3) + STR$(i), 4);
  46.     COLOR &HFFAAAAFF
  47.     LOCATE , 15: PRINT "N11: "; RIGHT$("0000" + LTRIM$(STR$(n11(0, i))), 4); " ="; n11(1, i);
  48.     COLOR &HFFFF0000
  49.     LOCATE , 40
  50.     PRINT "N12: "; RIGHT$("0000" + LTRIM$(STR$(n12(0, i))), 4); " ="; n12(1, i);
  51.     COLOR &HFFFFFF00
  52.     LOCATE , 65
  53.     PRINT "N13: "; RIGHT$("0000" + LTRIM$(STR$(n11(0, i))), 4); " ="; n13(1, i);
  54.     COLOR &HFF8800FF
  55.     LOCATE , 90
  56.     PRINT "N14: "; RIGHT$("0000" + LTRIM$(STR$(n11(0, i))), 4); " ="; n14(1, i)
  57.     'IF i MOD 25 = 24 THEN td# = TIMER(.001): PRINT td#: SLEEP: GOSUB drawFrame
  58.  
  59. drawFrame:
  60. 'Moldura...
  61. LINE (0, 0)-(929, 599), &HFFCCCCCC, B 'Moldura inteira
  62. LINE (1, 1)-(928, 598), &HFFCCCCCC, B
  63. LINE (2, 2)-(927, 597), &HFFCCCCCC, B
  64. LINE (3, 3)-(926, 596), &HFFCCCCCC, B
  65. LINE (4, 4)-(925, 595), &HFFCCCCCC, B
  66.  
  67. LINE (927, 40)-(2, 40), &HFFCCCCCC, B 'Linha Horizontal
  68. LINE (927, 41)-(2, 41), &HFFCCCCCC, B
  69.  
  70. 'Mostra Data
  71. 'd$ = MID$(DATE$, 1, 3)
  72. 'c$ = MID$(DATE$, 4, 3)
  73. 'e$ = MID$(DATE$, 7, 4)
  74. 'f$ = c$ + d$ + e$
  75. COLOR &HFFCCCCCC: LOCATE 2, 40: PRINT "* * * Repeated dozens  * * *"
  76. LOCATE 2, 4: PRINT f$
  77. LOCATE 4, 3: PRINT "Number of records =>"; total
  78.  
  79. ]
runtime Bplus.jpg
* runtime Bplus.jpg (Filesize: 230.82 KB, Dimensions: 981x829, Views: 166)
runtime Carlos.jpg
* runtime Carlos.jpg (Filesize: 251.19 KB, Dimensions: 959x845, Views: 136)
* complete.txt (Filesize: 84.88 KB, Downloads: 84)
* coloca em ordem V2.txt (Filesize: 2.53 KB, Downloads: 98)
« Last Edit: January 08, 2021, 05:02:35 pm by carloscordeiro »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: reduce numbers of: for. next
« Reply #5 on: January 06, 2021, 09:26:42 pm »
Quote
Why did the COLOR statement change the value to hexadecimal?

Hi @carloscordeiro,

I changed the colors.

SCREEN _NEWIMAGE(930, 600, 32)  '<<<< the 32 here allows me to use the full blown range of color QB64 is capable of giving us 255 * 255 * 255 colors at 255 transparency levels.

&H FF FF FF FF 'white at full opaque or solid color, no see through

the first set of FF is transparency or lack of 0 is transparent 255 or hex FF is solid
2nd set of FF's are red 0 to 255, or 00 to FF in hex
3rd set of FF's are green 0 to 255 or 00 to FF in hex
4th set of FF's are blue 0 to 255 or 00 toFF in hex

&HFFFFFFFF (white) = _RGB32(255, 255, 255, 255) 

&HFFFFFF00 (yellow  = full red + full green) = _RGB32(255, 255, 0) ' without 4th transparent = 255 default

&HFF0000FF (blue) = _RGB32(0, 0, 255)

half transparent blue &H880000FF or _RGB32(0, 0, 255, 128)

notice alpha = transparent level is on left in the hex number but last on right 4th place in _RGB32(red, green, blue, alpha ) number.

« Last Edit: January 06, 2021, 09:29:00 pm by bplus »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: reduce numbers of: for. next
« Reply #6 on: January 07, 2021, 07:31:48 am »
Bplus, would it be like this image? Or have more colors in HEX?

You may have already noticed that I love colors. :)
Color.jpg
* Color.jpg (Filesize: 129.12 KB, Dimensions: 861x667, Views: 160)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: reduce numbers of: for. next
« Reply #7 on: January 07, 2021, 10:15:36 am »
Bplus, would it be like this image? Or have more colors in HEX?

You may have already noticed that I love colors. :)

Yeah, colors are saver for me for Winters in N. Ohio, USA, we have clouds and occasional snow move in November and do not really leave until April.

Both Hex color method or _RGB32 have 255 * 255 * 255 color mixes = 16,581,375 plus 255 levels of transparencies.

Hex is just a quicker way to input color for me and might be slightly faster compiling as they are constant literals, maybe you'd like _RGB32() better because the numbers are base 10 instead of base 16.

Just waves of color, press spacebar for different patterns.
Code: QB64: [Select]
  1. _TITLE "Wavy with Plama:  Press Spacebar for New Plasma Injection."
  2. ' for QB64 fork (B+=MGA) 2017-05-05
  3. ' Wavy with Plasma Treatment.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-03
  4. ' from: animated circles started by Admin at SdlBasic 2017-05-03
  5. ' I added Plasma treatment and spacebar  changer
  6.  
  7. ' 2018-08-04 updated with better circle fill
  8.  
  9. '===================================================================
  10.  
  11. ' Instructions: press spacebar for new injection of plasma
  12.  
  13. '==================================================================
  14.  
  15.  
  16. CONST xmax = 1100
  17. CONST ymax = 700
  18. CONST DPI = 3.141516 * 2
  19. CONST PHIDELTA = DPI / 15
  20. CONST PHISTEP = DPI / 50
  21. CONST RADIUS = 20
  22. CONST SMALL_R = 20
  23. CONST DISTANCE = 23
  24. CONST W = xmax
  25. CONST H = ymax
  26.  
  27. SCREEN _NEWIMAGE(xmax, ymax, 32)
  28. _SCREENMOVE (1280 - xmax) / 2 + 30, (760 - ymax) / 2
  29. DIM SHARED pR, pG, pB AS INTEGER
  30. DIM x, y, xball, yball AS INTEGER
  31. DIM current_phi, phiIndex, phi AS DOUBLE
  32. current_phi = 0
  33. cN = 1
  34. resetPlasma
  35.     CLS
  36.     _LIMIT 10
  37.     IF _KEYHIT = 32 THEN cN = 1: resetPlasma
  38.     current_phi = current_phi + PHISTEP
  39.     FOR x = 0 TO (W + RADIUS) STEP DISTANCE
  40.         FOR y = 0 TO (H + RADIUS) STEP DISTANCE
  41.             phiIndex = ((x + y) MOD (2 * W)) / RADIUS
  42.             phi = phiIndex * PHIDELTA + current_phi
  43.             xball = COS(phi) * RADIUS + x
  44.             yball = SIN(phi) * RADIUS + y
  45.             changePlasma
  46.             fcirc xball, yball, SMALL_R
  47.         NEXT
  48.     NEXT
  49.     _DISPLAY
  50.  
  51. SUB changePlasma ()
  52.     cN = cN + 1
  53.     COLOR _RGB(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
  54.  
  55. SUB resetPlasma ()
  56.     pR = RND: pG = RND: pB = RND
  57.  
  58. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  59. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  60.     DIM subRadius AS LONG, RadiusError AS LONG
  61.     DIM X AS LONG, Y AS LONG
  62.  
  63.     subRadius = ABS(R)
  64.     RadiusError = -subRadius
  65.     X = subRadius
  66.     Y = 0
  67.  
  68.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  69.  
  70.     ' Draw the middle span here so we don't draw it twice in the main loop,
  71.     ' which would be a problem with blending turned on.
  72.     LINE (CX - X, CY)-(CX + X, CY), , BF
  73.  
  74.     WHILE X > Y
  75.         RadiusError = RadiusError + Y * 2 + 1
  76.         IF RadiusError >= 0 THEN
  77.             IF X <> Y + 1 THEN
  78.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  79.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  80.             END IF
  81.             X = X - 1
  82.             RadiusError = RadiusError - X * 2
  83.         END IF
  84.         Y = Y + 1
  85.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  86.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  87.     WEND
  88.  

Ohpe! here is another, better not get me going on color, hahahah! This is simple demo of what I call plasma.
Code: QB64: [Select]
  1. _TITLE "Scrolling Plasma Lines, press spacebar for new colors" 'B+ 2019-10-09
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. DIM ln(0 TO ymax) AS _UNSIGNED LONG
  6. r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  7.     IF INKEY$ = " " THEN r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  8.     FOR i = UBOUND(ln) - 1 TO 0 STEP -1
  9.         ln(i + 1) = ln(i)
  10.         LINE (0, i)-STEP(xmax, 1), ln(i + 1), BF
  11.     NEXT
  12.     ln(0) = _RGB32(127 + 127 * SIN(r * c), 127 + 127 * SIN(g * c), 127 + 127 * SIN(b * c))
  13.     c = c + 1
  14.     _DISPLAY
  15.     _LIMIT 60
  16.  
« Last Edit: January 07, 2021, 11:40:54 am by bplus »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: reduce numbers of: for. next
« Reply #8 on: January 07, 2021, 06:18:11 pm »
Bplus, I couldn't find the numerals of each value corresponding to the colors in your two examples.

Would this be the way to know all the corresponding numbers of each _RGB32 () color values? Or do you have a better idea for showing all color values?
Carlos
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(820, 700, 32)
  2.  
  3. FOR i = 1 TO 255
  4.     COLOR _RGB32(i, 255, 255)
  5.     PRINT "Carlos"; i;
  6.  
  7.     COLOR _RGB32(255, i, 255)
  8.     PRINT "Carlos"; i;
  9.  
  10.     COLOR _RGB32(255, 255, i)
  11.     PRINT "Carlos"; i;
  12.  
  13.     COLOR _RGB32(i, i, 255)
  14.     PRINT "Carlos"; i;
  15.  
  16.     COLOR _RGB32(i, 255, i)
  17.     PRINT "Carlos"; i;
  18.  
  19.     COLOR _RGB32(255, i, i)
  20.     PRINT "Carlos"; i;
  21.  
  22.     _DELAY .1
  23.  
  24. ]
All colors.jpg
* All colors.jpg (Filesize: 606.46 KB, Dimensions: 927x1001, Views: 143)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: reduce numbers of: for. next
« Reply #9 on: January 07, 2021, 07:34:41 pm »
Ha! That's inspiring! ;-))

Here is the complete list:
Code: QB64: [Select]
  1. _TITLE "ALL the colors, got a minute? hahaha!"
  2. SCREEN _NEWIMAGE(800, 700, 32)
  3. _DELAY .25
  4. x$ = SPC(80)
  5. FOR r = 0 TO 255
  6.     FOR g = 0 TO 255
  7.         FOR b = 0 TO 255
  8.             COLOR _RGB32(r, g, b)
  9.             i = i + 1
  10.             MID$(x$, 1, 80) = "This is color " + TS$(i) + ", _RGB32(" + TS$(r) + ", " + TS$(g) + ", " + TS$(b) + ")"
  11.             PRINT x$
  12.             _LIMIT 60
  13.         NEXT
  14.     NEXT
  15.  
  16. FUNCTION TS$ (n AS LONG)
  17.     TS$ = _TRIM$(STR$(n))
  18.  
  19.  

1000 times faster, all the colors /1000
Code: QB64: [Select]
  1. _TITLE "ALL the colors / 1000, got a minute? hahaha!"
  2. SCREEN _NEWIMAGE(800, 700, 32)
  3. _DELAY .25
  4. x$ = SPC(80)
  5. FOR r = 0 TO 255 STEP 10
  6.     FOR g = 0 TO 255 STEP 10
  7.         FOR b = 0 TO 255 STEP 10
  8.             COLOR _RGB32(r, g, b)
  9.             i = i + 1
  10.             MID$(x$, 1, 80) = "This is color " + TS$(i) + ", _RGB32(" + TS$(r) + ", " + TS$(g) + ", " + TS$(b) + ")"
  11.             PRINT x$
  12.             _LIMIT 60
  13.         NEXT
  14.     NEXT
  15.  
  16. FUNCTION TS$ (n AS LONG)
  17.     TS$ = _TRIM$(STR$(n))
  18.  
  19.  
« Last Edit: January 07, 2021, 07:42:52 pm by bplus »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: reduce numbers of: for. next
« Reply #10 on: January 07, 2021, 08:32:06 pm »
Okay, Bplus,
You have made a simple routine that I can use in the future. I thought that routines would be just complex. I see it can be done without advanced lines as you are used to doing them.

thank you very much

Carlos