Author Topic: Garland of pearls  (Read 3208 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Garland of pearls
« on: March 21, 2022, 08:12:03 pm »
in principle, if I create a cobweb of points and connections, it will be a real cobweb in 3d that takes over all the vibrations of the spider


Code: QB64: [Select]
  1.  
  2. CONST pip180 = 3.141592 / 180
  3. monx = 800: mony = 800: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  4.  
  5. gravity = 1
  6. obj_c = 15 'number objects
  7. DIM obj(obj_c - 1, 9) '0,1 posX,Y 3fix/mover
  8.  
  9.  
  10.  
  11. cent_x = monx / 2: cent_y = 20: zoom = 2
  12.  
  13. 'install "garland of pearls"
  14.  
  15.  
  16. 'garland
  17. min_weight = 6
  18. FOR a = 0 TO obj_c - 1
  19.     obj(a, 0) = (RND(1) - .5) * 100
  20.     obj(a, 1) = (RND(1) - .5) * 100
  21.     obj(a, 2) = min_weight + min_weight / 2 * RND(1)
  22.     obj(a, 3) = 1 '<---- 0 if fix, 1 if fly
  23.  
  24. obj(0, 0) = -64.5: obj(0, 1) = 5: obj(0, 3) = 0
  25. obj(obj_c - 1, 0) = 183.5: obj(obj_c - 1, 1) = -.5: obj(obj_c - 1, 3) = 0
  26.  
  27. 'connections
  28. conn_c = 100: DIM conn(conn_c - 1, 4)
  29. FOR a = 0 TO obj_c - 2
  30.     conn(a, 0) = a
  31.     conn(a, 1) = a + 1
  32.     conn(a, 2) = 20 'rope width
  33.     conn(a, 3) = 1
  34.  
  35.  
  36.  
  37.  
  38.  
  39. DO: _LIMIT 100
  40.  
  41.     'show info
  42.     wch = -1: FOR a = 0 TO obj_c - 1
  43.         IF _MOUSEX < 200 AND INT(_MOUSEY / 16) = a THEN wch = a: COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  44.         LOCATE a + 1, 1: PRINT a; "# weight:"; INT(obj(a, 2) * 10) / 10;: IF obj(a, 3) = 0 THEN PRINT "FIX";
  45.         IF wch = a THEN PRINT "<--- using mousewheel !"
  46.         IF wch <> -1 THEN obj(wch, 2) = obj(wch, 2) + mw / 10: IF obj(wch, 2) < min_weight THEN obj(wch, 2) = min_weight
  47.     NEXT a
  48.     LOCATE mony / 16 - 1, 1: IF moving THEN PRINT "press SPACE to FIX/FLY"; ELSE PRINT "grab the ball with the mouse and move it!";
  49.  
  50.     'draw objects
  51.     FOR a = 0 TO obj_c - 1
  52.         x = cent_x + obj(a, 0) * zoom
  53.         y = cent_y + obj(a, 1) * zoom
  54.         IF mouse_near = a THEN COLOR _RGB32(255, 0, 0) ELSE COLOR _RGB32(200, 200, 200)
  55.         CIRCLE (x, y), obj(a, 2) * zoom
  56.         _PRINTSTRING (x, y), LTRIM$(STR$(a))
  57.     NEXT a
  58.  
  59.     'draw connections
  60.  
  61.     COLOR _RGB32(150, 150, 150)
  62.     FOR a = 0 TO conn_c - 1: IF conn(a, 3) = 0 THEN _CONTINUE
  63.         x1 = obj(conn(a, 0), 0) * zoom + cent_x
  64.         y1 = obj(conn(a, 0), 1) * zoom + cent_y
  65.         x2 = obj(conn(a, 1), 0) * zoom + cent_x
  66.         y2 = obj(conn(a, 1), 1) * zoom + cent_y
  67.     LINE (x1, y1)-(x2, y2): NEXT a
  68.  
  69.     'calculate moving
  70.  
  71.  
  72.     FOR a = 0 TO obj_c - 1: IF obj(a, 3) = 0 OR (mouse_near = a AND _MOUSEBUTTON(1)) THEN _CONTINUE
  73.  
  74.         'connections vector
  75.         vec_x = 0: vec_y = 0: vec_c = 0
  76.         FOR t = 0 TO conn_c - 1: IF conn(t, 3) = 0 THEN _CONTINUE
  77.             x = -1: FOR t2 = 0 TO 1: IF conn(t, t2) = a THEN x = conn(t, t2 XOR 1)
  78.             NEXT t2
  79.             IF x <> -1 THEN
  80.                 disx = obj(a, 0) - obj(x, 0)
  81.                 disy = obj(a, 1) - obj(x, 1)
  82.                 ang = (-degree(disx, disy) + 0) * pip180
  83.                 dis = SQR(disx * disx + disy * disy)
  84.                 power = dis / obj(a, 2) / 5
  85.                 '  IF dis < (obj(a, 2) + obj(x, 2)) THEN power = -power / 10000
  86.                 vec_x = vec_x + SIN(ang) * power
  87.                 vec_y = vec_y - COS(ang) * power
  88.                 vec_c = vec_c + 1
  89.             END IF
  90.         NEXT t
  91.  
  92.         gravity = .1
  93.         lass = .98
  94.  
  95.         obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * lass
  96.         obj(a, 5) = (obj(a, 5) + vec_y / vec_c) * lass + gravity
  97.  
  98.         lx = obj(a, 0) + obj(a, 4)
  99.         ly = obj(a, 1) + obj(a, 5)
  100.  
  101.         obj(a, 0) = obj(a, 0) + obj(a, 4)
  102.         obj(a, 1) = obj(a, 1) + obj(a, 5)
  103.  
  104.  
  105.  
  106.     NEXT a
  107.  
  108.     mw = 0: WHILE _MOUSEINPUT: mw = mw + _MOUSEWHEEL: WEND
  109.  
  110.     'mouse moving activing
  111.     IF moving = 0 THEN
  112.         mouse_near = -1
  113.         FOR a = 0 TO obj_c - 1
  114.             disx = (cent_x + obj(a, 0) * zoom) - _MOUSEX
  115.             disy = (cent_y + obj(a, 1) * zoom) - _MOUSEY
  116.             dis = SQR(disx * disx + disy * disy)
  117.             IF dis < 10 THEN mouse_near = a
  118.         NEXT a
  119.     END IF
  120.  
  121.     IF (_MOUSEBUTTON(1) AND mouse_near <> -1) OR moving THEN
  122.         moving = 1
  123.         obj(mouse_near, 0) = (_MOUSEX - cent_x) / zoom
  124.         obj(mouse_near, 1) = (_MOUSEY - cent_y) / zoom
  125.     END IF
  126.  
  127.     moving = moving AND _MOUSEBUTTON(1)
  128.  
  129.  
  130.     'change weights with mousewheel
  131.  
  132.  
  133.  
  134.     _DISPLAY: CLS
  135.  
  136.     'commands
  137.     inkey2$ = INKEY$: IF inkey2$ = CHR$(27) THEN END
  138.     IF inkey2$ = " " AND _MOUSEBUTTON(1) AND moving THEN obj(mouse_near, 3) = obj(mouse_near, 3) XOR 1
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. FUNCTION degree (a, b): degreex = ATN(a / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0): degree = degreex: END FUNCTION
  146.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Garland of pearls
« Reply #1 on: March 21, 2022, 08:23:10 pm »
Wow nice effect!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
Re: Garland of pearls
« Reply #2 on: March 22, 2022, 04:03:28 am »
Very interesting!

Strange that you do something so difficult yet manage to plot the instructions off the screen.

I added this after the SCREEN is declared:
_ScreenMove (_DesktopWidth - _Width) \ 2, 20
It works better if you plug it in.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Garland of pearls
« Reply #3 on: March 22, 2022, 06:07:00 am »
This program is incredibly fun to play with. Thanks very much for sharing MasterGy! This could most likely be used to study standing wave motion in flexible chains, both transverse and longitudinal waves. You always manage to pack so much action into your programs, it's impressive.

I'm pretty sure your program solves a thing called the "elastic catenary", which might just be a stretched-out version of a hyperbolic cosine. I'm not positive on that though, something tells me no closed solution exists, but I haven't tried the math by hand myself. Oh boy, here we go... (just kidding) No need to do the actual math, you've already got the simulation on hand!

I like that you mention spider webs. I think I can see what you're about to do next and it's very exciting!


You're not done when it works, you're done when it's right.

Offline Dav

  • Forum Resident
  • Posts: 792
Re: Garland of pearls
« Reply #4 on: March 22, 2022, 09:34:14 am »
This is pretty amazing, @MasterGy!

- Dav

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Garland of pearls
« Reply #5 on: March 22, 2022, 10:11:44 am »
Thanks for the comments. I honestly admit, I myself am amazed that this works. In games, I long ago figured it out to display text, animate, move when I want change to be flexible. Let A and B. Let "A" be the current value. Let B be the new value. By definition B = A. But this makes it inflexible in timing, animation, positioning work.
Therefore, I usually do it so that not B = A, but B = B + (A-B) x "all", for example. "All" must be between 0 and 1! This will be a constant value. If 0, no offset occurs. If 1, an inelastic, immediate displacement occurs. On the other hand, if I write e.g.
 The more times we perform it, the closer it gets to B = A. The larger the difference between A and B, the faster it makes the change, and when it is almost reached, it slows down. In fact, it never reaches.
Implementing STxAxTIC with the pendulum program returns the cleanest physics. Then came my idea of ​​what it would be like to forget that much complicated physics and use the method described above to move the ball. Ball "B" wants to be in place of "A" ... B = B + (A-B) x "all"
In principle, since this seems to work, this method could also be used to move, collide without the use of rigid-body physics or any more serious mathematics. In theory. Pendulum, brick wall collapses by bricks, car overturns, precise collision of two bodies with rotations and directions. It seems as if this simple method bypasses the part of physics where pulse retention, angular velocity, vectors should be taken into account. The system simply extracts from itself.
I’m very curious as to how far this can go, and is the latter suggestion true? does it work
I described these so that if anyone cares and wants to deal with it, sees opportunities in it like I do, then see how simple it is. try it !
I set up the program to eliminate flexibility. From here, the things described above should work in principle.
The program starts and you can turn flexibility on and off with the "S" key. If we turn it off, we get approximately the pendulum motion of STxAxTIC. When turned on, it will be flexible as if they were connected with rubber.

Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. monx = 800: mony = 800: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  3.  
  4. min_weight = 6
  5. gravity = 1
  6. obj_c = 10 'number objects
  7. DIM obj(obj_c - 1, 9) '0,1 posX,Y 3fix/mover
  8. cent_x = monx / 2: cent_y = mony * .2: zoom = 2
  9.  
  10. 'garland
  11. FOR a = 0 TO obj_c - 1
  12.     obj(a, 0) = (RND(1) - .5) * 200
  13.     obj(a, 1) = (RND(1) - .5) * 200
  14.     obj(a, 2) = min_weight + min_weight / 2 * RND(1)
  15.     obj(a, 3) = 1 '<---- 0 if fix, 1 if fly
  16.     obj(a, 4) = 1 'active point
  17.  
  18. obj(0, 0) = -64.5: obj(0, 1) = 5: obj(0, 3) = 0
  19. 'obj(obj_c - 1, 0) = 183.5: obj(obj_c - 1, 1) = -.5: obj(obj_c - 1, 3) = 0
  20.  
  21. 'connections
  22. conn_c = 100: DIM conn(conn_c - 1, 4)
  23. FOR a = 0 TO obj_c - 2
  24.     conn(a, 0) = a
  25.     conn(a, 1) = a + 1
  26.     conn(a, 2) = 15 'rope width
  27.     conn(a, 3) = 1 'active connect
  28.  
  29.  
  30.  
  31. stiff = 1
  32.  
  33. DO: _LIMIT 100
  34.  
  35.     'show info
  36.     wch = -1: FOR a = 0 TO obj_c - 1
  37.         IF _MOUSEX < 200 AND INT(_MOUSEY / 16) = a THEN wch = a: COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  38.         LOCATE a + 1, 1: PRINT a; "# weight:"; INT(obj(a, 2) * 10) / 10;: IF obj(a, 3) = 0 THEN PRINT "FIX";
  39.         IF wch = a THEN PRINT "<--- using mousewheel !" 'change weights with mousewheel
  40.         IF wch <> -1 THEN obj(wch, 2) = obj(wch, 2) + mw / 10: IF obj(wch, 2) < min_weight THEN obj(wch, 2) = min_weight
  41.     NEXT a
  42.     LOCATE mony / 16 - 2, 1
  43.     IF moving THEN PRINT "press SPACE to FIX/FLY" ELSE PRINT "grab the ball with the mouse and move it!"
  44.     PRINT "S-button - rigid / flexible connections";
  45.     'draw objects
  46.     FOR a = 0 TO obj_c - 1: IF obj(a, 4) = 0 THEN _CONTINUE
  47.         x = cent_x + obj(a, 0) * zoom: y = cent_y + obj(a, 1) * zoom
  48.         IF mouse_near = a THEN COLOR _RGB32(255, 0, 0) ELSE COLOR _RGB32(200, 200, 200)
  49.         CIRCLE (x, y), obj(a, 2) * zoom: _PRINTSTRING (x, y), LTRIM$(STR$(a))
  50.     NEXT a
  51.  
  52.     'draw connections
  53.  
  54.     COLOR _RGB32(150, 150, 150)
  55.     FOR a = 0 TO conn_c - 1: IF conn(a, 3) = 0 THEN _CONTINUE
  56.         IF obj(conn(a, 0), 4) = 0 OR obj(conn(a, 1), 4) = 0 THEN _CONTINUE
  57.         x1 = obj(conn(a, 0), 0) * zoom + cent_x: y1 = obj(conn(a, 0), 1) * zoom + cent_y
  58.         x2 = obj(conn(a, 1), 0) * zoom + cent_x: y2 = obj(conn(a, 1), 1) * zoom + cent_y
  59.     LINE (x1, y1)-(x2, y2): NEXT a
  60.  
  61.  
  62.  
  63.     'calculate moving
  64.     FOR a = 0 TO obj_c - 1: obj(a, 6) = obj(a, 0): obj(a, 7) = obj(a, 1)
  65.         IF obj(a, 3) = 0 OR (mouse_near = a AND _MOUSEBUTTON(1)) OR obj(a, 4) = 0 THEN _CONTINUE
  66.         'connections vector
  67.         vec_x = 0: vec_y = 0: vec_c = 0
  68.         FOR t = 0 TO conn_c - 1: IF conn(t, 3) = 0 THEN _CONTINUE
  69.             x = -1: FOR t2 = 0 TO 1: IF conn(t, t2) = a THEN x = conn(t, t2 XOR 1)
  70.             NEXT t2
  71.             IF x <> -1 THEN
  72.                 IF obj(x, 4) THEN
  73.                     disx = obj(a, 0) - obj(x, 0)
  74.                     disy = obj(a, 1) - obj(x, 1)
  75.                     ang = (-degree(disx, disy) + 0) * pip180
  76.                     dis = SQR(disx * disx + disy * disy)
  77.                     power = (dis - (obj(a, 2) + obj(x, 2) + conn(t, 2))) * 1 ' obj(a, 2) ^ 2 '/ 20
  78.                     IF stiff THEN power = power / obj(a, 2) ^ 2 * 4
  79.                     vec_x = vec_x + SIN(ang) * power
  80.                     vec_y = vec_y - COS(ang) * power
  81.                     vec_c = vec_c + 1
  82.                 END IF
  83.             END IF
  84.         NEXT t
  85.  
  86.         gravity = .1: lass = .98
  87.         obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * lass: obj(a, 5) = (obj(a, 5) + vec_y / vec_c) * lass + gravity
  88.         obj(a, 6) = obj(a, 0) + obj(a, 4): obj(a, 7) = obj(a, 1) + obj(a, 5)
  89.     NEXT a
  90.     FOR a = 0 TO obj_c - 1: FOR t = 0 TO 1: obj(a, t) = obj(a, 6 + t): NEXT t, a
  91.  
  92.  
  93.  
  94.  
  95.     'mouse moving activing
  96.     mw = 0: WHILE _MOUSEINPUT: mw = mw + _MOUSEWHEEL: WEND
  97.     IF moving = 0 THEN
  98.         mouse_near = -1
  99.         FOR a = 0 TO obj_c - 1
  100.             disx = (cent_x + obj(a, 0) * zoom) - _MOUSEX
  101.             disy = (cent_y + obj(a, 1) * zoom) - _MOUSEY
  102.             dis = SQR(disx * disx + disy * disy)
  103.             IF dis < 10 THEN mouse_near = a
  104.         NEXT a
  105.     END IF
  106.  
  107.     IF (_MOUSEBUTTON(1) AND mouse_near <> -1) OR moving THEN
  108.         moving = 1
  109.         obj(mouse_near, 0) = (_MOUSEX - cent_x) / zoom
  110.         obj(mouse_near, 1) = (_MOUSEY - cent_y) / zoom
  111.     END IF
  112.  
  113.     moving = moving AND _MOUSEBUTTON(1)
  114.  
  115.     stiff = stiff XOR ABS(inkey2$ = "s")
  116.  
  117.     _DISPLAY: CLS
  118.  
  119.     'commands
  120.     inkey2$ = INKEY$: IF inkey2$ = CHR$(27) THEN END
  121.     IF inkey2$ = " " AND _MOUSEBUTTON(1) AND moving THEN obj(mouse_near, 3) = obj(mouse_near, 3) XOR 1
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. FUNCTION degree (a, b): degreex = ATN(a / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0): degree = degreex: END FUNCTION
  129.  
  130. FUNCTION randx (x): randx = x * RND(1) - x / 2: END FUNCTION

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Garland of pearls
« Reply #6 on: March 22, 2022, 10:33:05 am »
The trouble is, because of the translation, I can’t express myself the way I want to.
It doesn't matter what we measure. Distance, volume, size, speed, rotation, anything.
Quantity "A". This quantity wants to be "B".
Then use: B = B + (A-B) x "all"
This offers many opportunities.
I hope this thought, which I really want to go through, has gone through somewhat.
I wrote a simple illustration on it.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3.  
  4. CHANGING = .05
  5. 'if CHANGING 0:no move
  6. 'if CHANGING 1:immediate displacement
  7. 'if CHANGING between 0,1 elastic displacement
  8.  
  9.  
  10.     _LIMIT 50
  11.     x = x + (_MOUSEX - x) * CHANGING
  12.     y = y + (_MOUSEY - y) * CHANGING
  13.     _PRINTSTRING (x, y), "X"
  14.     _DISPLAY
  15.     CLS
  16.  

It shows movement. But the principle can be distance, volume, size, speed, rotation, anything ...

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Garland of pearls
« Reply #7 on: March 22, 2022, 10:52:40 am »
Hey MasterGy,

I think I understand what you're saying. I use a similar piece of mathematics for mouse controls in my pendulum code:

(There may be a version of it floating around that shows a trail behind the mouse pointer.)

Code: QB64: [Select]
  1. SUB RePin
  2.     DIM AS DOUBLE n
  3.     n = .05
  4.     mx0 = n * mx + (1 - n) * mx0
  5.     my0 = n * my + (1 - n) * my0
You're not done when it works, you're done when it's right.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Garland of pearls
« Reply #8 on: March 22, 2022, 03:36:20 pm »
grab the cobweb!

Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. monx = 800: mony = 800: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  3.  
  4. min_weight = 6
  5. gravity = 1
  6. obj_c = 1000 'number objects
  7. DIM obj(obj_c - 1, 9) '0,1 posX,Y 3fix/mover
  8. cent_x = monx / 2: cent_y = mony / 2: zoom = 1.8
  9.  
  10.  
  11.  
  12. 'cobweb
  13. ag0 = 320 'size
  14. ag1 = 18 'felbontas ag
  15. ag2 = 14 'felbontas net
  16. ag3 = ag0 * .18 / 2 'rad1
  17. ag4 = ag0 * .9 / 2 'rad2
  18.  
  19.  
  20. FOR t = 0 TO ag1 - 1
  21.     ang = (360 / ag1 * t + randx(360 / ag1 * .3)) * pip180
  22.     dis = ABS(ag3 - ag4)
  23.     x1 = SIN(ang) * ag3 + randx(ag3 * .1)
  24.     y1 = COS(ang) * ag3 + randx(ag3 * .1)
  25.     x2 = SIN(ang) * ag4 + randx(ag4 * .2)
  26.     y2 = COS(ang) * ag4 + randx(ag4 * .2)
  27.  
  28.     FOR t2 = 0 TO ag2 - 1
  29.         aobj = t2 + ag2 * t
  30.         obj(aobj, 0) = x1 + (x2 - x1) / (ag2 - 1) * t2
  31.         obj(aobj, 1) = y1 + (y2 - y1) / (ag2 - 1) * t2
  32.         obj(aobj, 2) = 1.9 'min_weight
  33.         obj(aobj, 3) = 1
  34.         '        IF t2 = ag2 - 1 THEN obj(aobj, 3) = 0
  35.  
  36.         obj(aobj, 4) = 1
  37.     NEXT t2
  38.  
  39.  
  40. 'connections
  41. conn_c = 1000: DIM conn(conn_c - 1, 4): ac = 0
  42.  
  43. FOR t = 0 TO ag2 - 2: FOR t2 = 0 TO ag1 - 1: conn(ac, 0) = t2 * ag2 + t: conn(ac, 1) = t2 * ag2 + ((t + 1) MOD ag2)
  44.         conn(ac, 2) = SQR((obj(conn(ac, 0), 0) - obj(conn(ac, 1), 0)) ^ 2 + (obj(conn(ac, 0), 1) - obj(conn(ac, 1), 1)) ^ 2)
  45.         conn(ac, 2) = conn(ac, 2) + randx(conn(ac, 2) * .1)
  46. conn(ac, 3) = 1: ac = ac + 1: NEXT t2, t
  47.  
  48. FOR t = 0 TO ag2 - 1: FOR t2 = 0 TO ag1 - 1: conn(ac, 0) = t + ag2 * t2: conn(ac, 1) = t + ag2 * ((t2 + 1) MOD ag1)
  49.         conn(ac, 2) = SQR((obj(conn(ac, 0), 0) - obj(conn(ac, 1), 0)) ^ 2 + (obj(conn(ac, 0), 1) - obj(conn(ac, 1), 1)) ^ 2)
  50.         conn(ac, 2) = conn(ac, 2) + randx(conn(ac, 2) * .1)
  51. conn(ac, 3) = 1: ac = ac + 1: NEXT t2, t
  52.  
  53. polar_p = ag1 * ag2
  54. FOR t = 0 TO 3
  55.     obj(polar_p + t, 0) = ((t AND 1) * 2 - 1) * ag0 / 2
  56.     obj(polar_p + t, 1) = (SGN(t AND 2) * 2 - 1) * ag0 / 2
  57.     obj(polar_p + t, 2) = 6 'min_weight
  58.     obj(polar_p + t, 3) = 0
  59.     obj(polar_p + t, 4) = 1
  60.     mindis = 999999999
  61.  
  62.     FOR a = 0 TO polar_p - 1
  63.         dis = SQR((obj(polar_p + t, 0) - obj(a, 0)) ^ 2 + (obj(polar_p + t, 1) - obj(a, 1)) ^ 2) * .8
  64.         IF dis < mindis THEN mindis = dis: conn_n = a
  65.     NEXT a
  66.     conn(ac, 0) = polar_p + t
  67.     conn(ac, 1) = conn_n
  68.     conn(ac, 2) = mindis
  69.     conn(ac, 3) = 1
  70.     ac = ac + 1
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. stiff = 1
  78.  
  79. DO: _LIMIT 100
  80.  
  81.     'show info
  82.     wch = -1: FOR a = 0 TO obj_c - 1
  83.         IF _MOUSEX < 200 AND INT(_MOUSEY / 16) = a THEN wch = a: COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  84.         ' LOCATE a + 1, 1: PRINT a; "# weight:"; INT(obj(a, 2) * 10) / 10;: IF obj(a, 3) = 0 THEN PRINT "FIX";
  85.         'IF wch = a THEN PRINT "<--- using mousewheel !" 'change weights with mousewheel
  86.         IF wch <> -1 THEN obj(wch, 2) = obj(wch, 2) + mw / 10: IF obj(wch, 2) < min_weight THEN obj(wch, 2) = min_weight
  87.     NEXT a
  88.     LOCATE mony / 16 - 2, 1
  89.     IF moving THEN PRINT "press SPACE to FIX/FLY" ELSE PRINT "grab the ball with the mouse and move it!"
  90.     '    PRINT "S-button - rigid / flexible connections";
  91.     'draw objects
  92.     FOR a = 0 TO obj_c - 1: IF obj(a, 4) = 0 THEN _CONTINUE
  93.         x = cent_x + obj(a, 0) * zoom: y = cent_y + obj(a, 1) * zoom
  94.         IF mouse_near = a THEN COLOR _RGB32(255, 0, 0) ELSE COLOR _RGB32(200, 200, 200)
  95.         '        CIRCLE (x, y), obj(a, 2) * zoom: _PRINTSTRING (x, y), LTRIM$(STR$(a))
  96.     NEXT a
  97.  
  98.     'draw connections
  99.  
  100.     COLOR _RGB32(200, 200, 200)
  101.     FOR a = 0 TO conn_c - 1: IF conn(a, 3) = 0 THEN _CONTINUE
  102.         IF obj(conn(a, 0), 4) = 0 OR obj(conn(a, 1), 4) = 0 THEN _CONTINUE
  103.         x1 = obj(conn(a, 0), 0) * zoom + cent_x: y1 = obj(conn(a, 0), 1) * zoom + cent_y
  104.         x2 = obj(conn(a, 1), 0) * zoom + cent_x: y2 = obj(conn(a, 1), 1) * zoom + cent_y
  105.     LINE (x1, y1)-(x2, y2): NEXT a
  106.  
  107.  
  108.  
  109.     'calculate moving
  110.     FOR a = 0 TO obj_c - 1: obj(a, 6) = obj(a, 0): obj(a, 7) = obj(a, 1)
  111.         IF obj(a, 3) = 0 OR (mouse_near = a AND _MOUSEBUTTON(1)) OR obj(a, 4) = 0 THEN _CONTINUE
  112.         'connections vector
  113.         vec_x = 0: vec_y = 0: vec_c = 0
  114.         FOR t = 0 TO conn_c - 1: IF conn(t, 3) = 0 THEN _CONTINUE
  115.             x = -1: FOR t2 = 0 TO 1: IF conn(t, t2) = a THEN x = conn(t, t2 XOR 1)
  116.             NEXT t2
  117.             IF x <> -1 THEN
  118.                 IF obj(x, 4) THEN
  119.                     disx = obj(a, 0) - obj(x, 0)
  120.                     disy = obj(a, 1) - obj(x, 1)
  121.                     ang = (-degree(disx, disy) + 0) * pip180
  122.                     dis = SQR(disx * disx + disy * disy)
  123.                     power = (dis - conn(t, 2)) * .6 ' obj(a, 2) ^ 2 '/ 20
  124.                     IF stiff THEN power = power / obj(a, 2) ^ 2 * 4
  125.                     vec_x = vec_x + SIN(ang) * power
  126.                     vec_y = vec_y - COS(ang) * power
  127.                     vec_c = vec_c + 1
  128.                 END IF
  129.             END IF
  130.         NEXT t
  131.  
  132.         gravity = 0 '.1
  133.         lass = .90
  134.         obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * lass
  135.         obj(a, 5) = (obj(a, 5) + vec_y / vec_c) * lass + gravity
  136.         obj(a, 6) = obj(a, 0) + obj(a, 4)
  137.         obj(a, 7) = obj(a, 1) + obj(a, 5)
  138.     NEXT a
  139.     FOR a = 0 TO obj_c - 1: FOR t = 0 TO 1: obj(a, t) = obj(a, 6 + t): NEXT t, a
  140.  
  141.  
  142.  
  143.  
  144.     'mouse moving activing
  145.     mw = 0: WHILE _MOUSEINPUT: mw = mw + _MOUSEWHEEL: WEND
  146.     mindis = 99999999
  147.     IF moving = 0 THEN
  148.         mouse_near = -1
  149.         FOR a = 0 TO obj_c - 1
  150.             disx = (cent_x + obj(a, 0) * zoom) - _MOUSEX
  151.             disy = (cent_y + obj(a, 1) * zoom) - _MOUSEY
  152.             dis = SQR(disx * disx + disy * disy)
  153.             IF dis < 60 AND mindis > dis THEN mouse_near = a:mindis = dis
  154.         NEXT a
  155.     END IF
  156.  
  157.     IF (_MOUSEBUTTON(1) AND mouse_near <> -1) OR moving THEN
  158.         moving = 1
  159.         obj(mouse_near, 0) = (_MOUSEX - cent_x) / zoom
  160.         obj(mouse_near, 1) = (_MOUSEY - cent_y) / zoom
  161.     END IF
  162.  
  163.     moving = moving AND _MOUSEBUTTON(1)
  164.  
  165.     stiff = stiff XOR ABS(inkey2$ = "s")
  166.  
  167.  
  168.     _DISPLAY: CLS
  169.  
  170.     'commands
  171.     inkey2$ = INKEY$: IF inkey2$ = CHR$(27) THEN END
  172.     IF inkey2$ = " " AND _MOUSEBUTTON(1) AND moving THEN obj(mouse_near, 3) = obj(mouse_near, 3) XOR 1
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. FUNCTION degree (a, b): degreex = ATN(a / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0): degree = degreex: END FUNCTION
  180.  
  181. FUNCTION randx (x): randx = x * RND(1) - x / 2: END FUNCTION
« Last Edit: March 22, 2022, 03:44:55 pm by MasterGy »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Garland of pearls
« Reply #9 on: March 22, 2022, 07:09:43 pm »
enter a picture in the program "temp = _LOADIMAGE("pic.jpg", 32)"
crush the picture with your mouse!

Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. monx = 800: mony = monx / _DESKTOPWIDTH * _DESKTOPHEIGHT: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon: _DISPLAYORDER _HARDWARE , _SOFTWARE
  3.  
  4. min_weight = 6
  5. gravity = 1
  6. obj_c = 1000 'number objects
  7. DIM obj(obj_c - 1, 9) '0,1 posX,Y 3fix/mover
  8. cent_x = monx / 2: cent_y = mony / 2: zoom = 2.4
  9.  
  10.  
  11.  
  12. conn_c = 1000: DIM conn(conn_c - 1, 4)
  13.  
  14.  
  15. temp = _LOADIMAGE("pic.jpg", 32): _DEST temp: _SETALPHA 100: pic = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  16.  
  17. sizex = 300: sizey = INT(sizex / _WIDTH(pic) * _HEIGHT(pic))
  18. felbx = 15: felby = INT(felbx / _WIDTH(pic) * _HEIGHT(pic))
  19. unitx = INT(_WIDTH(pic) / (felbx - 1))
  20. unity = INT(_HEIGHT(pic) / (felby - 1))
  21.  
  22.  
  23. FOR ty = 0 TO felby - 1
  24.     FOR tx = 0 TO felbx - 1
  25.         aobj = tx + ty * felbx
  26.         obj(aobj, 0) = sizex / felbx * tx - sizex / 2
  27.         obj(aobj, 1) = sizey / felby * ty - sizey / 2
  28.         obj(aobj, 2) = 5
  29.         obj(aobj, 3) = 1
  30.         IF (ty = 0 OR ty = felby - 1) AND (tx = 0 OR tx = felbx - 1) THEN obj(aobj, 3) = 0
  31.         obj(aobj, 4) = 1
  32.     NEXT tx
  33. NEXT ty
  34.  
  35.  
  36. 'connections
  37. FOR ty = 0 TO felby - 1: FOR tx = 0 TO felbx - 2: conn(ac, 0) = tx + ty * felbx: conn(ac, 1) = conn(ac, 0) + 1
  38.         conn(ac, 2) = SQR((obj(conn(ac, 0), 0) - obj(conn(ac, 1), 0)) ^ 2 + (obj(conn(ac, 0), 1) - obj(conn(ac, 1), 1)) ^ 2) * .8
  39. conn(ac, 3) = 1: ac = ac + 1: NEXT tx, ty
  40.  
  41. FOR tx = 0 TO felbx - 1: FOR ty = 0 TO felby - 2: conn(ac, 0) = tx + ty * felbx: conn(ac, 1) = conn(ac, 0) + felbx
  42.         conn(ac, 2) = SQR((obj(conn(ac, 0), 0) - obj(conn(ac, 1), 0)) ^ 2 + (obj(conn(ac, 0), 1) - obj(conn(ac, 1), 1)) ^ 2) * .8
  43. conn(ac, 3) = 1: ac = ac + 1: NEXT ty, tx
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. stiff = 1
  55. COLOR , 0
  56. DO: _LIMIT 30 '100
  57.  
  58.     'show info
  59.     wch = -1: FOR a = 0 TO obj_c - 1
  60.         IF _MOUSEX < 200 AND INT(_MOUSEY / 16) = a THEN wch = a: COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  61.         ' LOCATE a + 1, 1: PRINT a; "# weight:"; INT(obj(a, 2) * 10) / 10;: IF obj(a, 3) = 0 THEN PRINT "FIX";
  62.         'IF wch = a THEN PRINT "<--- using mousewheel !" 'change weights with mousewheel
  63.         IF wch <> -1 THEN obj(wch, 2) = obj(wch, 2) + mw / 10: IF obj(wch, 2) < min_weight THEN obj(wch, 2) = min_weight
  64.     NEXT a
  65.     LOCATE mony / 16 - 2, 1
  66.     IF moving THEN PRINT "press SPACE to FIX/FLY" ELSE PRINT "grab the ball with the mouse and move it!"
  67.     '    PRINT "S-button - rigid / flexible connections";
  68.     'draw objects
  69.     FOR a = 0 TO obj_c - 1: IF obj(a, 4) = 0 THEN _CONTINUE
  70.         x = cent_x + obj(a, 0) * zoom: y = cent_y + obj(a, 1) * zoom
  71.         obj(a, 8) = x
  72.         obj(a, 9) = y
  73.         IF mouse_near = a THEN COLOR _RGB32(255, 0, 0) ELSE COLOR _RGB32(200, 200, 200)
  74.         '        CIRCLE (x, y), obj(a, 2) * zoom: _PRINTSTRING (x, y), LTRIM$(STR$(a))
  75.  
  76.     NEXT a
  77.  
  78.     'draw connections
  79.     COLOR _RGB32(200, 200, 200)
  80.     FOR a = 0 TO conn_c - 1: IF conn(a, 3) = 0 THEN _CONTINUE
  81.         IF obj(conn(a, 0), 4) = 0 OR obj(conn(a, 1), 4) = 0 THEN _CONTINUE
  82.         x1 = obj(conn(a, 0), 0) * zoom + cent_x: y1 = obj(conn(a, 0), 1) * zoom + cent_y
  83.         x2 = obj(conn(a, 1), 0) * zoom + cent_x: y2 = obj(conn(a, 1), 1) * zoom + cent_y
  84.         '    LINE (x1, y1)-(x2, y2), _RGBA32(0, 0, 0, 128)
  85.     NEXT a
  86.  
  87.  
  88.  
  89.     'calculate moving
  90.     FOR a = 0 TO obj_c - 1: obj(a, 6) = obj(a, 0): obj(a, 7) = obj(a, 1)
  91.         IF obj(a, 3) = 0 OR (mouse_near = a AND _MOUSEBUTTON(1)) OR obj(a, 4) = 0 THEN _CONTINUE
  92.         'connections vector
  93.         vec_x = 0: vec_y = 0: vec_c = 0
  94.         FOR t = 0 TO conn_c - 1: IF conn(t, 3) = 0 THEN _CONTINUE
  95.             x = -1: FOR t2 = 0 TO 1: IF conn(t, t2) = a THEN x = conn(t, t2 XOR 1)
  96.             NEXT t2
  97.             IF x <> -1 THEN
  98.                 IF obj(x, 4) THEN
  99.                     disx = obj(a, 0) - obj(x, 0)
  100.                     disy = obj(a, 1) - obj(x, 1)
  101.                     ang = (-degree(disx, disy) + 0) * pip180
  102.                     dis = SQR(disx * disx + disy * disy)
  103.                     power = (dis - conn(t, 2)) * 2
  104.                     IF stiff THEN power = power / obj(a, 2) ^ 2 * 4
  105.                     vec_x = vec_x + SIN(ang) * power
  106.                     vec_y = vec_y - COS(ang) * power
  107.                     vec_c = vec_c + 1
  108.                 END IF
  109.             END IF
  110.         NEXT t
  111.  
  112.         gravity = 0 '.1
  113.         lass = .93
  114.         obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * lass
  115.         obj(a, 5) = (obj(a, 5) + vec_y / vec_c) * lass + gravity
  116.         obj(a, 6) = obj(a, 0) + obj(a, 4)
  117.         obj(a, 7) = obj(a, 1) + obj(a, 5)
  118.     NEXT a
  119.     FOR a = 0 TO obj_c - 1: FOR t = 0 TO 1: obj(a, t) = obj(a, 6 + t): NEXT t, a
  120.  
  121.  
  122.  
  123.  
  124.     'mouse moving activing
  125.     mw = 0: WHILE _MOUSEINPUT: mw = mw + _MOUSEWHEEL: WEND
  126.     mindis = 99999999
  127.     IF moving = 0 THEN
  128.         mouse_near = -1
  129.         FOR a = 0 TO obj_c - 1
  130.             disx = (cent_x + obj(a, 0) * zoom) - _MOUSEX
  131.             disy = (cent_y + obj(a, 1) * zoom) - _MOUSEY
  132.             dis = SQR(disx * disx + disy * disy)
  133.             IF dis < 60 AND mindis > dis THEN mouse_near = a: mindis = dis
  134.         NEXT a
  135.     END IF
  136.  
  137.     IF (_MOUSEBUTTON(1) AND mouse_near <> -1) OR moving THEN
  138.         moving = 1
  139.         obj(mouse_near, 0) = (_MOUSEX - cent_x) / zoom
  140.         obj(mouse_near, 1) = (_MOUSEY - cent_y) / zoom
  141.     END IF
  142.  
  143.     moving = moving AND _MOUSEBUTTON(1)
  144.  
  145.     stiff = stiff XOR ABS(inkey2$ = "s")
  146.  
  147.     'picture draw
  148.     FOR ty = 0 TO felby - 2: sy1 = INT(unity * ty): sy2 = sy1 + unity - 1
  149.         FOR tx = 0 TO felbx - 2: sx1 = INT(unitx * tx): sx2 = sx1 + unitx - 1: aobj = tx + ty * felbx
  150.             FOR t = 0 TO 7: p(t) = obj(aobj + (t AND 1) + SGN(t AND 2) * felbx, 8 + SGN(t AND 4)): NEXT t
  151.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), pic TO(p(0), p(4))-(p(1), p(5))-(p(2), p(6))
  152.             _MAPTRIANGLE (sx2, sy2)-(sx2, sy1)-(sx1, sy2), pic TO(p(3), p(7))-(p(1), p(5))-(p(2), p(6))
  153.         NEXT tx
  154.     NEXT ty
  155.  
  156.     _DISPLAY: CLS
  157.  
  158.     'commands
  159.     inkey2$ = INKEY$: IF inkey2$ = CHR$(27) THEN END
  160.     IF inkey2$ = " " AND _MOUSEBUTTON(1) AND moving THEN obj(mouse_near, 3) = obj(mouse_near, 3) XOR 1
  161.  
  162.  
  163.  
  164.  
  165. FUNCTION degree (a, b): degreex = ATN(a / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0): degree = degreex: END FUNCTION
  166. FUNCTION randx (x): randx = x * RND(1) - x / 2: END FUNCTION
  167.  

