Author Topic: Fireflies  (Read 7085 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Fireflies
« Reply #15 on: September 02, 2019, 01:10:14 pm »
Hey Steve,

Nice speed! where are the halo's? Can memory do alpha?


LOL B+, I had a feeling you would say that. Going wayyyy back to the 80's, arrays haven't really been my friend lol. But I am learning. Thanks for telling me, I'll look into it.

Yeah, I know the feeling, I confess I am a little stuck when it comes to Steve's memory and 3D with GL.

Practice on something simple, you have already worked that you are familiar. This is ideal time for me and memory, thanks Steve!
« Last Edit: September 02, 2019, 01:17:52 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Fireflies
« Reply #16 on: September 02, 2019, 02:43:27 pm »
LOL SMcNeill, it looks like you combined my math with B+'s code to make the trails and mountains. Not sure though. If both of you don't care, I'll put your 2 names on the code with mine and put it on my website. But I do need to practice the code as well to learn more. But thank you!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Fireflies
« Reply #17 on: September 02, 2019, 02:52:02 pm »
I love it when everybody's name gets to go on the code! :D

Actually one of us should put the halos back up and STxAxTIC  gave me an idea to try, so if you don't mind, I am not done yet. :D

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Fireflies
« Reply #18 on: September 02, 2019, 02:57:46 pm »
LOL OK :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Fireflies
« Reply #19 on: September 02, 2019, 03:05:45 pm »
Oh just a very simple little change in Steve's post, change Glow near the top, CONST
CONST glow = &H1FFFFFFF, ...

Now the flies are angelic! ;-))

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Fireflies
« Reply #20 on: September 02, 2019, 04:00:20 pm »
And here is STxAxTIC idea to simplify code for much more elegant solution, it worked very well! thank you very much!

