Author Topic: Dropping Balls  (Read 31647 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Dropping Balls
« on: March 31, 2018, 12:54:05 am »
Misunderstanding what Make71 wanted, I reworked my ball handling for bounces and collisions. Not bad for zero vectors or dot products... are you a fake physics fan?
Code: QB64: [Select]
  1. _TITLE "Dropping Balls by bplus 2018-03-31"
  2. CONST xmax = 800
  3. CONST ymax = 600
  4.  
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6.  
  7. gravity = 1
  8. balls = 8
  9. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  10. FOR i = 1 TO balls
  11.     r(i) = rand(15, 20)
  12.     x(i) = rand(r(i), xmax - r(i))
  13.     y(i) = rand(r(i), ymax - r(i))
  14.     c(i) = rand(1, 15)
  15.     dx(i) = rand(1, 3) * rdir
  16.     dy(i) = rand(10, 20)
  17.     rr(i) = rand(200, 255)
  18.     gg(i) = rand(200, 255)
  19.     bb(i) = rand(200, 255)
  20.     CLS
  21.     FOR i = 1 TO balls
  22.         'ready for collision
  23.         a(i) = _ATAN2(dy(i), dx(i))
  24.         power = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  25.         FOR j = i + 1 TO balls
  26.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  27.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  28.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  29.                 EXIT FOR
  30.             END IF
  31.         NEXT
  32.         dx(i) = power * COS(a(i))
  33.         dy(i) = power * SIN(a(i))
  34.         dy(i) = dy(i) + gravity
  35.         x(i) = x(i) + dx(i)
  36.         y(i) = y(i) + dy(i) '+ 2 * gravity
  37.         IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN
  38.             x(i) = xmax / 2
  39.             y(i) = 0
  40.             dx(i) = rand(1, 3) * rdir
  41.             dy(i) = 0
  42.         END IF
  43.         IF y(i) + r(i) > ymax THEN y(i) = ymax - r(i): dy(i) = dy(i) * -.8
  44.         FOR rad = r(i) TO 1 STEP -1
  45.             COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  46.             fcirc x(i), y(i), rad
  47.         NEXT
  48.     NEXT
  49.     _DISPLAY
  50.     _LIMIT 20
  51.  
  52. FUNCTION rand (lo, hi)
  53.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  54.  
  55. FUNCTION rdir ()
  56.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  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.  
  89.  

Dropping Balls.PNG
* Dropping Balls.PNG (Filesize: 10.1 KB, Dimensions: 800x631, Views: 538)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #1 on: March 31, 2018, 09:54:40 am »
OK most of flaws mostly fixed.
Code: QB64: [Select]
  1. _TITLE "Dropping Balls 2 by bplus 2018-03-31"
  2. ' attempt to fix
  3. CONST xmax = 800
  4. CONST ymax = 600
  5.  
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 360, 60
  8.  
  9. gravity = 1
  10. balls = 8
  11. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  12. FOR i = 1 TO balls
  13.     r(i) = rand(15, 20)
  14.     x(i) = rand(r(i), xmax - r(i))
  15.     y(i) = rand(r(i), ymax - r(i))
  16.     c(i) = rand(1, 15)
  17.     dx(i) = rand(0, 3) * rdir
  18.     dy(i) = rand(10, 20)
  19.     rr(i) = rand(200, 255)
  20.     gg(i) = rand(200, 255)
  21.     bb(i) = rand(200, 255)
  22.     CLS
  23.     FOR i = 1 TO balls
  24.         'ready for collision
  25.         dy(i) = dy(i) + gravity
  26.         a(i) = _ATAN2(dy(i), dx(i))
  27.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  28.         imoved = 0
  29.         FOR j = i + 1 TO balls
  30.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  31.                 imoved = 1
  32.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  33.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  34.                 'update new dx, dy for i and j balls
  35.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  36.                 power = .7 * (power1 + power2) / 2
  37.                 dx(i) = power * COS(a(i))
  38.                 dy(i) = power * SIN(a(i))
  39.                 dx(j) = power * COS(a(j))
  40.                 dy(j) = power * SIN(a(j))
  41.                 x(i) = x(i) + dx(i)
  42.                 y(i) = y(i) + dy(i)
  43.                 x(j) = x(j) + dx(j)
  44.                 y(j) = y(j) + dy(j)
  45.                 EXIT FOR
  46.             END IF
  47.         NEXT
  48.         IF imoved = 0 THEN
  49.             x(i) = x(i) + dx(i)
  50.             y(i) = y(i) + dy(i)
  51.         END IF
  52.         IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN
  53.             x(i) = xmax / 2 + rand(0, 100) * rdir
  54.             y(i) = 0
  55.             dx(i) = rand(0, 3) * rdir
  56.             dy(i) = 1
  57.         END IF
  58.         IF y(i) + r(i) > ymax THEN y(i) = ymax - r(i): dy(i) = dy(i) * -.7: x(i) = x(i) + .1 * dx(i)
  59.         FOR rad = r(i) TO 1 STEP -1
  60.             COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  61.             fcirc x(i), y(i), rad
  62.         NEXT
  63.     NEXT
  64.     _DISPLAY
  65.     _LIMIT 20
  66.  
  67. FUNCTION rand (lo, hi)
  68.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  69.  
  70. FUNCTION rdir ()
  71.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  72.  
  73. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  74. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  75.     DIM subRadius AS LONG, RadiusError AS LONG
  76.     DIM X AS LONG, Y AS LONG
  77.  
  78.     subRadius = ABS(R)
  79.     RadiusError = -subRadius
  80.     X = subRadius
  81.     Y = 0
  82.  
  83.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  84.  
  85.     ' Draw the middle span here so we don't draw it twice in the main loop,
  86.     ' which would be a problem with blending turned on.
  87.     LINE (CX - X, CY)-(CX + X, CY), , BF
  88.  
  89.     WHILE X > Y
  90.         RadiusError = RadiusError + Y * 2 + 1
  91.         IF RadiusError >= 0 THEN
  92.             IF X <> Y + 1 THEN
  93.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  94.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  95.             END IF
  96.             X = X - 1
  97.             RadiusError = RadiusError - X * 2
  98.         END IF
  99.         Y = Y + 1
  100.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  101.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  102.     WEND
  103.  
  104.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #2 on: March 31, 2018, 12:57:00 pm »
Sound effects added, but a little off when lots of sound all at once, still it's fun to listen to:
Code: QB64: [Select]
  1. _TITLE "Dropping Balls 2 w sound by bplus 2018-03-31"
  2. ' attempt to fix
  3. CONST xmax = 800
  4. CONST ymax = 600
  5.  
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 360, 60
  8.  
  9. gravity = 1
  10. balls = 8
  11. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  12. FOR i = 1 TO balls
  13.     r(i) = rand(15, 20)
  14.     x(i) = rand(r(i), xmax - r(i))
  15.     y(i) = rand(r(i), ymax - r(i))
  16.     c(i) = rand(1, 15)
  17.     dx(i) = rand(0, 3) * rdir
  18.     dy(i) = rand(10, 20)
  19.     rr(i) = rand(200, 255)
  20.     gg(i) = rand(200, 255)
  21.     bb(i) = rand(200, 255)
  22.     CLS
  23.     FOR i = 1 TO balls
  24.         'ready for collision
  25.         dy(i) = dy(i) + gravity
  26.         a(i) = _ATAN2(dy(i), dx(i))
  27.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  28.         imoved = 0
  29.         FOR j = i + 1 TO balls
  30.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  31.                 imoved = 1
  32.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  33.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  34.                 'update new dx, dy for i and j balls
  35.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  36.                 power = .7 * (power1 + power2) / 2
  37.                 dx(i) = power * COS(a(i))
  38.                 dy(i) = power * SIN(a(i))
  39.                 dx(j) = power * COS(a(j))
  40.                 dy(j) = power * SIN(a(j))
  41.                 x(i) = x(i) + dx(i)
  42.                 y(i) = y(i) + dy(i)
  43.                 x(j) = x(j) + dx(j)
  44.                 y(j) = y(j) + dy(j)
  45.                 snd 120 + r(i) * 250, r(j) * .15
  46.                 EXIT FOR
  47.             END IF
  48.         NEXT
  49.         IF imoved = 0 THEN
  50.             x(i) = x(i) + dx(i)
  51.             y(i) = y(i) + dy(i)
  52.         END IF
  53.         IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN
  54.             x(i) = xmax / 2 + rand(0, 100) * rdir
  55.             y(i) = 0
  56.             dx(i) = rand(0, 3) * rdir
  57.             dy(i) = 1
  58.         END IF
  59.         IF y(i) + r(i) > ymax + gravity THEN snd (y(i) + r(i) - (ymax + gravity)) * 100 + r(i) * 20, 6 'only when hits floor, not for rolling balls
  60.         IF y(i) + r(i) > ymax THEN y(i) = ymax - r(i): dy(i) = dy(i) * -.7: x(i) = x(i) + .1 * dx(i)
  61.  
  62.         FOR rad = r(i) TO 1 STEP -1
  63.             COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  64.             fcirc x(i), y(i), rad
  65.         NEXT
  66.     NEXT
  67.     _DISPLAY
  68.     _LIMIT 20
  69.  
  70. FUNCTION rand (lo, hi)
  71.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  72.  
  73. FUNCTION rdir ()
  74.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  75.  
  76. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  77. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  78.     DIM subRadius AS LONG, RadiusError AS LONG
  79.     DIM X AS LONG, Y AS LONG
  80.  
  81.     subRadius = ABS(R)
  82.     RadiusError = -subRadius
  83.     X = subRadius
  84.     Y = 0
  85.  
  86.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  87.  
  88.     ' Draw the middle span here so we don't draw it twice in the main loop,
  89.     ' which would be a problem with blending turned on.
  90.     LINE (CX - X, CY)-(CX + X, CY), , BF
  91.  
  92.     WHILE X > Y
  93.         RadiusError = RadiusError + Y * 2 + 1
  94.         IF RadiusError >= 0 THEN
  95.             IF X <> Y + 1 THEN
  96.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  97.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  98.             END IF
  99.             X = X - 1
  100.             RadiusError = RadiusError - X * 2
  101.         END IF
  102.         Y = Y + 1
  103.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  104.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  105.     WEND
  106.  
  107. SUB snd (frq, dur)
  108.     SOUND frq / 2.2, dur * .01
  109.  

FellippeHeitor

  • Guest
Re: Dropping Balls
« Reply #3 on: April 01, 2018, 07:19:26 pm »
Love the sound synthesis with SOUND!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #4 on: April 03, 2018, 05:39:05 pm »
Dynamically built pyramid pile, thanks to STxAxTIC's help:
Code: QB64: [Select]
  1. _TITLE "Dropping Balls pile attempt bplus 2018-04-03"
  2. 'attempt to build pile by adjusting drop rate, elasticity, gravity
  3. ' remove sound and adjust dropping to center of screen
  4.  
  5.  
  6.  
  7. ' built from Dropping balls 4 w snd and STATIC created 2018-04-3
  8. ' add STATIC's moving ball before figuring bounce from collision
  9. ' which was a mod of Dropping Balls 2 w sound posted 2018-03-31
  10. CONST xmax = 800
  11. CONST ymax = 600
  12.  
  13. SCREEN _NEWIMAGE(xmax, ymax, 32)
  14. _SCREENMOVE 360, 60
  15. elastic = .5
  16. gravity = .5
  17. balls = 160
  18. DIM x(balls), y(balls), r(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  19. FOR i = 1 TO balls
  20.     r(i) = 15
  21.     x(i) = xmax / 2 + (i MOD 2) * 8 - 4
  22.     y(i) = 0
  23.     dx(i) = 0
  24.     dy(i) = 3
  25.     rr(i) = rand(200, 255)
  26.     gg(i) = rand(200, 255)
  27.     bb(i) = rand(200, 255)
  28. maxBall = 0
  29.     CLS
  30.     loopCnt = loopCnt + 1
  31.     IF loopCnt MOD 17 = 0 THEN
  32.         IF maxBall < balls THEN maxBall = maxBall + 1
  33.     END IF
  34.     COLOR _RGB32(255, 255, 255)
  35.     _PRINTSTRING (100, 10), "Balls:" + STR$(maxBall)
  36.  
  37.     FOR i = 1 TO maxBall
  38.         'ready for collision
  39.         dy(i) = dy(i) + gravity
  40.         a(i) = _ATAN2(dy(i), dx(i))
  41.  
  42.         imoved = 0
  43.         FOR j = i + 1 TO maxBall
  44.  
  45.             ' The following is STATIC's adjustment of ball positions if overlapping
  46.             ' before calcultion of new positions from collision
  47.             ' Displacement vector and its magnitude.  Thanks STxAxTIC !
  48.             nx = x(j) - x(i)
  49.             ny = y(j) - y(i)
  50.             nm = SQR(nx ^ 2 + ny ^ 2)
  51.             IF nm < 1 + r(i) + r(j) THEN
  52.                 nx = nx / nm
  53.                 ny = ny / nm
  54.  
  55.                 ' Regardless of momentum exchange, separate the balls along the lone connecting them.
  56.                 DO WHILE nm < 1 + r(i) + r(j)
  57.                     flub = .001 '* RND
  58.  
  59.                     x(j) = x(j) + flub * nx
  60.                     y(j) = y(j) + flub * ny
  61.  
  62.                     x(i) = x(i) - flub * nx
  63.                     y(i) = y(i) - flub * ny
  64.  
  65.                     nx = x(j) - x(i)
  66.                     ny = y(j) - y(i)
  67.                     nm = SQR(nx ^ 2 + ny ^ 2)
  68.                     nx = nx / nm
  69.                     ny = ny / nm
  70.                 LOOP
  71.  
  72.  
  73.                 imoved = 1
  74.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  75.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  76.  
  77.                 'update new dx, dy for i and j balls
  78.                 power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  79.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  80.                 power = elastic * (power1 + power2) / 2
  81.                 dx(i) = power * COS(a(i))
  82.                 dy(i) = power * SIN(a(i))
  83.                 dx(j) = power * COS(a(j))
  84.                 dy(j) = power * SIN(a(j))
  85.                 x(i) = x(i) + dx(i)
  86.                 y(i) = y(i) + dy(i)
  87.                 x(j) = x(j) + dx(j)
  88.                 y(j) = y(j) + dy(j)
  89.                 'EXIT FOR
  90.             END IF
  91.         NEXT
  92.         IF imoved = 0 THEN
  93.             x(i) = x(i) + dx(i)
  94.             y(i) = y(i) + dy(i)
  95.         END IF
  96.         IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN
  97.             x(i) = xmax / 2 + (i MOD 2) * 4 * r(i) - 2 * r(i)
  98.             y(i) = 0
  99.             dx(i) = 0
  100.             dy(i) = 3
  101.         END IF
  102.  
  103.         IF y(i) + r(i) > ymax THEN y(i) = ymax - r(i): dy(i) = -dy(i) * elastic '???: x(i) = x(i) + .1 * dx(i)
  104.  
  105.         FOR rad = r(i) TO 1 STEP -1
  106.             COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  107.             fcirc x(i), y(i), rad
  108.         NEXT
  109.     NEXT
  110.     _DISPLAY
  111.     _LIMIT 20
  112.  
  113. FUNCTION rand (lo, hi)
  114.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  115.  
  116. FUNCTION rdir ()
  117.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  118.  
  119. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  120. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  121.     DIM subRadius AS LONG, RadiusError AS LONG
  122.     DIM X AS LONG, Y AS LONG
  123.  
  124.     subRadius = ABS(R)
  125.     RadiusError = -subRadius
  126.     X = subRadius
  127.     Y = 0
  128.  
  129.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  130.  
  131.     ' Draw the middle span here so we don't draw it twice in the main loop,
  132.     ' which would be a problem with blending turned on.
  133.     LINE (CX - X, CY)-(CX + X, CY), , BF
  134.  
  135.     WHILE X > Y
  136.         RadiusError = RadiusError + Y * 2 + 1
  137.         IF RadiusError >= 0 THEN
  138.             IF X <> Y + 1 THEN
  139.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  140.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  141.             END IF
  142.             X = X - 1
  143.             RadiusError = RadiusError - X * 2
  144.         END IF
  145.         Y = Y + 1
  146.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  147.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  148.     WEND
  149.  
  150. SUB snd (frq, dur)
  151.     SOUND frq / 2.2, dur * .01
  152.  
  153.  
Cherry picked pile.PNG
* Cherry picked pile.PNG (Filesize: 69.12 KB, Dimensions: 804x629, Views: 457)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #5 on: April 03, 2018, 11:19:54 pm »
For perfect pyramids, I offer this:
Code: QB64: [Select]
  1. _TITLE "pyramid of circles 2 by bplus 2018-04-03"
  2. CONST xmax = 800
  3. CONST ymax = 600
  4.  
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. _SCREENMOVE 360, 60
  7. DIM SHARED px(154), py(154), rr(154), gg(154), bb(154)
  8. FOR i = 1 TO 153
  9.     rr(i) = (RND * 55 + 200)
  10.     gg(i) = RND * 55 + 200 * INT(RND * 2)
  11.     bb(i) = RND * 55 + 200
  12. 'let n = number of circles at base of pile
  13. n = 10
  14.  
  15. 'let r = radius of each circle
  16. r = 20
  17.  
  18. 'let base be total length of pile
  19. baseLength = 2 * r * n
  20.  
  21. ' center pyramid in middle of screen
  22. startx = (xmax - baseLength) / 2
  23.  
  24. 'stacking circles that form equilateral triangles at their origins have a height change of
  25. deltaHeight = r * 3 ^ .5 'r times the sqr(3)
  26.  
  27. FOR row = n TO 1 STEP -1
  28.     IF row = n THEN y = ymax - r - 1 ELSE y = y - deltaHeight
  29.     FOR col = 1 TO row
  30.         x = startx + col * 2 * r - r
  31.         index = index + 1
  32.         target x, y, index
  33.     NEXT
  34.     startx = startx + r
  35.  
  36. SUB target (x, y, i)
  37.     nx = x: ny = y
  38.     ra = _PI(1 / (INT(RND * 7) + 4) + 1 / 2)
  39.     dx = 10 * COS(ra)
  40.     dy = 10 * SIN(ra)
  41.     bounce = 0: rb = INT(RND * 7) + 3
  42.     WHILE bounce < rb
  43.         IF nx + dx > xmax - 20 OR nx + dx < 20 THEN dx = -dx: bounce = bounce + 1
  44.         IF ny + dy > ymax - 20 OR ny + dy < 20 THEN dy = -dy: bounce = bounce + 1
  45.         nx = nx + dx: ny = ny + dy
  46.     WEND
  47.     dx = -dx: dy = -dy
  48.     WHILE bounce > 0
  49.         IF nx + dx > xmax - 20 OR nx + dx < 20 THEN dx = -dx: bounce = bounce - 1
  50.         IF ny + dy > ymax - 20 OR ny + dy < 20 THEN dy = -dy: bounce = bounce - 1
  51.         nx = nx + dx: ny = ny + dy
  52.         CLS
  53.         FOR j = 1 TO i - 1
  54.             FOR rad = 20 TO 1 STEP -1
  55.                 COLOR _RGB32(rr(j) - 10 * rad, gg(j) - 10 * rad, bb(j) - 10 * rad)
  56.                 fcirc px(j), py(j), rad
  57.             NEXT
  58.         NEXT
  59.         FOR rad = 20 TO 1 STEP -1
  60.             COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  61.             fcirc nx, ny, rad
  62.         NEXT
  63.         _DISPLAY
  64.         _LIMIT 200
  65.     WEND
  66.     'last bit
  67.     WHILE SQR((nx - x) ^ 2 + (ny - y) ^ 2) > 20
  68.         nx = nx + dx
  69.         ny = ny + dy
  70.         CLS
  71.         FOR j = 1 TO i - 1
  72.             FOR rad = 20 TO 1 STEP -1
  73.                 COLOR _RGB32(rr(j) - 10 * rad, gg(j) - 10 * rad, bb(j) - 10 * rad)
  74.                 fcirc px(j), py(j), rad
  75.             NEXT
  76.         NEXT
  77.         FOR rad = 20 TO 1 STEP -1
  78.             COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  79.             fcirc nx, ny, rad
  80.         NEXT
  81.         _DISPLAY
  82.         _LIMIT 200
  83.     WEND
  84.  
  85.     CLS
  86.     FOR j = 1 TO i - 1
  87.         FOR rad = 20 TO 1 STEP -1
  88.             COLOR _RGB32(rr(j) - 10 * rad, gg(j) - 10 * rad, bb(j) - 10 * rad)
  89.             fcirc px(j), py(j), rad
  90.         NEXT
  91.     NEXT
  92.     FOR rad = 20 TO 1 STEP -1
  93.         COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  94.         fcirc x, y, rad
  95.     NEXT
  96.     _DISPLAY
  97.     _DELAY .25
  98.     px(i) = x: py(i) = y
  99.  
  100.  
  101. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  102. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  103.     DIM subRadius AS LONG, RadiusError AS LONG
  104.     DIM X AS LONG, Y AS LONG
  105.  
  106.     subRadius = ABS(R)
  107.     RadiusError = -subRadius
  108.     X = subRadius
  109.     Y = 0
  110.  
  111.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  112.  
  113.     ' Draw the middle span here so we don't draw it twice in the main loop,
  114.     ' which would be a problem with blending turned on.
  115.     LINE (CX - X, CY)-(CX + X, CY), , BF
  116.  
  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), , BF
  122.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , 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), , BF
  129.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  130.     WEND
  131.  
  132.  
  133.  
  134.  
