Author Topic: Dropping Balls  (Read 23206 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Dropping Balls
« Reply #15 on: June 10, 2018, 09:02:38 pm »
Hey great minds think alike!  oops... ;D


Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: Dropping Balls
« Reply #16 on: June 11, 2018, 08:16:29 am »
@vince
That hourglass one simulation was good!
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 TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: Dropping Balls
« Reply #17 on: June 11, 2018, 09:34:16 am »
Hy Guys
Hy Vincent

very very fine effect in your mod/demo... but it is outlaw! :-) for gravity law surely....
see image to get into issue....

Thank's to share code
DroppingBalls OUTLAW by Vincent.png
* DroppingBalls OUTLAW by Vincent.png (Filesize: 111.39 KB, Dimensions: 1366x768, Views: 386)
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Dropping Balls
« Reply #18 on: June 11, 2018, 10:33:24 am »
Yes, I found that problem developing in my run too, the problem with modifying over and over... I had that fixed (maybe I should say balanced) in original code by altering the drop point. It also has something to do with elastic = sticky variable the lower the elastic setting the higher the stickiness.
« Last Edit: June 11, 2018, 10:37:13 am by bplus »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: Dropping Balls
« Reply #19 on: June 11, 2018, 01:27:02 pm »
Hy Guys
Hy Vincent

very very fine effect in your mod/demo... but it is outlaw! :-) for gravity law surely....
see image to get into issue....

Thank's to share code

Entirely bplus's and xstatic's fault. I had no part in the physics simulation.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Dropping Balls
« Reply #20 on: June 11, 2018, 02:26:35 pm »
Hy Guys
Hy Vincent

very very fine effect in your mod/demo... but it is outlaw! :-) for gravity law surely....
see image to get into issue....

Thank's to share code

Entirely bplus's and xstatic's fault. I had no part in the physics simulation.

V you have changed the code since I saw it (the problem is now exaggerated! probably due to big increase in Ball Radius), don't blame me for what you do with the code.

Append: I will say also (in your defense) that it is probably quite unexpected that a change in ball radius should effect "the physic's" but this code was modified from original dropping balls to try and get as perfect a pyramid formed and to do that "the physics" was already stretched beyond real world kind (if it was ever close to start).  Also by same logic, STxAxTIC should get 0 blame for what I did with his code.

« Last Edit: June 11, 2018, 04:00:04 pm by bplus »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: Dropping Balls
« Reply #21 on: June 11, 2018, 04:07:40 pm »
I'm joking, bplus. Tempodibasic's riveting analysis warranted the response.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Dropping Balls
« Reply #22 on: June 11, 2018, 04:23:18 pm »
I'm joking, bplus. Tempodibasic's riveting analysis warranted the response.

I was hoping that! but apparently I don't have much faith in my hopes.

Well I really like the numbers on the balls and would like to see them spin independently as they move and the hour glass thing might spin off to lottery thing. (pun intended)

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: Dropping Balls
« Reply #23 on: June 13, 2018, 12:24:48 am »
By the way, bplus, I may as well ask here. Since you make these screensaver/graphic demo type programs (as do I) in a variety of *BASICs (smallbasic, largebasic, purebasic, justbasic, etc), how do you feel about FreeBASIC?  It's pretty much the best for this sort of thing: makes small speedy exes, all the same graphics capability, cleaner syntax, and doesn't obscure advanced features, such as memory access, from the user. There's #lang "fblite" if you want it more QB-like, ie not forcing variable declaration. I suppose it doesn't have the same pull for the old DOS QB45 compatible nostalgia crowd and may not be as beginner friendly as the other BASICs but it is objectively the best.  I would certainly prefer it over QB64 for this type of thing, I wonder if you feel the same.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Dropping Balls
« Reply #24 on: June 13, 2018, 09:23:44 am »
Hi V,

I did try FB before QB64, quite a struggle to get started with it. Since I got into QB64, 50% of my FB no longer works. It is too confusing learning these 2 Basic's so similar and yet... I try running code off their forum and usually something goes wrong for me. Seems to me, QB64 has plenty of graphics devices for interesting screen stuff specially compared to what I had been using previous couple of years.

