SHARE
TWEET

Untitled

a guest Oct 21st, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GlowScript 2.9 VPython
  2.  
  3. xmax = 100
  4. ymax = 100
  5. zmax = 100
  6.  
  7. # Количество  красных шариков
  8. a = 100
  9. # Количество синих шариков
  10. b = 100
  11.  
  12. # Радиус синих шариков
  13. arad = 1.6
  14. # Радиус красных шариков
  15. brad = 1.6
  16.  
  17. c = 0
  18. aact = a
  19. dt = 0.2
  20. deltat = 150
  21.  
  22. acolor = vector(1, 0.1, 0.1)
  23. bcolor = vector(0.2, 0.2, 1)
  24. ccolor = vector(0.1, 1, 0.1)
  25.  
  26. amol = []
  27. bmol = []
  28.  
  29. t = 0
  30. t1 = 0
  31.  
  32. for i in arange(a):
  33.     amol.append(sphere(pos=vector(xmax * random(), ymax * random(), zmax * random()), radius=arad, color=acolor))
  34.     amol[i].vel = vector(random() - 0.5, random() - 0.5, random() - 0.5)
  35.     amol[i].react = 0
  36.  
  37. for i in arange(b):
  38.     bmol.append(sphere(pos=vector(xmax * random(), ymax * random(), zmax * random()), radius=brad, color=bcolor))
  39.     bmol[i].vel = vector(random() - 0.5, random() - 0.5, random() - 0.5)
  40.     bmol[i].react = 0
  41.  
  42. xx = box(pos=vector(0, 0, 0), size=vector(0.2, 0.2, 0.2), color=vector(0.1, 0.1, 0.1))
  43.  
  44.  
  45. # def reaction():
  46. #     xx.pos = (1, 0, 0)
  47.  
  48.  
  49. # c = controls(title='Controlling the Scene', x=50, y=50, width=200, height=200, range=50)
  50. # but = button(pos=(0, 0), width=60, height=60, text='Go!', bind=lambda: reaction())
  51.  
  52. # box(pos=vector(-arad, ymax / 2., zmax / 2.), size=vector(0.5, ymax + 2 * arad, zmax + 2 * arad),
  53. #     color=vector(0.3, 0.3, 0.3))
  54. # box(pos=vector(xmax + arad, ymax / 2., zmax / 2.), size=vector(0.5, ymax + 2 * arad, zmax + 2 * arad),
  55. #     color=vector(0.3, 0.3, 0.3))
  56. # box(pos=vector(xmax / 2., -arad, zmax / 2.), size=vector(xmax + 2 * arad, 0.5, zmax + 2 * arad),
  57. #     color=vector(0.3, 0.3, 0.3))
  58. # box(pos=vector(xmax / 2., ymax + arad, zmax / 2.), size=vector(xmax + 2 * arad, 0.5, zmax + 2 * arad),
  59. #     color=vector(0.3, 0.3, 0.3))
  60. # box(pos=vector(xmax / 2., ymax / 2., -arad), size=vector(xmax + 2 * arad, ymax + 2 * arad, 0.5),
  61. #     color=vector(0.2, 0.2, 0.2))
  62.  
  63. box(pos=vector(-arad, ymax / 2., zmax / 2.), size=vector(0.5, ymax + 2 * arad, zmax + 2 * arad),
  64.     color=vector(0.3, 0.3, 0.3))
  65. box(pos=vector(xmax + arad, ymax / 2., zmax / 2.), size=vector(0.5, ymax + 2 * arad, zmax + 2 * arad),
  66.     color=vector(0.3, 0.3, 0.3))
  67. box(pos=vector(xmax / 2., -arad, zmax / 2.), size=vector(xmax + 2 * arad, 0.5, zmax + 2 * arad),
  68.     color=vector(0.3, 0.3, 0.3))
  69. box(pos=vector(xmax / 2., ymax + arad, zmax / 2.), size=vector(xmax + 2 * arad, 0.5, zmax + 2 * arad),
  70.     color=vector(0.3, 0.3, 0.3))
  71. box(pos=vector(xmax / 2., ymax / 2., -arad), size=vector(xmax + 2 * arad, ymax + 2 * arad, 0.5),
  72.     color=vector(0.2, 0.2, 0.2))
  73.  
  74. while xx.pos == (0, 0, 0):
  75.     rate(5000)
  76.     for i in arange(a):
  77.         if amol[i].pos.x >= xmax - arad:
  78.             amol[i].vel.x = -amol[i].vel.x
  79.         if amol[i].pos.x <= arad:
  80.             amol[i].vel.x = -amol[i].vel.x
  81.         if amol[i].pos.y >= ymax - arad:
  82.             amol[i].vel.y = -amol[i].vel.y
  83.         if amol[i].pos.y <= arad:
  84.             amol[i].vel.y = -amol[i].vel.y
  85.         if amol[i].pos.z >= ymax - arad:
  86.             amol[i].vel.z = -amol[i].vel.z
  87.         if amol[i].pos.z <= arad:
  88.             amol[i].vel.z = -amol[i].vel.z
  89.         amol[i].pos = amol[i].pos + amol[i].vel * dt
  90.  
  91.     for i in arange(b):
  92.         if bmol[i].pos.x >= xmax - brad:
  93.             bmol[i].vel.x = -bmol[i].vel.x
  94.         if bmol[i].pos.x <= brad:
  95.             bmol[i].vel.x = -bmol[i].vel.x
  96.         if bmol[i].pos.y >= ymax - brad:
  97.             bmol[i].vel.y = -bmol[i].vel.y
  98.         if bmol[i].pos.y <= brad:
  99.             bmol[i].vel.y = -bmol[i].vel.y
  100.         if bmol[i].pos.z >= ymax - brad:
  101.             bmol[i].vel.z = -bmol[i].vel.z
  102.         if bmol[i].pos.z <= brad:
  103.             bmol[i].vel.z = -bmol[i].vel.z
  104.         bmol[i].pos = bmol[i].pos + bmol[i].vel * dt
  105.         for j in arange(a):
  106.             if mag(amol[j].pos - bmol[i].pos) <= arad + brad:
  107.                 bmol[i].vel = bmol[i].vel + (dot(amol[j].vel - bmol[i].vel, bmol[i].pos - amol[j].pos) / (
  108.                         mag(amol[j].pos - bmol[i].pos) ** 2)) * (bmol[i].pos - amol[j].pos)
  109.                 amol[j].vel = amol[j].vel - (dot(amol[j].vel - bmol[i].vel, bmol[i].pos - amol[j].pos) / (
  110.                         mag(amol[j].pos - bmol[i].pos) ** 2)) * (bmol[i].pos - amol[j].pos)
  111.  
  112. while t <= True:
  113.     rate(50)
  114.     for i in arange(a):
  115.         if amol[i].pos.x >= xmax - arad:
  116.             amol[i].vel.x = -amol[i].vel.x
  117.         if amol[i].pos.x <= arad:
  118.             amol[i].vel.x = -amol[i].vel.x
  119.         if amol[i].pos.y >= ymax - arad:
  120.             amol[i].vel.y = -amol[i].vel.y
  121.         if amol[i].pos.y <= arad:
  122.             amol[i].vel.y = -amol[i].vel.y
  123.         if amol[i].pos.z >= ymax - arad:
  124.             amol[i].vel.z = -amol[i].vel.z
  125.         if amol[i].pos.z <= arad:
  126.             amol[i].vel.z = -amol[i].vel.z
  127.         amol[i].pos = amol[i].pos + amol[i].vel * dt
  128.  
  129.     for i in arange(b):
  130.         if bmol[i].pos.x >= xmax - brad:
  131.             bmol[i].vel.x = -bmol[i].vel.x
  132.         if bmol[i].pos.x <= brad:
  133.             bmol[i].vel.x = -bmol[i].vel.x
  134.         if bmol[i].pos.y >= ymax - brad:
  135.             bmol[i].vel.y = -bmol[i].vel.y
  136.         if bmol[i].pos.y <= brad:
  137.             bmol[i].vel.y = -bmol[i].vel.y
  138.         if bmol[i].pos.z >= ymax - brad:
  139.             bmol[i].vel.z = -bmol[i].vel.z
  140.         if bmol[i].pos.z <= brad:
  141.             bmol[i].vel.z = -bmol[i].vel.z
  142.         bmol[i].pos = bmol[i].pos + bmol[i].vel * dt
  143.         for j in arange(a):
  144.             if mag(amol[j].pos - bmol[i].pos) <= arad + brad:
  145.                 bmol[i].vel = bmol[i].vel + (dot(amol[j].vel - bmol[i].vel, bmol[i].pos - amol[j].pos) / (
  146.                         mag(amol[j].pos - bmol[i].pos) ** 2)) * (bmol[i].pos - amol[j].pos)
  147.                 amol[j].vel = amol[j].vel - (dot(amol[j].vel - bmol[i].vel, bmol[i].pos - amol[j].pos) / (
  148.                         mag(amol[j].pos - bmol[i].pos) ** 2)) * (bmol[i].pos - amol[j].pos)
  149.                 if amol[j].react == 0:
  150.                     if bmol[i].react == 0:
  151.                         amol[j].react = 1
  152.                         bmol[i].react = 1
  153.                         amol[j].color = ccolor
  154.                         bmol[i].color = ccolor
  155.                         aact = aact - 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top