Pyramid of circles 2.PNG
* Pyramid of circles 2.PNG (Filesize: 40.79 KB, Dimensions: 804x624, Views: 425)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #6 on: April 04, 2018, 09:36:52 am »
Dang! I could of drawn a picture with the colored balls AND have the pyramid magically appear as from all the balls flying around slowly finding their resting place. BBL





Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Dropping Balls
« Reply #7 on: June 10, 2018, 10:35:11 am »
How hard would it be to adapt for an hourglass simulator?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #8 on: June 10, 2018, 11:41:07 am »
How hard would it be to adapt for an hourglass simulator?

Wow, it's been just a couple of months since I have posted this but seems like a year. BTW I did finish the BBL later thing and was not impressed and other things came up, so apologies for that if anyone was waiting....

Sand in 2D is easy from this, if I recall, just adjust the bounce factors. But if you want a really cool 3D sim, Ashish would be likely of great help with the GL stuff.

Glass-like graphics effects might be interesting to explore! Does anyone have some simple models?

Oh Petr did some transparency stuff for buttons but need shiny glass reflecting surround colors if not images fit onto the glass surface and distorted according to glass shape. (Yikes more 3D stuff!)
« Last Edit: June 10, 2018, 11:44:53 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #9 on: June 10, 2018, 04:32:34 pm »
How is this for a nice effect?