I started looking into your Hour Glass modification last night, looks like you are flipping between 2 screen pages which threw me (a technique I also found at FB instead of QB64 _DISPLAY which does the screen update in one go). But the one thing that really blew my mind was this:
Code: QB64: [Select]
  1.  
  2. SCREEN , , 1, 0 'hmm never used these before = active page 1, visual page 0
  3. LINE (0, 0)-(800, 600), _RGB(0, 0, 0), BF '>>>>>>>>>>>>>>>>>>>>> If I comment out just this one line
  4. a = 0
  5. xx = 150 * SIN(2 * a)
  6. yy = 300 * COS(a)
  7. PSET (xx + 400, yy + 300), _RGB(100, 100, 100)
  8. FOR a = 0 TO 2 * pi STEP 0.01
  9.     xx = 150 * SIN(2 * a)
  10.     yy = 300 * COS(a)
  11.     LINE -(xx + 400, yy + 300), _RGB(100, 100, 100)
  12.  
  13. PAINT (400, 150), _RGB(100, 100, 100)
  14. PAINT (400, 450), _RGB(100, 100, 100)
  15. LINE (380, 150)-(420, 450), _RGB(100, 100, 100), BF
  16.  
  17. PCOPY 1, 0  'new also to me
  18.  
  19.  
  20. balls = 0
  21. FOR yy = 50 TO 300 - 10 STEP 8
  22.     FOR xx = 10 TO 600 - 10 STEP 8
  23.         IF POINT(xx, yy) <> _RGB(0, 0, 0) THEN
  24.             balls = balls + 1
  25.             '  VVVVVVVVVVVVVVVVVVVVVV stuff here starts giving me errors, for ball array assignment???????
  26.             r(balls) = 3
  27.             x(balls) = xx
  28.             y(balls) = yy
  29.             c(balls) = 15
  30.             dx(balls) = rand(0, 3) * rdir
  31.             dy(balls) = 15
  32.  
  33.             rr(balls) = 255
  34.             gg(balls) = 255
  35.             bb(balls) = 0
  36.         END IF
  37.     NEXT
  38.  
  39. SCREEN , , 0, 0
  40.  
  41.  

How can a simple LINE statement that basically clears the screen be so vital to ball array assignments?

Also why do the balls immediately head to the right of the screen when not contained by the Hour glass figure? Their change in direction, dx (maybe called the x vector), should not be that uniform at all.

« Last Edit: June 13, 2018, 09:37:37 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: Dropping Balls
« Reply #25 on: June 13, 2018, 02:51:10 pm »
Quote
Hi V,

I did try FB before QB64, quite a struggle to get started with it. Since I got into QB64, 50% of my FB no longer works. It is too confusing learning these 2 Basic's so similar and yet... I try running code off their forum and usually something goes wrong for me. Seems to me, QB64 has plenty of graphics devices for interesting screen stuff specially compared to what I had been using previous couple of years.

I started looking into your Hour Glass modification last night, looks like you are flipping between 2 screen pages which threw me (a technique I also found at FB instead of QB64 _DISPLAY which does the screen update in one go). But the one thing that really blew my mind was this:
Code: [Select]

SCREEN , , 1, 0 'hmm never used these before = active page 1, visual page 0
LINE (0, 0)-(800, 600), _RGB(0, 0, 0), BF '>>>>>>>>>>>>>>>>>>>>> If I comment out just this one line
a = 0
xx = 150 * SIN(2 * a)
yy = 300 * COS(a)
PSET (xx + 400, yy + 300), _RGB(100, 100, 100)
FOR a = 0 TO 2 * pi STEP 0.01
    xx = 150 * SIN(2 * a)
    yy = 300 * COS(a)
    LINE -(xx + 400, yy + 300), _RGB(100, 100, 100)
NEXT

PAINT (400, 150), _RGB(100, 100, 100)
PAINT (400, 450), _RGB(100, 100, 100)
LINE (380, 150)-(420, 450), _RGB(100, 100, 100), BF

PCOPY 1, 0  'new also to me


balls = 0
FOR yy = 50 TO 300 - 10 STEP 8
    FOR xx = 10 TO 600 - 10 STEP 8
        IF POINT(xx, yy) <> _RGB(0, 0, 0) THEN
            balls = balls + 1
            '  VVVVVVVVVVVVVVVVVVVVVV stuff here starts giving me errors, for ball array assignment???????
            r(balls) = 3
            x(balls) = xx
            y(balls) = yy
            c(balls) = 15
            dx(balls) = rand(0, 3) * rdir
            dy(balls) = 15

            rr(balls) = 255
            gg(balls) = 255
            bb(balls) = 0
        END IF
    NEXT