Offline Dav

  • Forum Resident
  • Posts: 792
Re: Garland of pearls
« Reply #10 on: March 22, 2022, 09:59:26 pm »
Wow -- that image version is about the coolest effect I've seen in QB64...

- Dav

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Garland of pearls
« Reply #11 on: March 22, 2022, 10:47:24 pm »
Yeah, this really is something special!
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Garland of pearls
« Reply #12 on: March 23, 2022, 01:09:12 pm »
MasterGy is on a roll!

FellippeHeitor

  • Guest
Re: Garland of pearls
« Reply #13 on: March 23, 2022, 01:17:20 pm »
Wow, I only managed to run this now and I LOVE this spider web. Such cool work, MasterGy.

grab the cobweb!

Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. monx = 800: mony = 800: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  3.  
  4. min_weight = 6
  5. gravity = 1
  6. obj_c = 1000 'number objects
  7. DIM obj(obj_c - 1, 9) '0,1 posX,Y 3fix/mover
  8. cent_x = monx / 2: cent_y = mony / 2: zoom = 1.8
  9.  
  10.  
  11.  
  12. 'cobweb
  13. ag0 = 320 'size
  14. ag1 = 18 'felbontas ag
  15. ag2 = 14 'felbontas net
  16. ag3 = ag0 * .18 / 2 'rad1
  17. ag4 = ag0 * .9 / 2 'rad2
  18.  
  19.  
  20. FOR t = 0 TO ag1 - 1
  21.     ang = (360 / ag1 * t + randx(360 / ag1 * .3)) * pip180
  22.     dis = ABS(ag3 - ag4)
  23.     x1 = SIN(ang) * ag3 + randx(ag3 * .1)
  24.     y1 = COS(ang) * ag3 + randx(ag3 * .1)
  25.     x2 = SIN(ang) * ag4 + randx(ag4 * .2)
  26.     y2 = COS(ang) * ag4 + randx(ag4 * .2)
  27.  
  28.     FOR t2 = 0 TO ag2 - 1
  29.         aobj = t2 + ag2 * t
  30.         obj(aobj, 0) = x1 + (x2 - x1) / (ag2 - 1) * t2
  31.         obj(aobj, 1) = y1 + (y2 - y1) / (ag2 - 1) * t2
  32.         obj(aobj, 2) = 1.9 'min_weight
  33.         obj(aobj, 3) = 1
  34.         '        IF t2 = ag2 - 1 THEN obj(aobj, 3) = 0
  35.  
  36.         obj(aobj, 4) = 1
  37.     NEXT t2
  38.  
  39.  
  40. 'connections
  41. conn_c = 1000: DIM conn(conn_c - 1, 4): ac = 0
  42.  
  43. FOR t = 0 TO ag2 - 2: FOR t2 = 0 TO ag1 - 1: conn(ac, 0) = t2 * ag2 + t: conn(ac, 1) = t2 * ag2 + ((t + 1) MOD ag2)
  44.         conn(ac, 2) = SQR((obj(conn(ac, 0), 0) - obj(conn(ac, 1), 0)) ^ 2 + (obj(conn(ac, 0), 1) - obj(conn(ac, 1), 1)) ^ 2)
  45.         conn(ac, 2) = conn(ac, 2) + randx(conn(ac, 2) * .1)
  46. conn(ac, 3) = 1: ac = ac + 1: NEXT t2, t
  47.  
  48. FOR t = 0 TO ag2 - 1: FOR t2 = 0 TO ag1 - 1: conn(ac, 0) = t + ag2 * t2: conn(ac, 1) = t + ag2 * ((t2 + 1) MOD ag1)
  49.         conn(ac, 2) = SQR((obj(conn(ac, 0), 0) - obj(conn(ac, 1), 0)) ^ 2 + (obj(conn(ac, 0), 1) - obj(conn(ac, 1), 1)) ^ 2)
  50.         conn(ac, 2) = conn(ac, 2) + randx(conn(ac, 2) * .1)
  51. conn(ac, 3) = 1: ac = ac + 1: NEXT t2, t
  52.  
  53. polar_p = ag1 * ag2
  54. FOR t = 0 TO 3
  55.     obj(polar_p + t, 0) = ((t AND 1) * 2 - 1) * ag0 / 2
  56.     obj(polar_p + t, 1) = (SGN(t AND 2) * 2 - 1) * ag0 / 2
  57.     obj(polar_p + t, 2) = 6 'min_weight
  58.     obj(polar_p + t, 3) = 0
  59.     obj(polar_p + t, 4) = 1
  60.     mindis = 999999999
  61.  
  62.     FOR a = 0 TO polar_p - 1
  63.         dis = SQR((obj(polar_p + t, 0) - obj(a, 0)) ^ 2 + (obj(polar_p + t, 1) - obj(a, 1)) ^ 2) * .8
  64.         IF dis < mindis THEN mindis = dis: conn_n = a
  65.     NEXT a
  66.     conn(ac, 0) = polar_p + t
  67.     conn(ac, 1) = conn_n
  68.     conn(ac, 2) = mindis
  69.     conn(ac, 3) = 1
  70.     ac = ac + 1
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. stiff = 1
  78.  
  79. DO: _LIMIT 100
  80.  
  81.     'show info
  82.     wch = -1: FOR a = 0 TO obj_c - 1
  83.         IF _MOUSEX < 200 AND INT(_MOUSEY / 16) = a THEN wch = a: COLOR _RGB32(255, 255, 255) ELSE COLOR _RGB32(100, 100, 100)
  84.         ' LOCATE a + 1, 1: PRINT a; "# weight:"; INT(obj(a, 2) * 10) / 10;: IF obj(a, 3) = 0 THEN PRINT "FIX";
  85.         'IF wch = a THEN PRINT "<--- using mousewheel !" 'change weights with mousewheel
  86.         IF wch <> -1 THEN obj(wch, 2) = obj(wch, 2) + mw / 10: IF obj(wch, 2) < min_weight THEN obj(wch, 2) = min_weight
  87.     NEXT a
  88.     LOCATE mony / 16 - 2, 1
  89.     IF moving THEN PRINT "press SPACE to FIX/FLY" ELSE PRINT "grab the ball with the mouse and move it!"
  90.     '    PRINT "S-button - rigid / flexible connections";
  91.     'draw objects
  92.     FOR a = 0 TO obj_c - 1: IF obj(a, 4) = 0 THEN _CONTINUE
  93.         x = cent_x + obj(a, 0) * zoom: y = cent_y + obj(a, 1) * zoom
  94.         IF mouse_near = a THEN COLOR _RGB32(255, 0, 0) ELSE COLOR _RGB32(200, 200, 200)
  95.         '        CIRCLE (x, y), obj(a, 2) * zoom: _PRINTSTRING (x, y), LTRIM$(STR$(a))
  96.     NEXT a
  97.  
  98.     'draw connections
  99.  
  100.     COLOR _RGB32(200, 200, 200)
  101.     FOR a = 0 TO conn_c - 1: IF conn(a, 3) = 0 THEN _CONTINUE
  102.         IF obj(conn(a, 0), 4) = 0 OR obj(conn(a, 1), 4) = 0 THEN _CONTINUE
  103.         x1 = obj(conn(a, 0), 0) * zoom + cent_x: y1 = obj(conn(a, 0), 1) * zoom + cent_y
  104.         x2 = obj(conn(a, 1), 0) * zoom + cent_x: y2 = obj(conn(a, 1), 1) * zoom + cent_y
  105.     LINE (x1, y1)-(x2, y2): NEXT a
  106.  
  107.  
  108.  
  109.     'calculate moving
  110.     FOR a = 0 TO obj_c - 1: obj(a, 6) = obj(a, 0): obj(a, 7) = obj(a, 1)
  111.         IF obj(a, 3) = 0 OR (mouse_near = a AND _MOUSEBUTTON(1)) OR obj(a, 4) = 0 THEN _CONTINUE
  112.         'connections vector
  113.         vec_x = 0: vec_y = 0: vec_c = 0
  114.         FOR t = 0 TO conn_c - 1: IF conn(t, 3) = 0 THEN _CONTINUE
  115.             x = -1: FOR t2 = 0 TO 1: IF conn(t, t2) = a THEN x = conn(t, t2 XOR 1)
  116.             NEXT t2
  117.             IF x <> -1 THEN
  118.                 IF obj(x, 4) THEN
  119.                     disx = obj(a, 0) - obj(x, 0)
  120.                     disy = obj(a, 1) - obj(x, 1)
  121.                     ang = (-degree(disx, disy) + 0) * pip180
  122.                     dis = SQR(disx * disx + disy * disy)
  123.                     power = (dis - conn(t, 2)) * .6 ' obj(a, 2) ^ 2 '/ 20
  124.                     IF stiff THEN power = power / obj(a, 2) ^ 2 * 4
  125.                     vec_x = vec_x + SIN(ang) * power
  126.                     vec_y = vec_y - COS(ang) * power
  127.                     vec_c = vec_c + 1
  128.                 END IF
  129.             END IF
  130.         NEXT t
  131.  
  132.         gravity = 0 '.1
  133.         lass = .90
  134.         obj(a, 4) = (obj(a, 4) + vec_x / vec_c) * lass
  135.         obj(a, 5) = (obj(a, 5) + vec_y / vec_c) * lass + gravity
  136.         obj(a, 6) = obj(a, 0) + obj(a, 4)
  137.         obj(a, 7) = obj(a, 1) + obj(a, 5)
  138.     NEXT a
  139.     FOR a = 0 TO obj_c - 1: FOR t = 0 TO 1: obj(a, t) = obj(a, 6 + t): NEXT t, a
  140.  
  141.  
  142.  
  143.  
  144.     'mouse moving activing
  145.     mw = 0: WHILE _MOUSEINPUT: mw = mw + _MOUSEWHEEL: WEND
  146.     mindis = 99999999
  147.     IF moving = 0 THEN
  148.         mouse_near = -1
  149.         FOR a = 0 TO obj_c - 1
  150.             disx = (cent_x + obj(a, 0) * zoom) - _MOUSEX
  151.             disy = (cent_y + obj(a, 1) * zoom) - _MOUSEY
  152.             dis = SQR(disx * disx + disy * disy)
  153.             IF dis < 60 AND mindis > dis THEN mouse_near = a:mindis = dis
  154.         NEXT a
  155.     END IF
  156.  
  157.     IF (_MOUSEBUTTON(1) AND mouse_near <> -1) OR moving THEN
  158.         moving = 1
  159.         obj(mouse_near, 0) = (_MOUSEX - cent_x) / zoom
  160.         obj(mouse_near, 1) = (_MOUSEY - cent_y) / zoom
  161.     END IF
  162.  
  163.     moving = moving AND _MOUSEBUTTON(1)
  164.  
  165.     stiff = stiff XOR ABS(inkey2$ = "s")
  166.  
  167.  
  168.     _DISPLAY: CLS
  169.  
  170.     'commands
  171.     inkey2$ = INKEY$: IF inkey2$ = CHR$(27) THEN END
  172.     IF inkey2$ = " " AND _MOUSEBUTTON(1) AND moving THEN obj(mouse_near, 3) = obj(mouse_near, 3) XOR 1
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. FUNCTION degree (a, b): degreex = ATN(a / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0): degree = degreex: END FUNCTION
  180.  
  181. FUNCTION randx (x): randx = x * RND(1) - x / 2: END FUNCTION

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Garland of pearls
« Reply #14 on: March 23, 2022, 08:00:58 pm »
There is much more to it than interesting!
I asked the question on a Hungarian physics forum on facebook. If there is a meaningful answer, I will inform you! It needs to be addressed!

