Author Topic: Boing  (Read 3745 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Boing
« on: January 08, 2019, 04:31:09 pm »
Code: QB64: [Select]
  1. _TITLE "Mouse down, drag ball, release...  Boing" 'B+ 2019-01-08 from
  2. 'boing.bas for SmallBASIC 2015-07-25 MGA/B+
  3. 'coloring mods
  4.  
  5. CONST xmax = 1200
  6. CONST ymax = 700
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8.  
  9. DIM s(1 TO 4, 1 TO 2)
  10. s(1, 1) = 0: s(1, 2) = 50
  11. s(2, 1) = 0: s(2, 2) = ymax - 50
  12. s(3, 1) = xmax + 30: s(3, 2) = 50
  13. s(4, 1) = xmax + 30: s(4, 2) = ymax - 50
  14. oldtx = 0: oldtyty = 0: da = .03
  15. boingx = 0: boingy = 0
  16.     mb = _MOUSEBUTTON(1)
  17.     IF mb THEN
  18.         tx = _MOUSEX + 20
  19.         ty = _MOUSEY
  20.     ELSE
  21.         tx = xmax / 2
  22.         ty = ymax / 2
  23.         IF tx <> oldtx OR ty <> oldty THEN
  24.             boingx = 3 * (tx - oldtx) / 4
  25.             boingy = 3 * (ty - oldty) / 4
  26.         ELSE
  27.             boingx = -3 * boingx / 4
  28.             boingy = -3 * boingy / 4
  29.         END IF
  30.         tx = tx + boingx
  31.         ty = ty + boingy
  32.     END IF
  33.     a = 0
  34.     oldtx = tx
  35.     oldty = ty
  36.     CLS
  37.     FOR corner = 1 TO 4
  38.         s1x = s(corner, 1)
  39.         s1y = s(corner, 2)
  40.         dx = (tx - s1x) / 2000
  41.         dy = (ty - s1y) / 2000
  42.         x = tx - 20
  43.         y = ty
  44.         FOR i = 1 TO 2000
  45.             sx = 20 * COS(a) + x
  46.             sy = 20 * SIN(a) + y
  47.             LINE (sx, sy + 5)-(sx + 4, sy + 5), _RGB32(118, 118, 118), BF
  48.             LINE (sx, sy + 4)-(sx + 4, sy + 4), _RGB32(148, 148, 148), BF
  49.             LINE (sx, sy + 3)-(sx + 4, sy + 3), _RGB32(238, 238, 238), BF
  50.             LINE (sx, sy + 2)-(sx + 4, sy + 3), _RGB32(208, 208, 208), BF
  51.             LINE (sx, sy + 1)-(sx + 4, sy + 1), _RGB32(168, 168, 168), BF
  52.             LINE (sx, sy)-(sx + 4, sy), _RGB32(108, 108, 108), BF
  53.             LINE (sx, sy - 1)-(sx + 4, sy - 1), _RGB32(68, 68, 68), BF
  54.             x = x - dx: y = y - dy
  55.             a = a + da
  56.         NEXT
  57.     NEXT
  58.     FOR r = 50 TO 1 STEP -1
  59.         g = (50 - r) * 5 + 5
  60.         COLOR _RGB32(g, g, g)
  61.         fcirc tx - 20, ty, r
  62.     NEXT
  63.     _DISPLAY
  64.     _LIMIT 15
  65.  
  66. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  67. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  68.     DIM subRadius AS LONG, RadiusError AS LONG
  69.     DIM X AS LONG, Y AS LONG
  70.  
  71.     subRadius = ABS(R)
  72.     RadiusError = -subRadius
  73.     X = subRadius
  74.     Y = 0
  75.  
  76.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  77.  
  78.     ' Draw the middle span here so we don't draw it twice in the main loop,
  79.     ' which would be a problem with blending turned on.
  80.     LINE (CX - X, CY)-(CX + X, CY), , BF
  81.  
  82.     WHILE X > Y
  83.         RadiusError = RadiusError + Y * 2 + 1
  84.         IF RadiusError >= 0 THEN
  85.             IF X <> Y + 1 THEN
  86.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  87.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  88.             END IF
  89.             X = X - 1
  90.             RadiusError = RadiusError - X * 2
  91.         END IF
  92.         Y = Y + 1
  93.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  94.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  95.     WEND
  96.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Boing
« Reply #1 on: January 08, 2019, 05:19:48 pm »
Very nice, Bplus! Very good idea, to do something as this!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Boing
« Reply #2 on: January 08, 2019, 09:41:06 pm »
Like I told the kangaroo, just hop, you don't have to go say, boing! boing! boing!

That was cool!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Boing
« Reply #3 on: January 09, 2019, 05:35:51 am »
Perfect bplus! The physics looks good. What are concepts behind rendering that spring?
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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

FellippeHeitor

  • Guest
Re: Boing
« Reply #4 on: January 09, 2019, 11:14:24 am »
Very impressive work, bplus. If I had seen a screenshot first I'd never have believed you weren't using external images for this.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boing
« Reply #5 on: January 09, 2019, 11:25:57 am »
Thanks guys!

Ashish, The physics is just math, take 3/4's last bounce for next bounce.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Boing
« Reply #6 on: January 09, 2019, 05:41:55 pm »
Great job  Bplus

that ball is unbreakable!
As I move it by leftclick of mouse so I hear the metallic sound of the 4 cords. :-)
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Boing
« Reply #7 on: January 09, 2019, 06:30:31 pm »
Hmmm, I just realized, another program by Mark involving balls. Me, I make AI programs to organize files I download. After three previous downloads, it renamed the folder as, "Mark's Balls" and for some odd reason, my antivirus program keeps scanning it.

I'd love to know that 3/4 effect is for real. It certainly seems like a realistic situation, but I would think the math should be based on some form of geometric progression? Oh well, where's Bill when we need him?

Pete :D

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Boing
« Reply #8 on: January 09, 2019, 07:25:53 pm »
Really neat, I can't help but think that if you just click on the ball in the center it would be like punching it, and have it 'shrink away' and then come boinging back forward! split the R and B colors a few pixels as it gets bigger and pop on your old-skool 3d glasses for a show!
Granted after becoming radioactive I only have a half-life!