...

I like this much better:
https://www.qb64.org/forum/index.php?topic=262.0

[banned user], if you modify my code could you write that somewhere on or around title.

I don't understand the need or use of map!

And what have you against the sounds?  ;D
« Last Edit: June 10, 2018, 04:48:39 pm by bplus »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Dropping Balls
« Reply #10 on: June 10, 2018, 07:45:21 pm »
Here's a draft, several flaws though.

Code: QB64: [Select]
  1. _TITLE "Dropping Balls 2 w sound by vince 2018-03-31"
  2. ' attempt to fix
  3. CONST xmax = 800
  4. CONST ymax = 600
  5.  
  6. pi = 3.1415926
  7.  
  8. SCREEN _NEWIMAGE(xmax, ymax, 32)
  9. '_SCREENMOVE 360, 60
  10.  
  11. gravity = 1
  12. balls = 1000
  13. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  14.  
  15.  
  16. screen ,,1,0
  17. line (0,0)-(800,600),_rgb(0,0,0),bf
  18. a=0
  19. xx = 150*sin(2*a)
  20. yy = 300*cos(a)
  21. pset (xx+400,yy+300), _rgb(100,100,100)
  22. for a = 0 to 2*pi step 0.01
  23.         xx = 150*sin(2*a)
  24.         yy = 300*cos(a)
  25.         line -(xx+400,yy+300), _rgb(100,100,100)
  26.  
  27. paint (400,150),_rgb(100,100,100)
  28. paint (400,450),_rgb(100,100,100)
  29. line (380,150)-(420,450),_rgb(100,100,100),bf
  30.  
  31. pcopy 1,0
  32.  
  33.  
  34. balls = 0
  35. for yy = 50 to 300-10 step 8
  36. for xx = 10 to 600-10 step 8
  37.         if point(xx,yy) <> _rgb(0,0,0) then
  38.                 balls = balls + 1
  39.  
  40.                 r(balls) = 3
  41.                 x(balls) = xx
  42.                 y(balls) = yy
  43.                 c(balls) = 15
  44.                 dx(balls) = rand(0, 3) * rdir
  45.                 dy(balls) = 15
  46.  
  47.                 rr(balls) = 255
  48.                 gg(balls) = 255
  49.                 bb(balls) = 0
  50.         end if
  51.  
  52. screen ,,0,0
  53.  
  54. 'FOR i = 1 TO balls
  55. '    r(i) = rand(15, 20)
  56. '    x(i) = rand(r(i), xmax - r(i))
  57. '    y(i) = rand(r(i), ymax - r(i))
  58. '    c(i) = rand(1, 15)
  59. '    dx(i) = rand(0, 3) * rdir
  60. '    dy(i) = rand(10, 20)
  61. '    rr(i) = rand(200, 255)
  62. '    gg(i) = rand(200, 255)
  63. '    bb(i) = rand(200, 255)
  64. 'NEXT
  65.         pcopy 1,0
  66.     FOR i = 1 TO balls
  67.         'ready for collision
  68.         dy(i) = dy(i) + gravity
  69.         a(i) = _ATAN2(dy(i), dx(i))
  70.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  71.         imoved = 0
  72.         FOR j = i + 1 TO balls
  73.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  74.                 imoved = 1
  75.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  76.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  77.                 'update new dx, dy for i and j balls
  78.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  79.                 power = .7 * (power1 + power2) / 2
  80.                 dx(i) = power * COS(a(i))
  81.                 dy(i) = power * SIN(a(i))
  82.                 dx(j) = power * COS(a(j))
  83.                 dy(j) = power * SIN(a(j))
  84.                 x(i) = x(i) + dx(i)
  85.                 y(i) = y(i) + dy(i)
  86.                 x(j) = x(j) + dx(j)
  87.                 y(j) = y(j) + dy(j)
  88.                 snd 120 + r(i) * 250, r(j) * .15
  89.                 EXIT FOR
  90.             END IF
  91.         NEXT
  92.         IF imoved = 0 THEN
  93.             x(i) = x(i) + dx(i)
  94.             y(i) = y(i) + dy(i)
  95.         END IF
  96.         'IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN
  97.         '    x(i) = xmax / 2 + rand(0, 100) * rdir
  98.         '    y(i) = 0
  99.         '    dx(i) = rand(0, 3) * rdir
  100.         '    dy(i) = 1
  101.         'END IF
  102.         'IF y(i) + r(i) > ymax + gravity THEN snd (y(i) + r(i) - (ymax + gravity)) * 100 + r(i) * 20, 6 'only when hits floor, not for rolling balls
  103.                 screen ,,1,0
  104.                 '
  105.         IF point(x(i)+r(i),y(i))<>_rgb(100,100,100) THEN
  106.                         'y(i) = ymax - r(i)
  107.                         x(i) = x(i) - r(i)
  108.                         dy(i) = dy(i) * -.7
  109.                         dx(i) = dx(i) * -.7
  110.                         'x(i) = x(i) + .1 * dx(i)
  111.                 elseif  point(x(i)-r(i),y(i))<>_rgb(100,100,100) then
  112.                         x(i) = x(i) + r(i)
  113.                         dy(i) = dy(i) * -.7
  114.                         dx(i) = dx(i) * -.7
  115.                 elseif  point(x(i),y(i)+r(i))<>_rgb(100,100,100) then
  116.                         y(i) = y(i) - r(i)
  117.                         dy(i) = dy(i) * -.7
  118.                         dx(i) = dx(i) * -.7
  119.                 elseif  point(x(i),y(i)-r(i))<>_rgb(100,100,100) then
  120.                         y(i) = y(i) + r(i)
  121.                         dy(i) = dy(i) * -.7
  122.                         dx(i) = dx(i) * -.7
  123.                 end if
  124.                 screen ,,0,0
  125.  
  126.         FOR rad = r(i) TO 1 STEP -1
  127.             COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  128.             fcirc x(i), y(i), rad
  129.         NEXT
  130.     NEXT
  131.     _DISPLAY
  132.     _LIMIT 20
  133.  
  134. FUNCTION rand (lo, hi)
  135.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  136.  
  137. FUNCTION rdir ()
  138.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  139.  
  140. 'Steve McNeil's  copied from his forum  note: Radius is too common a name ;-)
  141. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  142.     DIM subRadius AS LONG, RadiusError AS LONG
  143.     DIM X AS LONG, Y AS LONG
  144.  
  145.     subRadius = ABS(R)
  146.     RadiusError = -subRadius
  147.     X = subRadius
  148.     Y = 0
  149.  
  150.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  151.  
  152.     ' Draw the middle span here so we don't draw it twice in the main loop,
  153.     ' which would be a problem with blending turned on ;-)
  154.     LINE (CX - X, CY)-(CX + X, CY), , BF
  155.  
  156.     WHILE X > Y
  157.         RadiusError = RadiusError + Y * 2 + 1
  158.         IF RadiusError >= 0 THEN
  159.             IF X <> Y + 1 THEN
  160.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  161.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  162.             END IF
  163.             X = X - 1
  164.             RadiusError = RadiusError - X * 2
  165.         END IF
  166.         Y = Y + 1
  167.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  168.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  169.     WEND
  170.  
  171. SUB snd (frq, dur)
  172.     'SOUND frq / 2.2, dur * .01
  173.  
  174.  
  175.  
