Author Topic: Boid Watching No 2.  (Read 6796 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Boid Watching No 2.
« on: September 06, 2018, 01:49:12 pm »
Originally posted at net, my best QB64 version of my take on Boids.
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)
  279.  

Think and use your mouse as a predator disrupting the flocking.
« Last Edit: September 06, 2018, 01:51:21 pm by bplus »

FellippeHeitor

  • Guest
Re: Boid Watching No 2.
« Reply #1 on: September 06, 2018, 02:32:23 pm »
That's really cool! I somehow managed to miss it at .net. Really good job on this one.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Boid Watching No 2.
« Reply #2 on: September 06, 2018, 02:48:32 pm »
Yeah, this is cool!
In order to understand recursion, one must first understand recursion.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Boid Watching No 2.
« Reply #3 on: September 06, 2018, 03:41:57 pm »
Yes, it is really very cool.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boid Watching No 2.
« Reply #4 on: September 06, 2018, 04:46:11 pm »
Thanks guys.

When I went grocery shopping today, I broke into cold sweat betting I had posted that code already. I did, as well as the earlier one, Mouse school of critters.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Boid Watching No 2.
« Reply #5 on: September 06, 2018, 05:33:56 pm »
Interesting how a larger 'group' seems to 'adopt' the stray smaller groups or individuals... Cool

Nice job... Got any more? (he asked knowingly... lol)

J
Logic is the beginning of wisdom.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Boid Watching No 2.
« Reply #6 on: September 06, 2018, 05:42:12 pm »
Really Nice!

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boid Watching No 2.
« Reply #7 on: September 06, 2018, 05:47:04 pm »
Thanks Dav, where were you guys when I first posted? Pete liked it, that's what happened. :D

Hey Johnno! Did we do a Bowling translation to QB64 yet?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Boid Watching No 2.
« Reply #8 on: September 06, 2018, 09:44:55 pm »
I've always wanted to try my hand at boid programing. never found very good tutorials\information. This is pretty cool.

your boids seem to have a tendency to fly up. if you set it to 150\200 its almost a continuous curve up.
setting above 250 is just funky doesn't really seem to work. and at 500 is super slow even with the _limit turned off.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boid Watching No 2.
« Reply #9 on: September 07, 2018, 12:27:21 am »
They had a tenacious tendency to fly left, so I have them coming in from right starting with the general direction of left. Going with the flow, so you know.

The flying up might be a part of boundary avoidance, instead of going in reverse direction they turn away, same with predator = mouse. Flying left and turning clockwise to avoid boundaries, predator or other birds = upwards tendency?

I don't know what you are referring to with numbers, Oh boids! it's been months since I worked the code. Yes, like in nature it is a delicate balance with the higher amounts of boids you would have to cut back on centering rule, and allow less spacing. They are all trying to avoid flying into each other while at same time obeying a centering number (schooling) and heading number.

« Last Edit: September 07, 2018, 12:42:07 am by bplus »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Boid Watching No 2.
« Reply #10 on: September 08, 2018, 07:35:01 pm »
That was cool. I think I'll have to study the landscape SUB, it was pretty aesthetically convincing for a random generation.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boid Watching No 2.
« Reply #11 on: September 08, 2018, 11:15:36 pm »
That was cool. I think I'll have to study the landscape SUB, it was pretty aesthetically convincing for a random generation.

I picked up that trick hanging out at Basic forums.