Code: QB64: [Select]
  1. OPTION _EXPLICIT ' B+ 2019-09-02 with STxAxTIC idea for simplification
  2. 'Thanks to Ken for inspiring mod fun!
  3. 'Thanks to Bplus on the QB64.org forum for the trail code.
  4. 'Made on Aug. 30, 2019 by Ken G. mod by B+
  5. '2019-09-01 mod of Fireflies #2 taking fly paths from Bugs on fire and adding Frames array
  6. ' for layering partially faded screens to get trails effect WITH a background display!
  7. ' 2 experiments have failed to produce desired trails do to my erroneous way of thinking.
  8. ' Time to pull out the heavy guns, cds Tools, and test an array like string of x, y locations.
  9. ' This might be a little complicated! We will be fading out old locations with transparencies
  10. ' rather than drawing over and over again with smoke layers.
  11. ' 2019-09-02 #4 mod Fireflies #3 with STxAxTIC idea dump the cds Tools!
  12. ' since flies are on a rail, you can backtrack locations from last angle used!
  13. ' No need to save the locations in an array! Much more elegant.
  14.  
  15. '        GLOBALS
  16. CONST nFlies = 25, xmax = 800, ymax = 600, cx = 400, cy = 300
  17.  
  18. TYPE flyType
  19.     a AS SINGLE
  20.     rr AS SINGLE 'random coeff = radius of flight path
  21.     m AS SINGLE
  22.     n AS SINGLE
  23.     r AS SINGLE
  24.     red AS INTEGER
  25.     green AS INTEGER
  26.     blue AS INTEGER
  27.  
  28. '     LOCALS for main code which is all this is!
  29. DIM i AS INTEGER, j AS INTEGER, a, bg&, x, y, ma
  30.  
  31. _TITLE "Fireflies #4 that glow, trails and background"
  32. SCREEN _NEWIMAGE(800, 600, 32)
  33. _SCREENMOVE 300, 60
  34.  
  35. 'prepare background image
  36. bg& = _NEWIMAGE(xmax, ymax, 32)
  37. drawLandscape
  38. _PUTIMAGE , 0, bg&
  39. 'setup trans
  40. DIM tr(0 TO 49) AS INTEGER
  41. FOR i = 0 TO 49
  42.     IF i <> 49 THEN tr(i) = INT(i / 3) + 1 ELSE tr(i) = 255
  43. 'setup flies
  44. DIM SHARED f(1 TO nFlies) AS flyType
  45. FOR i = 1 TO nFlies 'bug maker
  46.     f(i).r = RND * 3 + 1 '         radius
  47.     f(i).rr = RND * 200 + 250 '    radius of orbit
  48.     f(i).m = RND * 25 '            orbit cooff
  49.     f(i).n = RND * 25 '            orbit coeff 2
  50.     f(i).red = RND * 190 + 60 '    need to separartye color for alpha changes
  51.     f(i).green = RND * 190 + 60
  52.     f(i).blue = RND * 190 + 60
  53.     f(i).a = RND * _PI(2) '        angle in orbit that tracks location of x, y
  54.  
  55.     _PUTIMAGE , bg&, 0 'cls last screen shot
  56.     FOR i = 1 TO nFlies 'move bug
  57.         'mod a to radius of flight path  so they move approximately same rate
  58.         ma = .15 / f(i).rr
  59.         f(i).a = f(i).a + ma 'update f(i).a
  60.         'starting from f(i).a draw next 50 flies in this orbit with increasing opacity
  61.         FOR j = 0 TO 49 'calc new location and draw
  62.             a = f(i).a + j * ma
  63.             x = cx + f(i).rr * 1.5 * (COS(f(i).n * a) / 2 + SIN(f(i).m * a) / 3)
  64.             y = cy + f(i).rr * 1.25 * (SIN(f(i).n * a) / 2 + COS(f(i).m * a) / 3)
  65.             fcirc x, y, f(i).r + 8, _RGBA32(255, 255, 255, .15 * tr(j))
  66.             fcirc x, y, f(i).r, _RGBA32(f(i).red, f(i).green, f(i).blue, tr(j))
  67.         NEXT
  68.     NEXT
  69.     IF INKEY$ = CHR$(27) THEN END
  70.     _DISPLAY
  71.     _LIMIT 200
  72.  
  73. 'from Steve Gold standard
  74. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  75.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  76.     DIM X AS INTEGER, Y AS INTEGER
  77.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  78.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  79.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  80.     WHILE X > Y
  81.         RadiusError = RadiusError + Y * 2 + 1
  82.         IF RadiusError >= 0 THEN
  83.             IF X <> Y + 1 THEN
  84.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  85.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  86.             END IF
  87.             X = X - 1
  88.             RadiusError = RadiusError - X * 2
  89.         END IF
  90.         Y = Y + 1
  91.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  92.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  93.     WEND
  94.  
  95. SUB drawLandscape
  96.     'needs midInk, irnd
  97.  
  98.     DIM i AS INTEGER, startH AS SINGLE, rr AS INTEGER, gg AS INTEGER, bb AS INTEGER
  99.     DIM mountain AS INTEGER, Xright AS SINGLE, y AS SINGLE, upDown AS SINGLE, range AS SINGLE
  100.     DIM lastx AS SINGLE, X AS INTEGER
  101.     'the sky
  102.     FOR i = 0 TO ymax
  103.         midInk 0, 0, 48, 28, 0, 88, i / ymax
  104.         LINE (0, i)-(xmax, i)
  105.     NEXT
  106.     'the land
  107.     startH = ymax - 400
  108.     rr = 40: gg = 50: bb = 60
  109.     FOR mountain = 1 TO 6
  110.         Xright = 0
  111.         y = startH
  112.         WHILE Xright < xmax
  113.             ' upDown = local up / down over range, change along Y
  114.             ' range = how far up / down, along X
  115.             upDown = (RND * .8 - .35) * (mountain * .5)
  116.             range = Xright + irnd%(15, 25) * 2.5 / mountain
  117.             lastx = Xright - 1
  118.             FOR X = Xright TO range
  119.                 y = y + upDown
  120.                 COLOR _RGB(rr, gg, bb)
  121.                 LINE (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  122.                 lastx = X
  123.             NEXT
  124.             Xright = range
  125.         WEND
  126.         rr = irnd%(rr - 15, rr): gg = irnd%(gg - 15, gg): bb = irnd%(bb - 25, bb)
  127.         IF rr < 0 THEN rr = 0
  128.         IF gg < 0 THEN gg = 0
  129.         IF bb < 0 THEN bb = 0
  130.         startH = startH + irnd%(5, 20)
  131.     NEXT
  132.  
  133. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  134.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  135.  
  136. FUNCTION irnd% (n1, n2) 'return an integer between 2 numbers
  137.     DIM l%, h%
  138.     IF n1 > n2 THEN l% = n2: h% = n1 ELSE l% = n1: h% = n2
  139.     irnd% = INT(RND * (h% - l% + 1)) + l%
  140.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Fireflies
« Reply #21 on: September 02, 2019, 05:44:46 pm »
Fireflies last code of Bplus under guide of SxTAxTIxC

 
firesfly.png
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Fireflies
« Reply #22 on: September 02, 2019, 06:23:48 pm »
Amazing stuff.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Fireflies
« Reply #23 on: September 02, 2019, 07:00:19 pm »
Very nicely done! Two things I noticed... 1. No more alignments. I have the eye strain to prove it... lol and 2. Looks like Perlin noise landscapes... Cool...

Oh. If you can only code in a rolled up newspaper, you can probably make a game out of this... or maybe not... lol
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Fireflies
« Reply #24 on: September 03, 2019, 06:42:05 pm »
Super Nintendo had a tiny game built-in to it's Mario Paint cartridge where you swat flies with a fly swatter. lol