Hello !
It will be a little longer now. I want an answer to a question I haven't been able to sleep in days :)
Anyone who follows the group may know that I am involved in programming. It used to be machine control, more recently the math behind games. (Interestingly, behind the game programming are the most outdated applications of mathematics)
My recent creations:


I have only considered it important to note this now because I have been dealing with them feverishly lately. The basic development environment, in which I program, can only draw 1 triangle on the screen. That's why I wrote the graphic "engine", the camera movement, the physical background of the movements myself. This developer is so unpopular that I don't think QB64 is known in Hungary. I like to be active in a foreign forum because there are about a handful of people (a handful on a global scale) who struggle with this outdated developer and appreciate it.
Here a forum member wrote a simulation of a pendulum motion. This should be imagined as a fixed point + rigid connector + some weight + rigid connector + some weight .... What happens if we push? He returned the thing quite realistically on the screen. It’s some crazy math, a lot of computation, and limited because it works with 2 “weights,” and with 3, but 4 or more has so much computation that it crumbles all over and can’t be shown in real time.
I had an idea then. What if we created points in space / plane without giving it fixed coordinates. All you need to know about that point is that it is located relative to another point. There should be nothing else for that point other than to strive to maintain its relation to the other point specified.
Do this: "current situation" = "current situation" + ("where you should be" - "current situation") x "all"
This is important here. If "all" is 0, no change is made. If 1, an immediate change occurs. If all are between 0 and 1, it gives a proportionality to the dynamics / flexibility / speed of change.
Now I want to express the point somehow. Imagine a "space." It contains objects. Objects are defined by point clouds. In point clouds, we make connections between points. To an adjacent, or object center, or just a smooth random point, we connect the 1 given point within the point cloud that we just want to define, "smart." We determine for him how far away he should be from that other point ... We will try to make as many such "connections" as possible at all points in that point and that object so that he is as smart as possible and will know "where he is. ".
If this is the case, start the "simulation"! Suppose thousands of points are defined as above. Each point begins to move at such a speed / direction that the connections assigned to it can be fulfilled. All right, we're waiting ... after a while, all movement will stop. "system balanced". The shapes are nicely outlined in front of us.
Now move only 1 out of position !!! that is, ONE point !!!!!!!! This will affect the points you are connected to ... and also the points you are connected to ... and those .... so everyone is running that 1 pulse. A mechanism is starting. Impulses give and take ...
The video shows how I programmed this principle differently. Chain, an image, and a cobweb. In each case, I gave relationships to the points as above. The thing works. And here comes the point. Smart people have already written the mathematical model for every event in Newtonian physics. Rigid-body, wave curves, collision of bodies, pendulum motion, centrifugal force .... what else to say ???????????????
This idea, which I did, completely bypasses the knowledge and use of these. The screen is fully functional. You don't need any physical knowledge or complications. We need a point and the strengths of its connections and connections (or how long we tie it to another point) (perhaps a metaphor for mass?)
Using the principle, we can in principle simulate all Newtonian physics by completely circumventing their use. Example..something .... if we create a brick wall based on the above principle, we can shoot a brick out of it so that the wall collapses in reality..etc ... that's just 1 of the many options.
Here's my question. Unfortunately, I did not study mathematics or physics at higher levels. I'm sure this thing isn't some kind of invention. This can only be new to me. This may be a known, existing theory that is also taught in good places. I would like to ask those who were so lucky to learn things like what it is? what is it used for where can i find writing about this
Thank you!

(just a small philosophical remark: if we hit the wall! the above principle would show the tiny vibration of every part of the wall. what if the above principle simulates the connection between molecules? since reality "renders" so fast that we can't even measure it with instruments, we're just amazed at the end result, because it happens so fast that we can't see, so we don't understand)
To download programs running under video (running under windows) with source code:
https://drive.google.com/file/d/1hkIqbFx_JGzhYpGdQjZ1h0lZYFtiw3Ce/view?usp=sharing

« Last Edit: March 23, 2022, 08:06:55 pm by MasterGy »