Here's a really nice one from net when a number of us contributed mods:
Code: QB64: [Select]
  1. 'recurring lightning w Fade.bas for QB64 fork 2017-08-23
  2. 'translated from: recurring lightning.bas for SmallBASIC 0.12.9 2017-08-22
  3. 'translated from: recurring lightning.txt for JB (B+=MGA) 2017-08-21
  4. '2017-10-10 fade by TylerDarko and Branching Lightning by RhoSigma
  5.  
  6. CONST xmax = 800
  7. CONST ymax = 600
  8. CONST FORKINESS = 15 '1 to 20
  9.  
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _TITLE "Recurring Branching Lightning with Fade"
  12.  
  13. flash& = _NEWIMAGE(xmax, ymax, 32)
  14. land& = _NEWIMAGE(xmax, ymax, 32)
  15. _DEST land&
  16. drawLandscape
  17.  
  18.     _PUTIMAGE , land&, 0
  19.     _DEST flash&
  20.     CLS , _RGBA32(0, 0, 0, 0)
  21.     SELECT CASE rand&&(0, 180)
  22.         CASE 0 TO 35
  23.             DrawLightning (xmax - 1), rand&&(20, 100), 50, 3.141592653, 1
  24.         CASE 36 TO 71
  25.             DrawLightning rand&&((xmax / 2) + 75, (xmax - 1)), 0, 50, 2.35619449, 1
  26.         CASE 72 TO 107
  27.             DrawLightning rand&&((xmax / 2) - 75, (xmax / 2) + 75), 0, 50, 1.570796326, 1
  28.         CASE 108 TO 144
  29.             DrawLightning rand&&(0, (xmax / 2) - 75), 0, 50, 0.785398163, 1
  30.         CASE 145 TO 180
  31.             DrawLightning 0, rand&&(20, 100), 50, 0.0, 1
  32.     END SELECT
  33.     _DEST 0
  34.     _PUTIMAGE , flash&, 0
  35.     _DISPLAY
  36.     _DELAY 0.05
  37.     pulse% = rand&&(0, 2)
  38.     FOR fade% = 1 TO 24
  39.         LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA32(0, 0, 0, 25), BF
  40.         IF fade% > 3 AND pulse% > 0 AND rand&&(0, 99) > 50 THEN
  41.             _PUTIMAGE , land&, 0
  42.             _PUTIMAGE , flash&, 0
  43.             pulse% = pulse% - 1
  44.             fade% = 1
  45.         END IF
  46.         _DISPLAY
  47.         _LIMIT 80
  48.     NEXT fade%
  49.     _PUTIMAGE , land&, 0
  50.     FOR fade% = 1 TO 24
  51.         LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA32(0, 0, 0, 25), BF
  52.     NEXT fade%
  53.     _DISPLAY
  54.     rpause = rand&&(50, 2000)
  55.     _DELAY rpause / 1000 '<< adjust time as needed for your system
  56.  
  57. '============================================================
  58.  
  59. SUB DrawLightning (X&, Y&, Segments&, Dir#, Fork&)
  60.     Sign# = 0.392699081
  61.     xSeg# = xmax / (15.0 * Fork&)
  62.     ySeg# = ymax / (15.0 * Fork&)
  63.     DO
  64.         Angle& = rand&&(0, 99)
  65.         DeltaAngle# = Sign# * Angle& / 100.0
  66.         Dir# = Dir# + DeltaAngle#
  67.         Sign# = Sign# * -1.0
  68.  
  69.         nX& = X& + (COS(Dir#) * xSeg#)
  70.         nY& = Y& + (SIN(Dir#) * ySeg#)
  71.         cc&& = _RGBA32(128, RND * 55 + 200, RND * 55 + 200, 20 * FORKINESS / Fork&)
  72.         DrawLine X&, Y&, nX&, nY&, cc&&
  73.         X& = nX&
  74.         Y& = nY&
  75.  
  76.         IF ((Fork& < 3) AND (INT(RND(1) * 50) < (FORKINESS / Fork&))) THEN
  77.             DrawLightning (X&), (Y&), 5 + INT(RND(1) * 10), Dir# - (2.0 * DeltaAngle#), Fork& + 1
  78.         END IF
  79.         Segments& = Segments& - 1
  80.     LOOP WHILE Segments& > 0 AND Y& < ymax - rand&&(100, 200)
  81.  
  82. SUB DrawLine (x1%, y1%, x2%, y2%, cc&&)
  83.     IF x1% < 0 THEN
  84.         IF x2% < 0 THEN EXIT SUB
  85.         x1% = 0
  86.     ELSEIF x1% >= xmax THEN
  87.         IF x2% >= xmax THEN EXIT SUB
  88.         x1% = xmax - 1
  89.     END IF
  90.     IF y1% < 0 THEN
  91.         IF y2% < 0 THEN EXIT SUB
  92.         y1% = 0
  93.     ELSEIF y1% >= ymax THEN
  94.         IF y2% >= ymax THEN EXIT SUB
  95.         y1% = ymax - 1
  96.     END IF
  97.  
  98.     IF x2% < 0 THEN
  99.         x2% = 0
  100.     ELSEIF x2% >= xmax THEN
  101.         x2% = xmax - 1
  102.     END IF
  103.     IF y2% < 0 THEN
  104.         y2% = 0
  105.     ELSEIF y2% >= ymax THEN
  106.         y2% = ymax - 1
  107.     END IF
  108.     LINE (x1%, y1%)-(x2%, y2%), cc&&
  109.  
  110. SUB drawLandscape
  111.     'the sky
  112.     FOR i = 0 TO ymax
  113.         midInk 0, 0, 0, 128, 128, 128, i / ymax
  114.         LINE (0, i)-(xmax, i)
  115.     NEXT
  116.     'the land
  117.     startH = ymax - 200
  118.     rr = 70: gg = 70: bb = 90
  119.     FOR mountain = 1 TO 6
  120.         Xright = 0
  121.         y = startH
  122.         WHILE Xright < xmax
  123.             ' upDown = local up / down over range, change along Y
  124.             ' range = how far up / down, along X
  125.             upDown = (RND * .8 - .35) * (mountain * .5)
  126.             range = Xright + rand&&(15, 25) * 2.5 / mountain
  127.             lastx = Xright - 1
  128.             FOR X = Xright TO range
  129.                 y = y + upDown
  130.                 COLOR _RGB32(rr, gg, bb)
  131.                 LINE (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  132.                 lastx = X
  133.             NEXT
  134.             Xright = range
  135.         WEND
  136.         rr = rand&&(rr - 15, rr): gg = rand&&(gg - 15, gg): bb = rand&&(bb - 25, bb)
  137.         IF rr < 0 THEN rr = 0
  138.         IF gg < 0 THEN gg = 0
  139.         IF bb < 0 THEN bb = 0
  140.         startH = startH + rand&&(5, 20)
  141.     NEXT
  142.  
  143. SUB midInk (r1, g1, b1, r2, g2, b2, fr)
  144.     COLOR _RGB32(r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr)
  145.  
  146. FUNCTION rand&& (lo&&, hi&&)
  147.     rand&& = INT(RND * (hi&& - lo&& + 1)) + lo&&
  148.  
  149.  

BTW, Steve was in on this too!
« Last Edit: September 09, 2018, 12:43:53 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boid Watching No 2.
« Reply #12 on: September 09, 2018, 12:52:02 am »
And here is a pretty one from Ashish a sample from this
Quote
'p5js.bas by Fellippe & Ashish
'Open source - based on p5.js (https://p5js.org/)
'Last update 5/26/2017

Blue Mountains.PNG
* Blue Mountains.PNG (Filesize: 47.33 KB, Dimensions: 837x614, Views: 317)