NEXT

SCREEN , , 0, 0


How can a simple LINE statement that basically clears the screen be so vital to ball array assignments?

Also why do the balls immediately head to the right of the screen when not contained by the Hour glass figure? Their change in direction, dx (maybe called the x vector), should not be that uniform at all.



I was curious and tried it. And I got the hourglass body. Could you give me a link where this source comes from? Thanks

Code: QB64: [Select]
  1.  
  2. 'SCREEN , , 1, 0 'hmm never used these before = active page 1, visual page 0
  3.  
  4. one& = _NEWIMAGE(800, 600, 32)
  5. _DEST one&
  6.  
  7. LINE (0, 0)-(800, 600), _RGB(0, 0, 0), BF '>>>>>>>>>>>>>>>>>>>>> If I comment out just this one line
  8. a = 0
  9. xx = 150 * SIN(2 * a)
  10. yy = 300 * COS(a)
  11. PSET (xx + 400, yy + 300), _RGB(100, 100, 100)
  12. FOR a = 0 TO 2 * _PI STEP 0.01
  13.     xx = 150 * SIN(2 * a)
  14.     yy = 300 * COS(a)
  15.     LINE -(xx + 400, yy + 300), _RGB(100, 100, 100)
  16.  
  17. PAINT (400, 150), _RGB(100, 100, 100)
  18. PAINT (400, 450), _RGB(100, 100, 100)
  19. LINE (380, 150)-(420, 450), _RGB(100, 100, 100), BF
  20.  
  21. PCOPY 1, 0 'standard Qbasic statement - copy videomemory source, dest
  22.  
  23.  
  24. 'balls = 0
  25. TYPE balls
  26.     r AS INTEGER
  27.     x AS INTEGER
  28.     y AS INTEGER
  29.     c AS LONG
  30.     dx AS INTEGER
  31.     dy AS INTEGER
  32.     rr AS _UNSIGNED _BYTE
  33.     gg AS _UNSIGNED _BYTE
  34.     bb AS _UNSIGNED _BYTE
  35. REDIM balls(0) AS balls
  36.  
  37.  
  38. FOR yy = 50 TO 300 - 10 STEP 8
  39.     FOR xx = 10 TO 600 - 10 STEP 8
  40.         _SOURCE one&
  41.         IF POINT(xx, yy) <> _RGB(0, 0, 0) THEN
  42.             balls = balls + 1
  43.             REDIM _PRESERVE balls(balls) AS balls
  44.             '  VVVVVVVVVVVVVVVVVVVVVV stuff here starts giving me errors, for ball array assignment???????
  45.             balls(balls).r = 3
  46.             balls(balls).x = xx
  47.             balls(balls).y = yy
  48.             balls(balls).c = 15
  49.             balls(balls).dx = RND * 3 * rdir 'this i know not. What is it rdir?
  50.             balls(balls).dy = 15
  51.  
  52.             balls(balls).rr = 255
  53.             balls(balls).gg = 255
  54.             balls(balls).bb = 0
  55.         END IF
  56.     NEXT
  57.  
  58. 'SCREEN , , 0, 0
  59. SCREEN one&
  60.  

I have never seen Free Basic.
« Last Edit: June 13, 2018, 02:58:22 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Dropping Balls
« Reply #26 on: June 13, 2018, 03:58:42 pm »
Quote
I was curious and tried it. And I got the hourglass body. Could you give me a link where this source comes from? Thanks

Reply #12 of this thread is Vince mod of Dropping Balls with the Hour Glass figure.


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: Dropping Balls
« Reply #27 on: June 13, 2018, 05:22:26 pm »
Aha! Good work. Thank for reply.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: Dropping Balls
« Reply #28 on: June 13, 2018, 07:26:20 pm »
How can a simple LINE statement that basically clears the screen be so vital to ball array assignments?

The double for loop traverses the entire screen and only creates a ball if it's inside the hourglass by reading the colour of the screen.  I've used screen ,,1,0 for storing the hourglass image and drawing it on the main screen with pcopy 1,0, not for double buffering or screen syncing.  The same could be done with _source,_dest,_newimage, and _putimage.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Dropping Balls
« Reply #29 on: June 14, 2018, 09:16:18 am »
Thanks, have that figured out and can contain the balls inside hourglass but balls are disappearing at bottom so maybe a leak. I can do the thing without color detection by using two boundary arrays but getting build at bottom has been very frustrating .