Author Topic: Guts translation from past  (Read 4473 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Guts translation from past
« on: April 05, 2019, 10:25:06 am »
_vince
Quote
Bplus, can you repost the tapeworm example?  I think I saw it on [banned user]'s forum or maybe it was on the justbasic forum.

Sure let's have another look at this classic! (probably was at both forums)
Code: QB64: [Select]
  1. _TITLE "Guts" 'passed down through ages, I first encountered it through Richard Russel author BBC 4 Windows
  2. ' 2019-04-05 B+ translation to QB64 from: Guts.bas SmallBASIC 0.12.0 2015-11-17 MGA/B+
  3. 'modified  > GUTS  Original ARM BBC BASIC version by Jan Vibe, 800x600 ?
  4.  
  5. CONST xmax = 800
  6. CONST ymax = 600
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8.  
  9. DIM bX(15), bY(15), bZ(15), COLR(15) AS _UNSIGNED LONG
  10. bX(1) = -100: A = 0
  11. FOR N = 1 TO 15
  12.     COLR(16 - N) = _RGB32(7 * N + 150, 14 * N + 45, 14 * N + 45)
  13.  
  14. X1 = RND * xmax: Y1 = RND * ymax: DX1 = (RND * 16 + 1) * (RND - .5): DY1 = (RND * 16 + 1) * (RND - .5)
  15. X2 = RND * xmax: Y2 = RND * ymax: DX2 = (RND * 16 + 1) * (RND - .5): DY2 = (RND * 16 + 1) * (RND - .5)
  16.     H = X1 + DX1: IF H < 0 OR H > xmax THEN DX1 = (RND * 16 + 1) * -SGN(DX1)
  17.     H = Y1 + DY1: IF H < 0 OR H > ymax THEN DY1 = (RND * 16 + 1) * -SGN(DY1)
  18.     X1 = X1 + DX1: Y1 = Y1 + DY1
  19.     IF X2 < X1 AND DX2 < 24 THEN DX2 = DX2 + 1
  20.     IF X2 > X1 AND DX2 > -24 THEN DX2 = DX2 - 1
  21.     IF Y2 < Y1 AND DY2 < 24 THEN DY2 = DY2 + 1
  22.     IF Y2 > Y1 AND DY2 > -24 THEN DY2 = DY2 - 1
  23.     X2 = X2 + DX2: Y2 = Y2 + DY2: A = (A + 10) MOD 360: Z = (SIN(_D2R(A) + 1)) + 2
  24.     FOR N = 2 TO 15
  25.         bX(N - 1) = bX(N): bY(N - 1) = bY(N): bZ(N - 1) = bZ(N)
  26.     NEXT
  27.     bX(15) = X2: bY(15) = Y2: bZ(15) = Z
  28.     FOR N = 1 TO 15: fcirc bX(N), bY(N), N * bZ(N) + 5, COLR(N): NEXT
  29.     _DISPLAY
  30.     _LIMIT 60
  31.  
  32. 'from Steve Gold standard
  33. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  34.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  35.     DIM X AS INTEGER, Y AS INTEGER
  36.  
  37.     Radius = ABS(R)
  38.     RadiusError = -Radius
  39.     X = Radius
  40.     Y = 0
  41.  
  42.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  43.  
  44.     ' Draw the middle span here so we don't draw it twice in the main loop,
  45.     ' which would be a problem with blending turned on.
  46.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  47.  
  48.     WHILE X > Y
  49.         RadiusError = RadiusError + Y * 2 + 1
  50.         IF RadiusError >= 0 THEN
  51.             IF X <> Y + 1 THEN
  52.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  53.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  54.             END IF
  55.             X = X - 1
  56.             RadiusError = RadiusError - X * 2
  57.         END IF
  58.         Y = Y + 1
  59.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  60.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  61.     WEND
  62.  
  63.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Guts translation from past
« Reply #1 on: April 05, 2019, 11:40:39 am »
How about a Glowing Tapeworm?

Code: QB64: [Select]
  1. _TITLE "Glowing Tapeworm" ' 2019-04-05 B_ modified Guts
  2. ' 2019-04-05 B+ translation to QB64 from: Guts.bas SmallBASIC 0.12.0 2015-11-17 MGA/B+
  3. 'modified  > GUTS  Original ARM BBC BASIC version by Jan Vibe, 800x600 ?
  4.  
  5. CONST xmax = 800
  6. CONST ymax = 600
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8.  
  9. DIM bX(63), bY(63), bZ(63), COLR(63) AS _UNSIGNED LONG
  10. bX(1) = -100: A = 0
  11.  
  12. ' gut palette
  13. FOR N = 1 TO 63
  14.     COLR(64 - N) = _RGB32(1.5 * N + 150, 3 * N + 45, 3 * N + 45)
  15.  
  16. X1 = RND * xmax: Y1 = RND * ymax: DX1 = (RND * 16 + 1) * (RND - .5): DY1 = (RND * 16 + 1) * (RND - .5)
  17. X2 = RND * xmax: Y2 = RND * ymax: DX2 = (RND * 16 + 1) * (RND - .5): DY2 = (RND * 16 + 1) * (RND - .5)
  18.     LINE (0, 0)-(xmax, ymax), _RGBA32(0, 0, 0, 15), BF
  19.     H = X1 + DX1: IF H < 0 OR H > xmax THEN DX1 = (RND * 16 + 1) * -SGN(DX1)
  20.     H = Y1 + DY1: IF H < 0 OR H > ymax THEN DY1 = (RND * 16 + 1) * -SGN(DY1)
  21.     X1 = X1 + DX1: Y1 = Y1 + DY1
  22.     IF X2 < X1 AND DX2 < 24 THEN DX2 = DX2 + 1
  23.     IF X2 > X1 AND DX2 > -24 THEN DX2 = DX2 - 1
  24.     IF Y2 < Y1 AND DY2 < 24 THEN DY2 = DY2 + 1
  25.     IF Y2 > Y1 AND DY2 > -24 THEN DY2 = DY2 - 1
  26.     X2 = X2 + DX2: Y2 = Y2 + DY2: A = (A + 10) MOD 360: Z = (SIN(_D2R(A) + 1)) + 2
  27.     FOR N = 1 TO 63
  28.         bX(N - 1) = bX(N): bY(N - 1) = bY(N): bZ(N - 1) = bZ(N)
  29.     NEXT
  30.     bX(63) = X2: bY(63) = Y2: bZ(63) = Z
  31.     FOR N = 1 TO 63: fcirc bX(N), bY(N), .6 * N * bZ(N), COLR(N): NEXT
  32.     _DISPLAY
  33.     _LIMIT 60
  34.  
  35. 'from Steve Gold standard
  36. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  37.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  38.     DIM X AS INTEGER, Y AS INTEGER
  39.  
  40.     Radius = ABS(R)
  41.     RadiusError = -Radius
  42.     X = Radius
  43.     Y = 0
  44.  
  45.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  46.  
  47.     ' Draw the middle span here so we don't draw it twice in the main loop,
  48.     ' which would be a problem with blending turned on.
  49.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  50.  
  51.     WHILE X > Y
  52.         RadiusError = RadiusError + Y * 2 + 1
  53.         IF RadiusError >= 0 THEN
  54.             IF X <> Y + 1 THEN
  55.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  56.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  57.             END IF
  58.             X = X - 1
  59.             RadiusError = RadiusError - X * 2
  60.         END IF
  61.         Y = Y + 1
  62.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  63.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  64.     WEND
  65.  
  66.  

FellippeHeitor

  • Guest
Re: Guts translation from past
« Reply #2 on: April 05, 2019, 11:57:39 am »
How about a Glowing Tapeworm?

Code: QB64: [Select]
  1. _TITLE "Glowing Tapeworm" ' 2019-04-05 B_ modified Guts
  2. ' 2019-04-05 B+ translation to QB64 from: Guts.bas SmallBASIC 0.12.0 2015-11-17 MGA/B+
  3. 'modified  > GUTS  Original ARM BBC BASIC version by Jan Vibe, 800x600 ?
  4.  
  5. CONST xmax = 800
  6. CONST ymax = 600
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8.  
  9. DIM bX(63), bY(63), bZ(63), COLR(63) AS _UNSIGNED LONG
  10. bX(1) = -100: A = 0
  11.  
  12. ' gut palette
  13. FOR N = 1 TO 63
  14.     COLR(64 - N) = _RGB32(1.5 * N + 150, 3 * N + 45, 3 * N + 45)
  15.  
  16. X1 = RND * xmax: Y1 = RND * ymax: DX1 = (RND * 16 + 1) * (RND - .5): DY1 = (RND * 16 + 1) * (RND - .5)
  17. X2 = RND * xmax: Y2 = RND * ymax: DX2 = (RND * 16 + 1) * (RND - .5): DY2 = (RND * 16 + 1) * (RND - .5)
  18.     LINE (0, 0)-(xmax, ymax), _RGBA32(0, 0, 0, 15), BF
  19.     H = X1 + DX1: IF H < 0 OR H > xmax THEN DX1 = (RND * 16 + 1) * -SGN(DX1)
  20.     H = Y1 + DY1: IF H < 0 OR H > ymax THEN DY1 = (RND * 16 + 1) * -SGN(DY1)
  21.     X1 = X1 + DX1: Y1 = Y1 + DY1
  22.     IF X2 < X1 AND DX2 < 24 THEN DX2 = DX2 + 1
  23.     IF X2 > X1 AND DX2 > -24 THEN DX2 = DX2 - 1
  24.     IF Y2 < Y1 AND DY2 < 24 THEN DY2 = DY2 + 1
  25.     IF Y2 > Y1 AND DY2 > -24 THEN DY2 = DY2 - 1
  26.     X2 = X2 + DX2: Y2 = Y2 + DY2: A = (A + 10) MOD 360: Z = (SIN(_D2R(A) + 1)) + 2
  27.     FOR N = 1 TO 63
  28.         bX(N - 1) = bX(N): bY(N - 1) = bY(N): bZ(N - 1) = bZ(N)
  29.     NEXT
  30.     bX(63) = X2: bY(63) = Y2: bZ(63) = Z
  31.     FOR N = 1 TO 63: fcirc bX(N), bY(N), .6 * N * bZ(N), COLR(N): NEXT
  32.     _DISPLAY
  33.     _LIMIT 60
  34.  
  35. 'from Steve Gold standard
  36. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  37.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  38.     DIM X AS INTEGER, Y AS INTEGER
  39.  
  40.     Radius = ABS(R)
  41.     RadiusError = -Radius
  42.     X = Radius
  43.     Y = 0
  44.  
  45.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  46.  
  47.     ' Draw the middle span here so we don't draw it twice in the main loop,
  48.     ' which would be a problem with blending turned on.
  49.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  50.  
  51.     WHILE X > Y
  52.         RadiusError = RadiusError + Y * 2 + 1
  53.         IF RadiusError >= 0 THEN
  54.             IF X <> Y + 1 THEN
  55.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  56.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  57.             END IF
  58.             X = X - 1
  59.             RadiusError = RadiusError - X * 2
  60.         END IF
  61.         Y = Y + 1
  62.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  63.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  64.     WEND
  65.  
  66.  

Cool!!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Guts translation from past
« Reply #3 on: April 05, 2019, 01:35:12 pm »
nice, bplus, thanks

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Guts translation from past
« Reply #4 on: April 05, 2019, 05:42:51 pm »
fine! the first one. Cool the second...do you plan to make a clone of Slither.io?
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Guts translation from past
« Reply #5 on: April 05, 2019, 06:13:48 pm »
Thanks guys!

Slither.io never heard of it, checked it out, reminds me of the Snake Game with company.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Guts translation from past
« Reply #6 on: April 06, 2019, 12:53:55 am »
Perfect bplus! :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Guts translation from past
« Reply #7 on: April 06, 2019, 04:13:27 am »
What? That's great, Bplus!