hg.png
* hg.png (Filesize: 5.69 KB, Dimensions: 800x600, Views: 440)

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Dropping Balls
« Reply #11 on: June 10, 2018, 08:26:37 pm »
As requested by Phil

Code: QB64: [Select]
  1. _TITLE "Dropping Balls pile attempt bplus ;-)"
  2. 'attempt to build pile by adjusting drop rate, elasticity, gravity
  3. ' remove sound and adjust dropping to center of screen
  4.  
  5. ' built from Dropping balls 4 w snd and STATIC created 2018-04-3
  6. ' add STATIC's moving ball before figuring bounce from collision
  7. ' which was a mod of Dropping Balls 2 w sound posted 2018-03-31
  8. CONST xmax = 800
  9. CONST ymax = 600
  10.  
  11. pi = 3.1415926
  12.  
  13. SCREEN _NEWIMAGE(xmax, ymax, 32)
  14. _SCREENMOVE 360, 60
  15. elastic = .5
  16. gravity = .5
  17. balls = 160
  18. DIM x(balls), y(balls), r(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  19.  
  20. dim aa(balls)
  21. dim aaa(balls)
  22. FOR i = 1 TO balls
  23.     r(i) = 50
  24.     x(i) = xmax / 2 + (i MOD 2) * 8 - 4
  25.     y(i) = 0
  26.     dx(i) = 0
  27.     dy(i) = 3
  28.     rr(i) = rand(200, 255)
  29.     gg(i) = rand(200, 255)
  30.     bb(i) = rand(200, 255)
  31.         aa(i) = 2*pi*rnd
  32.         aaa(i) = 0
  33.         'rnd*0.1-0.05
  34. maxBall = 0
  35.  
  36. t = timer
  37.     CLS
  38.     'loopCnt = loopCnt + 1
  39.     'IF loopCnt MOD 17 = 0 THEN
  40.         IF maxBall < balls and timer-t>1 THEN
  41.                 maxBall = maxBall + 1
  42.                 t = timer
  43.         end if
  44.  
  45.  
  46.     'END IF
  47.     COLOR _RGB32(255, 255, 255)
  48.     _PRINTSTRING (100, 10), "Balls:" + STR$(maxBall)
  49.  
  50.     FOR i = 1 TO maxBall
  51.                 aa(i) = aa(i) + aaa(i)
  52.  
  53.                 if abs(aaa(i)) > 0.5 then aaa(i)=aaa(i)+ sgn(aaa(i))*0.02
  54.  
  55.         'ready for collision
  56.         dy(i) = dy(i) + gravity
  57.         a(i) = _ATAN2(dy(i), dx(i))
  58.  
  59.         imoved = 0
  60.         FOR j = i + 1 TO maxBall
  61.  
  62.             ' The following is STATIC's adjustment of ball positions if overlapping
  63.             ' before calcultion of new positions from collision
  64.             ' Displacement vector and its magnitude.  Thanks STxAxTIC !
  65.             nx = x(j) - x(i)
  66.             ny = y(j) - y(i)
  67.             nm = SQR(nx ^ 2 + ny ^ 2)
  68.             IF nm < 1 + r(i) + r(j) THEN
  69.                 nx = nx / nm
  70.                 ny = ny / nm
  71.  
  72.                 ' Regardless of momentum exchange, separate the balls along the lone connecting them.
  73.                 DO WHILE nm < 1 + r(i) + r(j)
  74.                     flub = .001 '* RND
  75.  
  76.                     x(j) = x(j) + flub * nx
  77.                     y(j) = y(j) + flub * ny
  78.  
  79.                     x(i) = x(i) - flub * nx
  80.                     y(i) = y(i) - flub * ny
  81.  
  82.                     nx = x(j) - x(i)
  83.                     ny = y(j) - y(i)
  84.                     nm = SQR(nx ^ 2 + ny ^ 2)
  85.                     nx = nx / nm
  86.                     ny = ny / nm
  87.                 LOOP
  88.  
  89.  
  90.                 imoved = 1
  91.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  92.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  93.  
  94.                 'update new dx, dy for i and j balls
  95.                 power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  96.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  97.                 power = elastic * (power1 + power2) / 2
  98.                 dx(i) = power * COS(a(i))
  99.                 dy(i) = power * SIN(a(i))
  100.                 dx(j) = power * COS(a(j))
  101.                 dy(j) = power * SIN(a(j))
  102.                 x(i) = x(i) + dx(i)
  103.                 y(i) = y(i) + dy(i)
  104.                 x(j) = x(j) + dx(j)
  105.                 y(j) = y(j) + dy(j)
  106.                 'EXIT FOR
  107.  
  108.                                 aaa(i) = rnd*0.2-0.1
  109.             END IF
  110.         NEXT
  111.         IF imoved = 0 THEN
  112.             x(i) = x(i) + dx(i)
  113.             y(i) = y(i) + dy(i)
  114.         END IF
  115.         IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN
  116.             x(i) = xmax / 2 + (i MOD 2) * 4 * r(i) - 2 * r(i)
  117.             y(i) = 0
  118.             dx(i) = 0
  119.             dy(i) = 3
  120.  
  121.                                 aaa(i) = rnd*0.2-0.1
  122.         END IF
  123.  
  124.         IF y(i) + r(i) > ymax THEN
  125.                 y(i) = ymax - r(i): dy(i) = -dy(i) * elastic '???: x(i) = x(i) + .1 * dx(i)
  126.  
  127.                                 aaa(i) = rnd*0.2-0.1
  128.                 end if
  129.  
  130.         FOR rad = r(i) TO 1 STEP -1
  131.             COLOR _RGB32(rr(i) - 3 * rad, gg(i) - 3 * rad, bb(i) - 3 * rad)
  132.             fcirc x(i), y(i), rad
  133.         NEXT
  134.                 textrot x(i), y(i), ltrim$(str$(i)), aa(i), aa(i)
  135.  
  136.     NEXT
  137.     _DISPLAY
  138.     _LIMIT 30
  139.  
  140.  
  141. sub textrot (x0 as integer, y0 as integer, s as string, a as double, b as double)
  142.  
  143.         dim img as long
  144.         img = _newimage(16,16,32)
  145.  
  146.         _dest img
  147.         line (0,0)-(16,16),_rgb(0,0,0),bf
  148.         color _rgb(255,255,255)
  149.         _printstring (0,0),left$(s$,2),img
  150.  
  151.         _source img
  152.         _dest 0
  153.         dim z as long
  154.         r = 0.5
  155.         for yy = -16/r to 16/r
  156.         for xx = -16/r to 16/r
  157.                 xxx=r*xx*cos(a)+r*yy*sin(a)+8
  158.                 yyy=r*yy*cos(a)-r*xx*sin(a)+8
  159.                 if xxx<15 and xxx>=0 then
  160.                 if yyy<15 and yyy>=0 then
  161.                 z = point(xxx,yyy)
  162.                 if z = _rgb(255,255,255) then
  163.                         pset (x0+xx,y0+yy),_rgb(0,0,0)
  164.                 end if
  165.                 end if
  166.                 end if
  167.         next
  168.         next
  169.  
  170.         _freeimage(img)
  171.  
  172.         _source 0
  173.  
  174. FUNCTION rand (lo, hi)
  175.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  176.  
  177. FUNCTION rdir ()
  178.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  179.  
  180. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  181. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  182.     DIM subRadius AS LONG, RadiusError AS LONG
  183.     DIM X AS LONG, Y AS LONG
  184.  
  185.     subRadius = ABS(R)
  186.     RadiusError = -subRadius
  187.     X = subRadius
  188.     Y = 0
  189.  
  190.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  191.  
  192.     ' Draw the middle span here so we don't draw it twice in the main loop,
  193.     ' which would be a problem with blending turned on.
  194.     LINE (CX - X, CY)-(CX + X, CY), , BF
  195.  
  196.     WHILE X > Y
  197.         RadiusError = RadiusError + Y * 2 + 1
  198.         IF RadiusError >= 0 THEN
  199.             IF X <> Y + 1 THEN
  200.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  201.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  202.             END IF
  203.             X = X - 1
  204.             RadiusError = RadiusError - X * 2
  205.         END IF
  206.         Y = Y + 1
  207.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  208.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  209.     WEND
  210.  
  211. SUB snd (frq, dur)
  212.     'SOUND frq / 2.2, dur * .01
  213.  
« Last Edit: June 10, 2018, 08:55:35 pm by v »

FellippeHeitor

  • Guest
Re: Dropping Balls
« Reply #12 on: June 10, 2018, 08:28:22 pm »
I'm stunned! That was awesome, Vince!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dropping Balls
« Reply #13 on: June 10, 2018, 08:36:39 pm »
Hi [banned user],

The mirror effect helps explain what I first saw. I like silence too, and the song and unique sounds. Thanks for adding notes to code.


Hi V,

The hour glass is good start, ball containment seems first priority but some are being contained, I will look into what you are doing with that more closely.

The 2nd one with the numbers rotated on balls is cool and it would be really interesting if a constant but different spin were added to each ball as they move around. Nice one guys!

I have to confess, when I saw hour glass running I was thinking lottery and the ping pong balls WITH NUMBERS flying around! :D
« Last Edit: June 10, 2018, 08:40:05 pm by bplus »

FellippeHeitor

  • Guest
Re: Dropping Balls
« Reply #14 on: June 10, 2018, 08:40:24 pm »
I have to confess, when I saw hour glass running I was thinking lottery and the ping pong balls WITH NUMBERS flying around! :D

Exactly what I had in mind when I proposed it too!