Author Topic: Help! buggy code  (Read 5194 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Help! buggy code
« on: June 17, 2019, 07:16:26 pm »
and the screen just sits there...
Code: QB64: [Select]
  1. _TITLE "draw Spinner" 'B+ started 2019-06-15
  2. CONST nSpinners = 100
  3. TYPE SpinnerType
  4.     x AS SINGLE
  5.     y AS SINGLE
  6.     dx AS SINGLE
  7.     dy AS SINGLE
  8.     sz AS SINGLE
  9.     c AS _UNSIGNED LONG
  10.  
  11. SCREEN _NEWIMAGE(xmax, ymax, 32)
  12. '_SCREENMOVE 300, 20
  13. DIM SHARED s(1 TO nSpinners) AS SpinnerType
  14. DIM i, i2, lc, sc&
  15. COLOR , &HFFAABBCC
  16. FOR i = 1 TO nSpinners
  17.     newSpinner i
  18. i2 = 1
  19.     _PUTIMAGE , sc&
  20.     lc = lc + 1
  21.     IF lc MOD 100 = 99 THEN
  22.         lc = 0
  23.         IF i2 < nSpinners THEN i2 = i2 + 1
  24.     END IF
  25.     FOR i = 1 TO i2
  26.         drawSpinner s(i).x, s(i).y, s(i).sz, _ATAN2(s(i).dy, s(i).dx), s(i).c
  27.         s(i).x = s(i).x + s(i).dx: s(i).y = s(i).y + s(i).dy
  28.         IF s(i).x < -100 OR s(i).x > xmax + 100 OR s(i).y < -100 OR s(i).y > ymax + 100 THEN newSpinner i
  29.     NEXT
  30.     _DISPLAY
  31.     _LIMIT 15
  32.  
  33. SUB newSpinner (i AS INTEGER) 'set Spinners dimensions start angles, color?
  34.     DIM r
  35.     s(i).sz = RND * .25 + .5
  36.     IF RND < .5 THEN r = -1 ELSE r = 1
  37.     s(i).dx = (s(i).sz * RND * 8) * r * 2: s(i).dy = (s(i).sz * RND * 8) * r * 2
  38.     r = INT(RND * 4)
  39.     SELECT CASE r
  40.         CASE 0: s(i).x = RND * (xmax - 120) + 60: s(i).y = 0: IF s(i).dy < 0 THEN s(i).dy = -s(i).dy
  41.         CASE 1: s(i).x = RND * (xmax - 120) + 60: s(i).y = ymax: IF s(i).dy > 0 THEN s(i).dy = -s(i).dy
  42.         CASE 2: s(i).x = 0: s(i).y = RND * (ymax - 120) + 60: IF s(i).dx < 0 THEN s(i).dx = -s(i).dx
  43.         CASE 3: s(i).x = xmax: s(i).y = RND * (ymax - 120) + 60: IF s(i).dx > 0 THEN s(i).dx = -s(i).dx
  44.     END SELECT
  45.     r = RND * 120
  46.     s(i).c = _RGB32(r, RND * .5 * r, RND * .25 * r)
  47.  
  48. SUB drawSpinner (x AS INTEGER, y AS INTEGER, scale AS SINGLE, heading AS SINGLE, c AS _UNSIGNED LONG)
  49.     DIM x1, x2, x3, x4, y1, y2, y3, y4, r, a, a1, a2, lg, d, rd, red, blue, green
  50.     STATIC switch AS INTEGER
  51.     switch = switch + 2
  52.     switch = switch MOD 16 + 1
  53.     red = _RED32(c): green = _GREEN32(c): blue = _BLUE32(c)
  54.     r = 10 * scale
  55.     x1 = x + r * COS(heading): y1 = y + r * SIN(heading)
  56.     r = 2 * r 'lg lengths
  57.     FOR lg = 1 TO 8
  58.         IF lg < 5 THEN
  59.             a = heading + .9 * lg * _PI(1 / 5) + (lg = switch) * _PI(1 / 10)
  60.         ELSE
  61.             a = heading - .9 * (lg - 4) * _PI(1 / 5) - (lg = switch) * _PI(1 / 10)
  62.         END IF
  63.         x2 = x1 + r * COS(a): y2 = y1 + r * SIN(a)
  64.         drawLink x1, y1, 3 * scale, x2, y2, 2 * scale, _RGB32(red + 20, green + 10, blue + 5)
  65.         IF lg = 1 OR lg = 2 OR lg = 7 OR lg = 8 THEN d = -1 ELSE d = 1
  66.         a1 = a + d * _PI(1 / 12)
  67.         x3 = x2 + r * 1.5 * COS(a1): y3 = y2 + r * 1.5 * SIN(a1)
  68.         drawLink x2, y2, 2 * scale, x3, y3, scale, _RGB32(red + 35, green + 17, blue + 8)
  69.         rd = INT(RND * 8) + 1
  70.         a2 = a1 + d * _PI(1 / 8) * rd / 8
  71.         x4 = x3 + r * 1.5 * COS(a2): y4 = y3 + r * 1.5 * SIN(a2)
  72.         drawLink x3, y3, scale, x4, y4, scale, _RGB32(red + 50, green + 25, blue + 12)
  73.     NEXT
  74.     r = r * .5
  75.     fcirc x1, y1, r, _RGB32(red - 20, green - 10, blue - 5)
  76.     x2 = x1 + (r + 1) * COS(heading - _PI(1 / 12)): y2 = y1 + (r + 1) * SIN(heading - _PI(1 / 12))
  77.     fcirc x2, y2, r * .2, &HFF000000
  78.     x2 = x1 + (r + 1) * COS(heading + _PI(1 / 12)): y2 = y1 + (r + 1) * SIN(heading + _PI(1 / 12))
  79.     fcirc x2, y2, r * .2, &HFF000000
  80.     r = r * 2
  81.     x1 = x + r * .9 * COS(heading + _PI): y1 = y + r * .9 * SIN(heading + _PI)
  82.     TiltedEllipseFill 0, x1, y1, r, .7 * r, heading + _PI, _RGB32(red, green, blue)
  83.  
  84. SUB drawLink (x1, y1, r1, x2, y2, r2, c AS _UNSIGNED LONG)
  85.     DIM a, a1, a2, x3, x4, x5, x6, y3, y4, y5, y6
  86.     a = _ATAN2(y2 - y1, x2 - x1)
  87.     a1 = a + _PI(1 / 2)
  88.     a2 = a - _PI(1 / 2)
  89.     x3 = x1 + r1 * COS(a1): y3 = y1 + r1 * SIN(a1)
  90.     x4 = x1 + r1 * COS(a2): y4 = y1 + r1 * SIN(a2)
  91.     x5 = x2 + r2 * COS(a1): y5 = y2 + r2 * SIN(a1)
  92.     x6 = x2 + r2 * COS(a2): y6 = y2 + r2 * SIN(a2)
  93.     fquad x3, y3, x4, y4, x5, y5, x6, y6, c
  94.     fcirc x1, y1, r1, c
  95.     fcirc x2, y2, r2, c
  96.  
  97. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  98. SUB fquad (x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER, x3 AS INTEGER, y3 AS INTEGER, x4 AS INTEGER, y4 AS INTEGER, c AS _UNSIGNED LONG)
  99.     ftri x1, y1, x2, y2, x4, y4, c
  100.     ftri x3, y3, x4, y4, x1, y1, c
  101.  
  102. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  103.     DIM a&
  104.     a& = _NEWIMAGE(1, 1, 32)
  105.     _DEST a&
  106.     PSET (0, 0), K
  107.     _DEST 0
  108.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  109.     _FREEIMAGE a& '<<< this is important!
  110.  
  111. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  112.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  113.     DIM X AS INTEGER, Y AS INTEGER
  114.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  115.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  116.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  117.     WHILE X > Y
  118.         RadiusError = RadiusError + Y * 2 + 1
  119.         IF RadiusError >= 0 THEN
  120.             IF X <> Y + 1 THEN
  121.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  122.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  123.             END IF
  124.             X = X - 1
  125.             RadiusError = RadiusError - X * 2
  126.         END IF
  127.         Y = Y + 1
  128.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  129.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  130.     WEND
  131.  
  132. SUB TiltedEllipseFill (destHandle&, x0, y0, a, b, ang, c AS _UNSIGNED LONG)
  133.     DIM max AS INTEGER, mx2 AS INTEGER, i AS INTEGER, j AS INTEGER, k AS SINGLE, lasti AS SINGLE, lastj AS SINGLE
  134.     DIM prc AS _UNSIGNED LONG, tef AS LONG
  135.     prc = _RGB32(255, 255, 255, 255)
  136.     IF a > b THEN max = a + 1 ELSE max = b + 1
  137.     mx2 = max + max
  138.     tef = _NEWIMAGE(mx2, mx2)
  139.     _DEST tef
  140.     _SOURCE tef 'point wont read without this!
  141.     FOR k = 0 TO 6.2832 + .05 STEP .1
  142.         i = max + a * COS(k) * COS(ang) + b * SIN(k) * SIN(ang)
  143.         j = max + a * COS(k) * SIN(ang) - b * SIN(k) * COS(ang)
  144.         IF k <> 0 THEN
  145.             LINE (lasti, lastj)-(i, j), prc
  146.         ELSE
  147.             PSET (i, j), prc
  148.         END IF
  149.         lasti = i: lastj = j
  150.     NEXT
  151.     DIM xleft(mx2) AS INTEGER, xright(mx2) AS INTEGER, x AS INTEGER, y AS INTEGER
  152.     FOR y = 0 TO mx2
  153.         x = 0
  154.         WHILE POINT(x, y) <> prc AND x < mx2
  155.             x = x + 1
  156.         WEND
  157.         xleft(y) = x
  158.         WHILE POINT(x, y) = prc AND x < mx2
  159.             x = x + 1
  160.         WEND
  161.         WHILE POINT(x, y) <> prc AND x < mx2
  162.             x = x + 1
  163.         WEND
  164.         IF x = mx2 THEN xright(y) = xleft(y) ELSE xright(y) = x
  165.     NEXT
  166.     _DEST destHandle&
  167.     FOR y = 0 TO mx2
  168.         IF xleft(y) <> mx2 THEN LINE (xleft(y) + x0 - max, y + y0 - max)-(xright(y) + x0 - max, y + y0 - max), c, BF
  169.     NEXT
  170.     _FREEIMAGE tef
  171.  
  172.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Help! buggy code
« Reply #1 on: June 17, 2019, 11:20:19 pm »
Man that code has a lot of bugs...

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Help! buggy code
« Reply #2 on: June 18, 2019, 12:25:18 am »
A slight alteration:

Code: QB64: [Select]
  1.     FUNCTION glutGet& (BYVAL what&)
  2.  
  3. _SCREENMOVE -32000, -32000
  4. BorderWidth = glutGet(506)
  5. TitleBarHeight = glutGet(507)
  6.  
  7. _TITLE "draw Spinner" 'B+ started 2019-06-15
  8. CONST nSpinners = 100
  9. TYPE SpinnerType
  10.     x AS SINGLE
  11.     y AS SINGLE
  12.     dx AS SINGLE
  13.     dy AS SINGLE
  14.     sz AS SINGLE
  15.     c AS _UNSIGNED LONG
  16. PRINT xmax, ymax
  17.  
  18. DIM SHARED s(1 TO nSpinners) AS SpinnerType
  19. DIM i, i2, lc, sc&
  20.  
  21. SCREEN _NEWIMAGE(xmax, ymax, 32)
  22. _SCREENMOVE -BorderWidth, -BorderWidth - TitleBarHeight
  23.  
  24. COLOR , &HFFAABBCC
  25. FOR i = 1 TO nSpinners
  26.     newSpinner i
  27. i2 = 1
  28.  
  29.  
  30. '_SCREENSHOW
  31.     _PUTIMAGE , sc&
  32.     lc = lc + 1
  33.     IF lc MOD 100 = 99 THEN
  34.         lc = 0
  35.         IF i2 < nSpinners THEN i2 = i2 + 1
  36.     END IF
  37.     FOR i = 1 TO i2
  38.         drawSpinner s(i).x, s(i).y, s(i).sz, _ATAN2(s(i).dy, s(i).dx), s(i).c
  39.         s(i).x = s(i).x + s(i).dx: s(i).y = s(i).y + s(i).dy
  40.         IF s(i).x < -100 OR s(i).x > xmax + 100 OR s(i).y < -100 OR s(i).y > ymax + 100 THEN newSpinner i
  41.     NEXT
  42.     _DISPLAY
  43.     _LIMIT 15
  44.  
  45. SUB newSpinner (i AS INTEGER) 'set Spinners dimensions start angles, color?
  46.     DIM r
  47.     s(i).sz = RND * .25 + .5
  48.     IF RND < .5 THEN r = -1 ELSE r = 1
  49.     s(i).dx = (s(i).sz * RND * 8) * r * 2: s(i).dy = (s(i).sz * RND * 8) * r * 2
  50.     r = INT(RND * 4)
  51.     SELECT CASE r
  52.         CASE 0: s(i).x = RND * (xmax - 120) + 60: s(i).y = 0: IF s(i).dy < 0 THEN s(i).dy = -s(i).dy
  53.         CASE 1: s(i).x = RND * (xmax - 120) + 60: s(i).y = ymax: IF s(i).dy > 0 THEN s(i).dy = -s(i).dy
  54.         CASE 2: s(i).x = 0: s(i).y = RND * (ymax - 120) + 60: IF s(i).dx < 0 THEN s(i).dx = -s(i).dx
  55.         CASE 3: s(i).x = xmax: s(i).y = RND * (ymax - 120) + 60: IF s(i).dx > 0 THEN s(i).dx = -s(i).dx
  56.     END SELECT
  57.     r = RND * 120
  58.     s(i).c = _RGB32(r, RND * .5 * r, RND * .25 * r)
  59.  
  60. SUB drawSpinner (x AS INTEGER, y AS INTEGER, scale AS SINGLE, heading AS SINGLE, c AS _UNSIGNED LONG)
  61.     DIM x1, x2, x3, x4, y1, y2, y3, y4, r, a, a1, a2, lg, d, rd, red, blue, green
  62.     STATIC switch AS INTEGER
  63.     switch = switch + 2
  64.     switch = switch MOD 16 + 1
  65.     red = _RED32(c): green = _GREEN32(c): blue = _BLUE32(c)
  66.     r = 10 * scale
  67.     x1 = x + r * COS(heading): y1 = y + r * SIN(heading)
  68.     r = 2 * r 'lg lengths
  69.     FOR lg = 1 TO 8
  70.         IF lg < 5 THEN
  71.             a = heading + .9 * lg * _PI(1 / 5) + (lg = switch) * _PI(1 / 10)
  72.         ELSE
  73.             a = heading - .9 * (lg - 4) * _PI(1 / 5) - (lg = switch) * _PI(1 / 10)
  74.         END IF
  75.         x2 = x1 + r * COS(a): y2 = y1 + r * SIN(a)
  76.         drawLink x1, y1, 3 * scale, x2, y2, 2 * scale, _RGB32(red + 20, green + 10, blue + 5)
  77.         IF lg = 1 OR lg = 2 OR lg = 7 OR lg = 8 THEN d = -1 ELSE d = 1
  78.         a1 = a + d * _PI(1 / 12)
  79.         x3 = x2 + r * 1.5 * COS(a1): y3 = y2 + r * 1.5 * SIN(a1)
  80.         drawLink x2, y2, 2 * scale, x3, y3, scale, _RGB32(red + 35, green + 17, blue + 8)
  81.         rd = INT(RND * 8) + 1
  82.         a2 = a1 + d * _PI(1 / 8) * rd / 8
  83.         x4 = x3 + r * 1.5 * COS(a2): y4 = y3 + r * 1.5 * SIN(a2)
  84.         drawLink x3, y3, scale, x4, y4, scale, _RGB32(red + 50, green + 25, blue + 12)
  85.     NEXT
  86.     r = r * .5
  87.     fcirc x1, y1, r, _RGB32(red - 20, green - 10, blue - 5)
  88.     x2 = x1 + (r + 1) * COS(heading - _PI(1 / 12)): y2 = y1 + (r + 1) * SIN(heading - _PI(1 / 12))
  89.     fcirc x2, y2, r * .2, &HFF000000
  90.     x2 = x1 + (r + 1) * COS(heading + _PI(1 / 12)): y2 = y1 + (r + 1) * SIN(heading + _PI(1 / 12))
  91.     fcirc x2, y2, r * .2, &HFF000000
  92.     r = r * 2
  93.     x1 = x + r * .9 * COS(heading + _PI): y1 = y + r * .9 * SIN(heading + _PI)
  94.     TiltedEllipseFill 0, x1, y1, r, .7 * r, heading + _PI, _RGB32(red, green, blue)
  95.  
  96. SUB drawLink (x1, y1, r1, x2, y2, r2, c AS _UNSIGNED LONG)
  97.     DIM a, a1, a2, x3, x4, x5, x6, y3, y4, y5, y6
  98.     a = _ATAN2(y2 - y1, x2 - x1)
  99.     a1 = a + _PI(1 / 2)
  100.     a2 = a - _PI(1 / 2)
  101.     x3 = x1 + r1 * COS(a1): y3 = y1 + r1 * SIN(a1)
  102.     x4 = x1 + r1 * COS(a2): y4 = y1 + r1 * SIN(a2)
  103.     x5 = x2 + r2 * COS(a1): y5 = y2 + r2 * SIN(a1)
  104.     x6 = x2 + r2 * COS(a2): y6 = y2 + r2 * SIN(a2)
  105.     fquad x3, y3, x4, y4, x5, y5, x6, y6, c
  106.     fcirc x1, y1, r1, c
  107.     fcirc x2, y2, r2, c
  108.  
  109. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  110. SUB fquad (x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER, x3 AS INTEGER, y3 AS INTEGER, x4 AS INTEGER, y4 AS INTEGER, c AS _UNSIGNED LONG)
  111.     ftri x1, y1, x2, y2, x4, y4, c
  112.     ftri x3, y3, x4, y4, x1, y1, c
  113.  
  114. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  115.     DIM a&
  116.     a& = _NEWIMAGE(1, 1, 32)
  117.     _DEST a&
  118.     PSET (0, 0), K
  119.     _DEST 0
  120.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  121.     _FREEIMAGE a& '<<< this is important!
  122.  
  123. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  124.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  125.     DIM X AS INTEGER, Y AS INTEGER
  126.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  127.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  128.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  129.     WHILE X > Y
  130.         RadiusError = RadiusError + Y * 2 + 1
  131.         IF RadiusError >= 0 THEN
  132.             IF X <> Y + 1 THEN
  133.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  134.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  135.             END IF
  136.             X = X - 1
  137.             RadiusError = RadiusError - X * 2
  138.         END IF
  139.         Y = Y + 1
  140.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  141.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  142.     WEND
  143.  
  144. SUB TiltedEllipseFill (destHandle&, x0, y0, a, b, ang, c AS _UNSIGNED LONG)
  145.     DIM max AS INTEGER, mx2 AS INTEGER, i AS INTEGER, j AS INTEGER, k AS SINGLE, lasti AS SINGLE, lastj AS SINGLE
  146.     DIM prc AS _UNSIGNED LONG, tef AS LONG
  147.     prc = _RGB32(255, 255, 255, 255)
  148.     IF a > b THEN max = a + 1 ELSE max = b + 1
  149.     mx2 = max + max
  150.     tef = _NEWIMAGE(mx2, mx2)
  151.     _DEST tef
  152.     _SOURCE tef 'point wont read without this!
  153.     FOR k = 0 TO 6.2832 + .05 STEP .1
  154.         i = max + a * COS(k) * COS(ang) + b * SIN(k) * SIN(ang)
  155.         j = max + a * COS(k) * SIN(ang) - b * SIN(k) * COS(ang)
  156.         IF k <> 0 THEN
  157.             LINE (lasti, lastj)-(i, j), prc
  158.         ELSE
  159.             PSET (i, j), prc
  160.         END IF
  161.         lasti = i: lastj = j
  162.     NEXT
  163.     DIM xleft(mx2) AS INTEGER, xright(mx2) AS INTEGER, x AS INTEGER, y AS INTEGER
  164.     FOR y = 0 TO mx2
  165.         x = 0
  166.         WHILE POINT(x, y) <> prc AND x < mx2
  167.             x = x + 1
  168.         WEND
  169.         xleft(y) = x
  170.         WHILE POINT(x, y) = prc AND x < mx2
  171.             x = x + 1
  172.         WEND
  173.         WHILE POINT(x, y) <> prc AND x < mx2
  174.             x = x + 1
  175.         WEND
  176.         IF x = mx2 THEN xright(y) = xleft(y) ELSE xright(y) = x
  177.     NEXT
  178.     _DEST destHandle&
  179.     FOR y = 0 TO mx2
  180.         IF xleft(y) <> mx2 THEN LINE (xleft(y) + x0 - max, y + y0 - max)-(xright(y) + x0 - max, y + y0 - max), c, BF
  181.     NEXT
  182.     _FREEIMAGE tef
  183.  

Using screenhide and screenshow, there's a blank artifact program window frame which almost always seems to get caught up in the desktop screenshot.  (The program is running and executing the screenimage command, before windows has finished making and then completely hiding the window from the screenhide command, which gives us a screen capture of a desktop with the window in the middle of closing.)

screenmove -32000,-32000 is a good, quick way to hide the window from the screen, and by using the glutget commands, we can eliminate the need for FULLSCREEN, just by positioning the window so that it's properly placed to make the program seemlessly cover the whole screen. 

And what's the point of that, you ask??

So you can ALT-Tab another program (such as QB64, or your web browser) back into focus ON TOP of the buggy little program, and have it run freely in the background for you, under the other app which you put in focus.  (Though, I do find myself getting distracted while typing on the forums here, by the dozen spiders which are dancing happily across my screen...)   
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Help! buggy code
« Reply #3 on: June 18, 2019, 03:32:15 am »
That's sooo cool, gonna freak out my wife with it today :)
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help! buggy code
« Reply #4 on: June 18, 2019, 05:40:03 am »
Oh my God!
all these bugs enter into my screen and into my brain....
who can save me?

I'll call these superHeroes https://images-na.ssl-images-amazon.com/images/I/511J5S8F5XL._SY445_.jpg

Very very fine!
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help! buggy code
« Reply #5 on: June 18, 2019, 05:43:10 am »
Yep!
Steve also you!
Damn destiny!
Steve help me too you!
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help! buggy code
« Reply #6 on: June 18, 2019, 09:32:00 am »
Hi Steve,

Thanks for the modification. Our systems must work differently because _SCREEN HIDE, _SCREENSHOW did fix the screen artifact problem for me, the screen just blinks and then you see the bug(s). Your mod leaves a shadow screen, if I run it from the QB64 IDE and it seems a 50/50 change for artifact from the .exe, here are what I am seeing in screen shots attached. BTW the MS Windows button let's me access tools when I have Full Screen App running eg, for screen shots.

So if my code leaves screen artifacts or screen shadows then try Steve's mod or vice versa :)



 
Steve Mod of Buggy.PNG
* Steve Mod of Buggy.PNG (Filesize: 26.1 KB, Dimensions: 765x561, Views: 271)
steve mod exe.PNG
* steve mod exe.PNG (Filesize: 82.51 KB, Dimensions: 686x608, Views: 264)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Help! buggy code
« Reply #7 on: June 18, 2019, 11:48:16 am »
I had to insert a 'cls' at the top of the 'screenshow' while...wend..loop, but other than that, cool demo. The only things missing were webs, flies and a rolled up newspaper.... Nicely done!
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Help! buggy code
« Reply #8 on: June 18, 2019, 12:32:49 pm »
Hi. My fast modification:

Code: QB64: [Select]
  1.  
  2. DIM i, i2, lc, sc&
  3.  
  4. _TITLE "draw Spinner" 'B+ started 2019-06-15
  5. CONST nSpinners = 100
  6. TYPE SpinnerType
  7.     x AS SINGLE
  8.     y AS SINGLE
  9.     dx AS SINGLE
  10.     dy AS SINGLE
  11.     sz AS SINGLE
  12.     c AS _UNSIGNED LONG
  13.  
  14. SCREEN _NEWIMAGE(xmax, ymax, 32)
  15. '_SCREENMOVE 300, 20
  16. DIM SHARED s(1 TO nSpinners) AS SpinnerType
  17.  
  18. COLOR , &HFFAABBCC
  19. FOR i = 1 TO nSpinners
  20.     newSpinner i
  21. i2 = 1
  22.  
  23.     _PUTIMAGE , sc&
  24.     lc = lc + 1
  25.     IF lc MOD 100 = 99 THEN
  26.         lc = 0
  27.         IF i2 < nSpinners THEN i2 = i2 + 1
  28.     END IF
  29.     FOR i = 1 TO i2
  30.         drawSpinner s(i).x, s(i).y, s(i).sz, _ATAN2(s(i).dy, s(i).dx), s(i).c
  31.         s(i).x = s(i).x + s(i).dx: s(i).y = s(i).y + s(i).dy
  32.         IF s(i).x < -100 OR s(i).x > xmax + 100 OR s(i).y < -100 OR s(i).y > ymax + 100 THEN newSpinner i
  33.     NEXT
  34.     _DISPLAY
  35.     _LIMIT 15
  36.  
  37. SUB newSpinner (i AS INTEGER) 'set Spinners dimensions start angles, color?
  38.     DIM r
  39.     s(i).sz = RND * .25 + .5
  40.     IF RND < .5 THEN r = -1 ELSE r = 1
  41.     s(i).dx = (s(i).sz * RND * 8) * r * 2: s(i).dy = (s(i).sz * RND * 8) * r * 2
  42.     r = INT(RND * 4)
  43.     SELECT CASE r
  44.         CASE 0: s(i).x = RND * (xmax - 120) + 60: s(i).y = 0: IF s(i).dy < 0 THEN s(i).dy = -s(i).dy
  45.         CASE 1: s(i).x = RND * (xmax - 120) + 60: s(i).y = ymax: IF s(i).dy > 0 THEN s(i).dy = -s(i).dy
  46.         CASE 2: s(i).x = 0: s(i).y = RND * (ymax - 120) + 60: IF s(i).dx < 0 THEN s(i).dx = -s(i).dx
  47.         CASE 3: s(i).x = xmax: s(i).y = RND * (ymax - 120) + 60: IF s(i).dx > 0 THEN s(i).dx = -s(i).dx
  48.     END SELECT
  49.     r = RND * 120
  50.     s(i).c = _RGB32(r, RND * .5 * r, RND * .25 * r)
  51.  
  52. SUB drawSpinner (x AS INTEGER, y AS INTEGER, scale AS SINGLE, heading AS SINGLE, c AS _UNSIGNED LONG)
  53.     DIM x1, x2, x3, x4, y1, y2, y3, y4, r, a, a1, a2, lg, d, rd, red, blue, green
  54.     STATIC switch AS INTEGER
  55.     switch = switch + 2
  56.     switch = switch MOD 16 + 1
  57.     red = _RED32(c): green = _GREEN32(c): blue = _BLUE32(c)
  58.     r = 10 * scale
  59.     x1 = x + r * COS(heading): y1 = y + r * SIN(heading)
  60.     r = 2 * r 'lg lengths
  61.     FOR lg = 1 TO 8
  62.         IF lg < 5 THEN
  63.             a = heading + .9 * lg * _PI(1 / 5) + (lg = switch) * _PI(1 / 10)
  64.         ELSE
  65.             a = heading - .9 * (lg - 4) * _PI(1 / 5) - (lg = switch) * _PI(1 / 10)
  66.         END IF
  67.         x2 = x1 + r * COS(a): y2 = y1 + r * SIN(a)
  68.         drawLink x1, y1, 3 * scale, x2, y2, 2 * scale, _RGB32(red + 20, green + 10, blue + 5)
  69.         IF lg = 1 OR lg = 2 OR lg = 7 OR lg = 8 THEN d = -1 ELSE d = 1
  70.         a1 = a + d * _PI(1 / 12)
  71.         x3 = x2 + r * 1.5 * COS(a1): y3 = y2 + r * 1.5 * SIN(a1)
  72.         drawLink x2, y2, 2 * scale, x3, y3, scale, _RGB32(red + 35, green + 17, blue + 8)
  73.         rd = INT(RND * 8) + 1
  74.         a2 = a1 + d * _PI(1 / 8) * rd / 8
  75.         x4 = x3 + r * 1.5 * COS(a2): y4 = y3 + r * 1.5 * SIN(a2)
  76.         drawLink x3, y3, scale, x4, y4, scale, _RGB32(red + 50, green + 25, blue + 12)
  77.     NEXT
  78.     r = r * .5
  79.     fcirc x1, y1, r, _RGB32(red - 20, green - 10, blue - 5)
  80.     x2 = x1 + (r + 1) * COS(heading - _PI(1 / 12)): y2 = y1 + (r + 1) * SIN(heading - _PI(1 / 12))
  81.     fcirc x2, y2, r * .2, &HFF000000
  82.     x2 = x1 + (r + 1) * COS(heading + _PI(1 / 12)): y2 = y1 + (r + 1) * SIN(heading + _PI(1 / 12))
  83.     fcirc x2, y2, r * .2, &HFF000000
  84.     r = r * 2
  85.     x1 = x + r * .9 * COS(heading + _PI): y1 = y + r * .9 * SIN(heading + _PI)
  86.     TiltedEllipseFill 0, x1, y1, r, .7 * r, heading + _PI, _RGB32(red, green, blue)
  87.  
  88. SUB drawLink (x1, y1, r1, x2, y2, r2, c AS _UNSIGNED LONG)
  89.     DIM a, a1, a2, x3, x4, x5, x6, y3, y4, y5, y6
  90.     a = _ATAN2(y2 - y1, x2 - x1)
  91.     a1 = a + _PI(1 / 2)
  92.     a2 = a - _PI(1 / 2)
  93.     x3 = x1 + r1 * COS(a1): y3 = y1 + r1 * SIN(a1)
  94.     x4 = x1 + r1 * COS(a2): y4 = y1 + r1 * SIN(a2)
  95.     x5 = x2 + r2 * COS(a1): y5 = y2 + r2 * SIN(a1)
  96.     x6 = x2 + r2 * COS(a2): y6 = y2 + r2 * SIN(a2)
  97.     fquad x3, y3, x4, y4, x5, y5, x6, y6, c
  98.     fcirc x1, y1, r1, c
  99.     fcirc x2, y2, r2, c
  100.  
  101. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  102. SUB fquad (x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER, x3 AS INTEGER, y3 AS INTEGER, x4 AS INTEGER, y4 AS INTEGER, c AS _UNSIGNED LONG)
  103.     ftri x1, y1, x2, y2, x4, y4, c
  104.     ftri x3, y3, x4, y4, x1, y1, c
  105.  
  106. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  107.     DIM a&
  108.     a& = _NEWIMAGE(1, 1, 32)
  109.     _DEST a&
  110.     PSET (0, 0), K
  111.     _DEST 0
  112.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  113.     _FREEIMAGE a& '<<< this is important!
  114.  
  115. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  116.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  117.     DIM X AS INTEGER, Y AS INTEGER
  118.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  119.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  120.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  121.     WHILE X > Y
  122.         RadiusError = RadiusError + Y * 2 + 1
  123.         IF RadiusError >= 0 THEN
  124.             IF X <> Y + 1 THEN
  125.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  126.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  127.             END IF
  128.             X = X - 1
  129.             RadiusError = RadiusError - X * 2
  130.         END IF
  131.         Y = Y + 1
  132.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  133.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  134.     WEND
  135.  
  136. SUB TiltedEllipseFill (destHandle&, x0, y0, a, b, ang, c AS _UNSIGNED LONG)
  137.     DIM max AS INTEGER, mx2 AS INTEGER, i AS INTEGER, j AS INTEGER, k AS SINGLE, lasti AS SINGLE, lastj AS SINGLE
  138.     DIM prc AS _UNSIGNED LONG, tef AS LONG
  139.     prc = _RGB32(255, 255, 255, 255)
  140.     IF a > b THEN max = a + 1 ELSE max = b + 1
  141.     mx2 = max + max
  142.     tef = _NEWIMAGE(mx2, mx2)
  143.     _DEST tef
  144.     _SOURCE tef 'point wont read without this!
  145.     FOR k = 0 TO 6.2832 + .05 STEP .1
  146.         i = max + a * COS(k) * COS(ang) + b * SIN(k) * SIN(ang)
  147.         j = max + a * COS(k) * SIN(ang) - b * SIN(k) * COS(ang)
  148.         IF k <> 0 THEN
  149.             LINE (lasti, lastj)-(i, j), prc
  150.         ELSE
  151.             PSET (i, j), prc
  152.         END IF
  153.         lasti = i: lastj = j
  154.     NEXT
  155.     DIM xleft(mx2) AS INTEGER, xright(mx2) AS INTEGER, x AS INTEGER, y AS INTEGER
  156.     FOR y = 0 TO mx2
  157.         x = 0
  158.         WHILE POINT(x, y) <> prc AND x < mx2
  159.             x = x + 1
  160.         WEND
  161.         xleft(y) = x
  162.         WHILE POINT(x, y) = prc AND x < mx2
  163.             x = x + 1
  164.         WEND
  165.         WHILE POINT(x, y) <> prc AND x < mx2
  166.             x = x + 1
  167.         WEND
  168.         IF x = mx2 THEN xright(y) = xleft(y) ELSE xright(y) = x
  169.     NEXT
  170.     _DEST destHandle&
  171.     FOR y = 0 TO mx2
  172.         IF xleft(y) <> mx2 THEN LINE (xleft(y) + x0 - max, y + y0 - max)-(xright(y) + x0 - max, y + y0 - max), c, BF
  173.     NEXT
  174.     _FREEIMAGE tef
  175.  
  176.  
  177.  




Your bug do SCREENIMAGE. Use it as first statement in program as possible, and wait until is screenimage done.
Nice work, Bplus
« Last Edit: June 18, 2019, 12:37:04 pm by Petr »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Help! buggy code
« Reply #9 on: June 18, 2019, 12:38:05 pm »
@bplus:  That shaded area is what I get with your version as well.  Apparently, there’s a race condition going on behind the scenes with the screen capture routine, verses the screen hide/move routines.  The only way to be certain the effect is gone, is probably going to be to add a _DELAY in there to give the OS time to clear the display fully, before SCREENIMAGE is invoked.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help! buggy code
« Reply #10 on: June 18, 2019, 12:54:52 pm »
@bplus:  That shaded area is what I get with your version as well.  Apparently, there’s a race condition going on behind the scenes with the screen capture routine, verses the screen hide/move routines.  The only way to be certain the effect is gone, is probably going to be to add a _DELAY in there to give the OS time to clear the display fully, before SCREENIMAGE is invoked.

Yes, Petr's works fine with my system with his _DELAY even without _SCREENHIDE and _SCREENSHOW! Oh I see he takes his picture before the code gets going.



Thanks to all for comments! The legs aren't working quite as I hoped but close enough for an effect :)
« Last Edit: June 18, 2019, 12:56:54 pm by bplus »