Author Topic: Boid Watching  (Read 4571 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Boid Watching
« on: April 28, 2018, 11:34:52 pm »
Edit: Add some background info
At JB the subject of Boids came up but I couldn't get what bluatigro was talking about, then I found the youtube videos!
Boids is like birds flocking and breaking apart and regrouping...
Quote
Oh hey! I decided to look up boid, thinking bluatigro might be trying for bird, I ran into this almost immediately:
www.youtube.com/watch?v=GUkjC-69vaw

and the one right after too, (not any more)
www.youtube.com/watch?v=QbUPfMXXQIY

cool!

Boid Rules (these can be turned on or off, so you get all kinds of variations of "behavior"):
1. Avoid barriers / obstacles
2. Head in same direction as your "radial" group
3. Head or Group towards "center of gravity" so to speak
4. Space out while grouping, don't get too close or overlap.

I was using mouse position as centering / obstacle toggle.

In video's I liked how they formed particular groups, not just one big one around mouse position.


Got it going pretty well now, watch the critters flock and break apart and re-qroup in different groups:
Code: QB64: [Select]
  1. _TITLE "Boid Watching   by bplus 2018-04-28"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3. 'from
  4. 'Boid Watching.txt for JB 2.0 B+ 2018-04-28
  5. 'from
  6. 'networking.bas  SmallBASIC 0.12.9 [B+=MGA] 2017-04-14
  7. ' combined with
  8. 'Mouse school critter attract or repell.txt for JB 2.0 B+ 2018-04-26
  9. ' plus what I picked up generally from the videos
  10.  
  11. CONST xmax = 1200
  12. CONST ymax = 700
  13. SCREEN _NEWIMAGE(xmax, ymax, 32)
  14. _SCREENMOVE 100, 40
  15.  
  16.  
  17. 'Boid behavior based on several modes
  18.  
  19. centerMode = 1 ' on / off
  20. cf = .01 'centering factor how strong a pull from 0 to 1  .01 is week .1 pretty strong!
  21.  
  22. headMode = 1 ' on / off
  23. sway = _PI / 6 'just turn neighbor towards neighbor
  24. hf = .2 'heading factor how strong an influence  0 to 1
  25.  
  26. spaceMode = 1 ' on / off
  27. spacing = 15 'space amount approx
  28.  
  29. noise = 0 'general randomness added to movements individualism
  30.  
  31. Boids = 20
  32.  
  33. DIM SHARED x(Boids), y(Boids), a(Boids), r(Boids), c&(Boids), predator
  34.  
  35. FOR i = 1 TO Boids
  36.     newCritter i
  37.  
  38.     CLS
  39.     IF INKEY$ = "q" THEN END
  40.     FOR i = 1 TO Boids
  41.         m = _MOUSEINPUT: mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
  42.  
  43.         FOR j = i + 1 TO Boids
  44.  
  45.             IF distance(x(i), y(i), x(j), y(j)) < 100 THEN
  46.  
  47.                 'sway the neighbors towards each other
  48.                 IF headMode THEN
  49.                     IF a(i) > a(j) THEN
  50.                         a(i) = a(i) - sway * hf
  51.                         a(j) = a(j) + sway * hf
  52.                     ELSE
  53.                         a(i) = a(i) + sway * hf
  54.                         a(j) = a(j) - sway * hf
  55.                     END IF
  56.                 END IF
  57.  
  58.                 'stickiness stay close to neighbors, close distance between
  59.                 IF centerMode THEN
  60.                     IF x(i) > x(j) THEN
  61.                         x(i) = x(i) - cf * (x(i) - x(j))
  62.                         x(j) = x(j) + cf * (x(i) - x(j))
  63.                     ELSE
  64.                         x(i) = x(i) + cf * (x(j) - x(i))
  65.                         x(j) = x(j) - cf * (x(j) - x(i))
  66.                     END IF
  67.                     IF y(i) > y(j) THEN
  68.                         y(i) = y(i) - cf * (y(i) - y(j))
  69.                         y(j) = y(j) + cf * (y(i) - y(j))
  70.                     ELSE
  71.                         y(i) = y(i) + cf * (y(j) - y(i))
  72.                         y(j) = y(j) - cf * (y(j) - y(i))
  73.                     END IF
  74.                 END IF
  75.  
  76.                 'don't let them bunch up
  77.                 IF spaceMode THEN
  78.                     ' The following is STATIC's adjustment of ball positions if overlapping
  79.                     ' before calcultion of new positions from collision
  80.                     ' Displacement vector and its magnitude.  Thanks STxAxTIC !
  81.                     nx = x(j) - x(i)
  82.                     ny = y(j) - y(i)
  83.                     nm = SQR(nx ^ 2 + ny ^ 2)
  84.                     IF nm < spacing + 20 THEN
  85.                         nx = nx / nm
  86.                         ny = ny / nm
  87.                         ' Regardless of momentum exchange, separate the balls along the lone connecting them.
  88.                         WHILE nm < spacing + 30
  89.                             x(j) = x(j) + .1 * spacing * nx
  90.                             y(j) = y(j) + .1 * spacing * ny
  91.                             x(i) = x(i) - .1 * spacing * nx
  92.                             y(i) = y(i) - .1 * spacing * ny
  93.                             nx = x(j) - x(i)
  94.                             ny = y(j) - y(i)
  95.                             nm = SQR(nx ^ 2 + ny ^ 2)
  96.                             nx = nx / nm
  97.                             ny = ny / nm
  98.                         WEND
  99.                     END IF 'spacer
  100.                 END IF 'space Mode
  101.             END IF 'distance
  102.         NEXT
  103.         IF x(i) < 30 OR x(i) > xmax - 30 OR y(i) < 30 OR y(i) > ymax - 30 THEN a(i) = a(i) + sway
  104.         'out of sight
  105.         IF x(i) < -1 * r(i) OR x(i) > xmax + r(i) OR y(i) < -1 * r(i) OR y(i) > ymax + r(i) THEN 'start new
  106.             newCritter i
  107.         END IF
  108.         IF distance(x(i), y(i), mx, my) < 75 THEN
  109.             a(i) = _ATAN2(my - y(i), mx - x(i)) + _PI
  110.             predatorMode = 1
  111.         ELSE
  112.             predatorMode = 0
  113.         END IF
  114.  
  115.         'update points
  116.         x(i) = x(i) + 10 * COS(a(i)) + RND * noise - .5 * noise
  117.         y(i) = y(i) + 10 * SIN(a(i)) + RND * noise - .5 * noise
  118.  
  119.         critter i
  120.  
  121.     NEXT
  122.     'mouse predator
  123.     COLOR _RGB32(160, 0, 0)
  124.     fcirc mx, my, 25
  125.  
  126.     _DISPLAY
  127.     _LIMIT 20
  128.  
  129. SUB newCritter (index)
  130.     x(index) = rand(0, xmax)
  131.     y(index) = rand(0, ymax)
  132.     a(index) = -2 * _PI * RND
  133.     r(index) = rand(10, 15)
  134.     c&(index) = _RGB32(rand(64, 155), rand(64, 155), rand(64, 155))
  135.  
  136. SUB critter (i)
  137.     COLOR c&(i)
  138.     fcirc x(i), y(i), r(i)
  139.     IF predator THEN
  140.         x1 = x(i) + .75 * r(i) * COS(a(i) - _PI(1 / 9) + _PI)
  141.         y1 = y(i) + .75 * r(i) * SIN(a(i) - _PI(1 / 9) + _PI)
  142.         x2 = x(i) + .75 * r(i) * COS(a(i) + _PI(1 / 9) + _PI)
  143.         y2 = y(i) + .75 * r(i) * SIN(a(i) + _PI(1 / 9) + _PI)
  144.     ELSE
  145.         x1 = x(i) + .75 * r(i) * COS(a(i) - _PI(1 / 9))
  146.         y1 = y(i) + .75 * r(i) * SIN(a(i) - _PI(1 / 9))
  147.         x2 = x(i) + .75 * r(i) * COS(a(i) + _PI(1 / 9))
  148.         y2 = y(i) + .75 * r(i) * SIN(a(i) + _PI(1 / 9))
  149.     END IF
  150.     COLOR _RGB32(255, 255, 255)
  151.     fcirc x1, y1, .25 * r(i)
  152.     fcirc x2, y2, .25 * r(i)
  153.     IF predator THEN
  154.         x3 = x1 + .125 * r(i) * COS(a(i) + _PI)
  155.         y3 = y1 + .125 * r(i) * SIN(a(i) + _PI)
  156.         x4 = x2 + .125 * r(i) * COS(a(i) + _PI)
  157.         y4 = y2 + .125 * r(i) * SIN(a(i) + _PI)
  158.     ELSE
  159.         x3 = x1 + .125 * r(i) * COS(a(i))
  160.         y3 = y1 + .125 * r(i) * SIN(a(i))
  161.         x4 = x2 + .125 * r(i) * COS(a(i))
  162.         y4 = y2 + .125 * r(i) * SIN(a(i))
  163.     END IF
  164.     COLOR _RGB32(0, 0, 0)
  165.     fcirc x3, y3, .125 * r(i)
  166.     fcirc x4, y4, .125 * r(i)
  167.  
  168. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  169. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  170.     DIM subRadius AS LONG, RadiusError AS LONG
  171.     DIM X AS LONG, Y AS LONG
  172.  
  173.     subRadius = ABS(R)
  174.     RadiusError = -subRadius
  175.     X = subRadius
  176.     Y = 0
  177.  
  178.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  179.  
  180.     ' Draw the middle span here so we don't draw it twice in the main loop,
  181.     ' which would be a problem with blending turned on.
  182.     LINE (CX - X, CY)-(CX + X, CY), , BF
  183.  
  184.     WHILE X > Y
  185.         RadiusError = RadiusError + Y * 2 + 1
  186.         IF RadiusError >= 0 THEN
  187.             IF X <> Y + 1 THEN
  188.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  189.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  190.             END IF
  191.             X = X - 1
  192.             RadiusError = RadiusError - X * 2
  193.         END IF
  194.         Y = Y + 1
  195.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  196.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  197.     WEND
  198.  
  199. FUNCTION rand% (lo%, hi%)
  200.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  201.  
  202. FUNCTION distance (x1, y1, x2, y2)
  203.     distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
  204.  
  205. FUNCTION rdir ()
  206.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  207.  
  208.  
« Last Edit: April 29, 2018, 09:05:27 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boid Watching
« Reply #1 on: April 29, 2018, 07:15:06 pm »
Too many balls, too silly?

Here Boids Watch 2:
Code: QB64: [Select]
  1. _TITLE "Boid Watching 2  by bplus 2018-04-29"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3. 'from Boid Watching.bas for QB64 version 2017 1106/82 B+ 2018-04-28
  4. 'from Boid Watching.txt for JB 2.0 B+ 2018-04-28
  5. 'from networking.bas  SmallBASIC 0.12.9 [B+=MGA] 2017-04-14
  6. ' combined with
  7. 'Mouse school critter attract or repell.txt for JB 2.0 B+ 2018-04-26
  8. ' plus what I picked up generally from the videos
  9.  
  10. CONST xmax = 1200
  11. CONST ymax = 700
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 100, 40
  14.  
  15.  
  16. 'Boid behavior based on several modes
  17.  
  18. centerMode = 1 ' on / off
  19. cf = .01 'centering factor how strong a pull from 0 to 1  .01 is week .1 pretty strong!
  20.  
  21. headMode = 1 ' on / off
  22. sway = _PI / 6 'just turn neighbor towards neighbor
  23. hf = .2 'heading factor how strong an influence  0 to 1
  24.  
  25. spaceMode = 1 ' on / off
  26. spacing = 15 'space amount approx
  27.  
  28. noise = 10 'general randomness added to movements individualism
  29.  
  30. Boids = 50
  31.  
  32. DIM SHARED x(Boids), y(Boids), z(Boids), a(Boids), r(Boids), c(Boids) AS _UNSIGNED LONG, predator
  33.  
  34. FOR i = 1 TO Boids
  35.     newCritter i
  36.  
  37. land& = _NEWIMAGE(xmax, ymax, 32)
  38. _DEST land&
  39. drawLandscape
  40.  
  41.     _PUTIMAGE , land&, 0
  42.     IF INKEY$ = "q" THEN END
  43.     FOR i = 1 TO Boids
  44.         m = _MOUSEINPUT: mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
  45.  
  46.         FOR j = i + 1 TO Boids
  47.  
  48.             IF distance(x(i), y(i), x(j), y(j)) < 100 THEN
  49.  
  50.                 'sway the neighbors towards each other
  51.                 IF headMode THEN
  52.                     IF a(i) > a(j) THEN
  53.                         a(i) = a(i) - sway * hf
  54.                         a(j) = a(j) + sway * hf
  55.                     ELSE
  56.                         a(i) = a(i) + sway * hf
  57.                         a(j) = a(j) - sway * hf
  58.                     END IF
  59.                 END IF
  60.  
  61.                 'stickiness stay close to neighbors, close distance between
  62.                 IF centerMode THEN
  63.                     IF x(i) > x(j) THEN
  64.                         x(i) = x(i) - cf * (x(i) - x(j))
  65.                         x(j) = x(j) + cf * (x(i) - x(j))
  66.                     ELSE
  67.                         x(i) = x(i) + cf * (x(j) - x(i))
  68.                         x(j) = x(j) - cf * (x(j) - x(i))
  69.                     END IF
  70.                     IF y(i) > y(j) THEN
  71.                         y(i) = y(i) - cf * (y(i) - y(j))
  72.                         y(j) = y(j) + cf * (y(i) - y(j))
  73.                     ELSE
  74.                         y(i) = y(i) + cf * (y(j) - y(i))
  75.                         y(j) = y(j) - cf * (y(j) - y(i))
  76.                     END IF
  77.                 END IF
  78.  
  79.                 'don't let them bunch up
  80.                 IF spaceMode THEN
  81.                     ' The following is STATIC's adjustment of ball positions if overlapping
  82.                     ' before calcultion of new positions from collision
  83.                     ' Displacement vector and its magnitude.  Thanks STxAxTIC !
  84.                     nx = x(j) - x(i)
  85.                     ny = y(j) - y(i)
  86.                     nm = SQR(nx ^ 2 + ny ^ 2)
  87.                     IF nm < spacing + 20 THEN
  88.                         nx = nx / nm
  89.                         ny = ny / nm
  90.                         ' Regardless of momentum exchange, separate the balls along the lone connecting them.
  91.                         WHILE nm < spacing + 30
  92.                             x(j) = x(j) + .1 * spacing * nx
  93.                             y(j) = y(j) + .1 * spacing * ny
  94.                             x(i) = x(i) - .1 * spacing * nx
  95.                             y(i) = y(i) - .1 * spacing * ny
  96.                             nx = x(j) - x(i)
  97.                             ny = y(j) - y(i)
  98.                             nm = SQR(nx ^ 2 + ny ^ 2)
  99.                             nx = nx / nm
  100.                             ny = ny / nm
  101.                         WEND
  102.                     END IF 'spacer
  103.                 END IF 'space Mode
  104.             END IF 'distance
  105.         NEXT
  106.         IF y(i) < 30 OR y(i) > ymax - 30 THEN a(i) = a(i) + sway
  107.         'out of sight
  108.         IF x(i) < -1 * r(i) OR x(i) > xmax + r(i) OR y(i) < -1 * r(i) OR y(i) > ymax + r(i) THEN 'start new
  109.             newCritter i
  110.         END IF
  111.         IF distance(x(i), y(i), mx, my) < 75 THEN
  112.             a(i) = _ATAN2(my - y(i), mx - x(i)) + _PI
  113.             predatorMode = 1
  114.         ELSE
  115.             predatorMode = 0
  116.         END IF
  117.  
  118.         'update points
  119.         x(i) = x(i) + 10 * COS(a(i)) + RND * noise - .5 * noise
  120.         y(i) = y(i) + 10 * SIN(a(i)) + RND * noise - .5 * noise
  121.  
  122.         drawBoid i
  123.  
  124.     NEXT
  125.     'mouse predator
  126.     'COLOR _RGB32(160, 0, 0)
  127.     'fcirc mx, my, 25
  128.  
  129.     _DISPLAY
  130.     _LIMIT 20
  131.  
  132. SUB newCritter (index)
  133.     x(index) = rand(xmax, xmax + 100)
  134.     y(index) = rand(100, ymax - 50)
  135.     z(index) = RND * .6 + .4
  136.     a(index) = _PI * RND + _PI(.5)
  137.     r(index) = rand(10, 12)
  138.     r = rand(10 + INT(z(i) * 40), 40 + INT(z(i) * 40))
  139.     c(index) = _RGB32(r, r, r)
  140.  
  141. SUB critter (i)
  142.     COLOR c&(i)
  143.     fcirc x(i), y(i), r(i)
  144.     IF predator THEN
  145.         x1 = x(i) + .75 * r(i) * COS(a(i) - _PI(1 / 9) + _PI)
  146.         y1 = y(i) + .75 * r(i) * SIN(a(i) - _PI(1 / 9) + _PI)
  147.         x2 = x(i) + .75 * r(i) * COS(a(i) + _PI(1 / 9) + _PI)
  148.         y2 = y(i) + .75 * r(i) * SIN(a(i) + _PI(1 / 9) + _PI)
  149.     ELSE
  150.         x1 = x(i) + .75 * r(i) * COS(a(i) - _PI(1 / 9))
  151.         y1 = y(i) + .75 * r(i) * SIN(a(i) - _PI(1 / 9))
  152.         x2 = x(i) + .75 * r(i) * COS(a(i) + _PI(1 / 9))
  153.         y2 = y(i) + .75 * r(i) * SIN(a(i) + _PI(1 / 9))
  154.     END IF
  155.     COLOR _RGB32(255, 255, 255)
  156.     fcirc x1, y1, .25 * r(i)
  157.     fcirc x2, y2, .25 * r(i)
  158.     IF predator THEN
  159.         x3 = x1 + .125 * r(i) * COS(a(i) + _PI)
  160.         y3 = y1 + .125 * r(i) * SIN(a(i) + _PI)
  161.         x4 = x2 + .125 * r(i) * COS(a(i) + _PI)
  162.         y4 = y2 + .125 * r(i) * SIN(a(i) + _PI)
  163.     ELSE
  164.         x3 = x1 + .125 * r(i) * COS(a(i))
  165.         y3 = y1 + .125 * r(i) * SIN(a(i))
  166.         x4 = x2 + .125 * r(i) * COS(a(i))
  167.         y4 = y2 + .125 * r(i) * SIN(a(i))
  168.     END IF
  169.     COLOR _RGB32(0, 0, 0)
  170.     fcirc x3, y3, .125 * r(i)
  171.     fcirc x4, y4, .125 * r(i)
  172.  
  173. SUB drawBoid (i)
  174.     r = RND * _PI(1 / 4) 'flapping
  175.     w = _PI(7 / 12)
  176.     IF predator THEN
  177.         x1 = x(i) + z(i) * r(i) * COS(a(i) + _PI)
  178.         y1 = y(i) + z(i) * r(i) * SIN(a(i) + _PI)
  179.         x2 = x(i) + z(i) * r(i) * COS(a(i) + _PI + w + r)
  180.         y2 = y(i) + z(i) * r(i) * SIN(a(i) + _PI + w + r)
  181.         x3 = x(i) + z(i) * r(i) * COS(a(i) + _PI - w - r)
  182.         y3 = y(i) + z(i) * r(i) * SIN(a(i) + _PI - w - r)
  183.  
  184.     ELSE
  185.         x1 = x(i) + z(i) * r(i) * COS(a(i))
  186.         y1 = y(i) + z(i) * r(i) * SIN(a(i))
  187.         x2 = x(i) + z(i) * r(i) * COS(a(i) + w + r)
  188.         y2 = y(i) + z(i) * r(i) * SIN(a(i) + w + r)
  189.         x3 = x(i) + z(i) * r(i) * COS(a(i) - w - r)
  190.         y3 = y(i) + z(i) * r(i) * SIN(a(i) - w - r)
  191.     END IF
  192.     filltri x(i), y(i), x1, y1, x2, y2, c(i)
  193.     filltri x(i), y(i), x1, y1, x3, y3, c(i)
  194.  
  195. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  196. SUB filltri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  197.     a& = _NEWIMAGE(1, 1, 32)
  198.     _DEST a&
  199.     PSET (0, 0), K
  200.     _DEST 0
  201.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  202.     _FREEIMAGE a& '<<< this is important!
  203.  
  204. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  205. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  206.     DIM subRadius AS LONG, RadiusError AS LONG
  207.     DIM X AS LONG, Y AS LONG
  208.  
  209.     subRadius = ABS(R)
  210.     RadiusError = -subRadius
  211.     X = subRadius
  212.     Y = 0
  213.  
  214.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  215.  
  216.     ' Draw the middle span here so we don't draw it twice in the main loop,
  217.     ' which would be a problem with blending turned on.
  218.     LINE (CX - X, CY)-(CX + X, CY), , BF
  219.  
  220.     WHILE X > Y
  221.         RadiusError = RadiusError + Y * 2 + 1
  222.         IF RadiusError >= 0 THEN
  223.             IF X <> Y + 1 THEN
  224.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  225.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  226.             END IF
  227.             X = X - 1
  228.             RadiusError = RadiusError - X * 2
  229.         END IF
  230.         Y = Y + 1
  231.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  232.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  233.     WEND
  234.  
  235. FUNCTION rand% (lo%, hi%)
  236.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  237.  
  238. FUNCTION distance (x1, y1, x2, y2)
  239.     distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
  240.  
  241. FUNCTION rdir ()
  242.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  243.  
  244. SUB drawLandscape
  245.     'the sky
  246.     FOR i = 0 TO ymax
  247.         midInk 0, 0, 128, 128, 128, 255, i / ymax
  248.         LINE (0, i)-(xmax, i)
  249.     NEXT
  250.     'the land
  251.     startH = ymax - 200
  252.     rr = 70: gg = 70: bb = 90
  253.     FOR mountain = 1 TO 6
  254.         Xright = 0
  255.         y = startH
  256.         WHILE Xright < xmax
  257.             ' upDown = local up / down over range, change along Y
  258.             ' range = how far up / down, along X
  259.             upDown = (RND * .8 - .35) * (mountain * .5)
  260.             range = Xright + rand(15, 25) * 2.5 / mountain
  261.             lastx = Xright - 1
  262.             FOR X = Xright TO range
  263.                 y = y + upDown
  264.                 COLOR _RGB(rr, gg, bb)
  265.                 LINE (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  266.                 lastx = X
  267.             NEXT
  268.             Xright = range
  269.         WEND
  270.         rr = rand(rr - 15, rr): gg = rand(gg - 15, gg): bb = rand(bb - 25, bb)
  271.         IF rr < 0 THEN rr = 0
  272.         IF gg < 0 THEN gg = 0
  273.         IF bb < 0 THEN bb = 0
  274.         startH = startH + rand(5, 20)
  275.     NEXT
  276.  
  277. SUB midInk (r1, g1, b1, r2, g2, b2, fr)
  278.     COLOR _RGB(r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr)
Boid Watch 2.PNG
* Boid Watch 2.PNG (Filesize: 14.51 KB, Dimensions: 1196x718, Views: 394)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Boid Watching
« Reply #2 on: May 09, 2018, 10:25:24 am »
Nice work bplus! :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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