Author Topic: Happy New Year  (Read 2850 times)

0 Members and 1 Guest are viewing this topic.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Happy New Year
« on: January 01, 2022, 02:54:08 pm »
Looking forward to getting this damn virus behind us. It did hit our home ending a lot of beautiful meals and a hook ups with some very funny relatives. But on the positive side ( if that word still carries a happy meaning) my Christmas turned into an adult Halloween. Tons  of chocolates, tarts and treats you couldn't stop eating. At the moment I'm trying to write some code while consuming a coffee with chocolates filled with brandy. I suspect its' the chocolates that have inspired me to pass along this season greeting. I'm very thankful for all the help this community has provided to me. Going for a couple more chocolates, they could actually be a cure for the virus.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Happy New Year
« Reply #1 on: January 01, 2022, 06:35:52 pm »
Code: QB64: [Select]
  1. _Title "Happy Trails 2022" 'from Happy Trails 2018
  2. ' 2017-12-29 another redesign of fireworks
  3. ' 2017-12-28 redesign fireworks
  4. ' now with lake refelction 2017-12-27 forget the bouncing sparks
  5. ' combine Welcome Plasma Font with landscape
  6. '_title "Fireworks 3 translation to QB64 2017-12-26 bplus"
  7. 'fireworks 3.bas SmallBASIC 0.12.2 [B+=MGA] 2015-05-09
  8. 'fireworks 2.bas 2016-05-05 now with Gravity, Newtonian bounce, smoke debris
  9. 'fireworks 3.bas try with map variables make bursts around a central point
  10.  
  11.  
  12. Const xmax = 1200
  13. Const ymax = 720
  14. Const waterline = 600 ' 600 = ratio 5 to 1 sky to water
  15. '                       raise and lower waterline as desired  highest about 400?
  16. Const lTail = 15
  17. Const bluey = 5 * 256 ^ 2 + 256 * 5 + 5
  18. Const debrisMax = 28000
  19.  
  20. Screen _NewImage(xmax, ymax, 32)
  21. _ScreenMove 120, 20
  22.  
  23. Type fireWorkType
  24.     x As Integer
  25.     y As Integer
  26.     seed As Integer
  27.     age As Integer
  28.     life As Integer
  29.  
  30.  
  31. Type debrisType
  32.     x As Single
  33.     y As Single
  34.     c As Long
  35.  
  36. Common Shared fw() As fireWorkType
  37. Common Shared debris() As debrisType
  38. Common Shared cN, pR!, pG!, pB!
  39.  
  40. Screen _NewImage(xmax, ymax, 32)
  41.  
  42. 'prepare message font
  43. mess$ = " Happy New Year 2022"
  44. Print mess$
  45. w = 8 * Len(mess$): h = 16
  46. Dim p(w, h)
  47. black&& = Point(0, 10)
  48. For y = 0 To h
  49.     For x = 0 To w
  50.         If Point(x, y) <> black&& Then
  51.             p(x, y) = 1
  52.         End If
  53.     Next
  54. xo = 0: yo = 15: m = 7.2
  55. resetPlasma
  56.  
  57. 'prepare landscape
  58. land& = _NewImage(xmax, ymax, 32)
  59. _Dest land&
  60. drawLandscape
  61.  
  62. 'prepare fire works
  63. nFW = 3
  64. Dim fw(1 To 10) As fireWorkType
  65. For i = 1 To nFW
  66.     initFireWork (i)
  67.  
  68. ''debris feild
  69. 'DIM debris(debrisMax) AS debrisType
  70.  
  71. 'OK start the show
  72.     'cls screen with land image
  73.     _PutImage , land&, 0
  74.  
  75.     'draw fireworks
  76.     For f = 1 To nFW
  77.         If fw(f).age <= fw(f).life Then drawfw (f) Else initFireWork f
  78.     Next
  79.  
  80.     ''debris
  81.     'FOR i = 0 TO debrisStack
  82.     '    PSET (debris(i).x, debris(i).y), debris(i).c
  83.     '    debris(i).x = debris(i).x + RND * 3 - 1.5
  84.     '    debris(i).y = debris(i).y + RND * 3.5 - 1.5
  85.     '    IF debris(i).x < 0 OR debris(i).y < 0 OR debris(i).x > xmax OR debris(i).y > waterline + RND * 20 THEN NewDebris (i)
  86.     'NEXT
  87.  
  88.     'text message in plasma
  89.     For y = 0 To h - 1
  90.         For x = 0 To w - 1
  91.             If p(x, y) Then
  92.                 changePlasma
  93.             Else
  94.                 Color 0
  95.             End If
  96.             Line (xo + x * m, yo + y * m)-(xo + x * m + m, yo + y * m + m), , BF
  97.         Next
  98.     Next
  99.     lc = lc + 1
  100.     If lc Mod 200 = 0 Then resetPlasma
  101.  
  102.     'reflect sky
  103.     skyWaterRatio = waterline / (ymax - waterline) - .05
  104.     For y = waterline To ymax
  105.         For x = 0 To xmax
  106.             c&& = Point(x, waterline - ((y - waterline - 1) * skyWaterRatio) + Rnd * 5)
  107.             PSet (x, y + 1), c&& + bluey
  108.         Next
  109.     Next
  110.  
  111.     _Display
  112.     _Limit 200 'no limit needed on my system!
  113.  
  114.     ''accumulate debris
  115.     'IF lc MOD 2000 THEN
  116.     '    IF debrisStack < debrisMax THEN
  117.     '        FOR i = 1 TO 2
  118.     '            NewDebris i + debrisStack
  119.     '        NEXT
  120.     '        debrisStack = debrisStack + 2
  121.     '    END IF
  122.     'END IF
  123.  
  124. 'SUB NewDebris (i)
  125. '    debris(i).x = RND * xmax
  126. '    debris(i).y = RND * ymax
  127. '    c = RND * 155
  128. '    debris(i).c = _RGB32(c, c, c)
  129. 'END SUB
  130.  
  131. Sub changePlasma ()
  132.     cN = cN + .01
  133.     Color _RGB(127 + 127 * Sin(pR! * .3 * cN), 127 + 127 * Sin(pG! * .3 * cN), 127 + 127 * Sin(pB! * .3 * cN))
  134.  
  135. Sub resetPlasma ()
  136.     pR! = Rnd ^ 2: pG! = Rnd ^ 2: pB! = Rnd ^ 2
  137.  
  138. Sub drawLandscape
  139.     'the sky
  140.     For i = 0 To ymax
  141.         midInk 0, 0, 0, 78, 28, 68, i / ymax
  142.         Line (0, i)-(xmax, i)
  143.     Next
  144.     'the land
  145.     startH = waterline - 80
  146.     rr = 10: gg = 20: bb = 15
  147.     For mountain = 1 To 6
  148.         Xright = 0
  149.         y = startH
  150.         While Xright < xmax
  151.             ' upDown = local up / down over range, change along Y
  152.             ' range = how far up / down, along X
  153.             upDown = (Rnd * .8 - .35) * (1 / (1 * mountain))
  154.             range = Xright + rand&&(5, 35) * 2.5 / mountain
  155.             lastx = Xright - 1
  156.             For X = Xright To range
  157.                 y = y + upDown
  158.                 Color _RGB32(rr, gg, bb)
  159.                 Line (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  160.                 lastx = X
  161.             Next
  162.             Xright = range
  163.         Wend
  164.         rr = rand&&(rr + 5, rr): gg = rand&&(gg + 5, gg): bb = rand&&(bb + 4, bb)
  165.         If rr < 0 Then rr = 0
  166.         If gg < 0 Then gg = 0
  167.         If bb < 0 Then bb = 0
  168.         startH = startH + rand&&(1, 10)
  169.     Next
  170.     'LINE (0, waterline)-(xmax, ymax), _RGB32(0, 0, 0), BF
  171.  
  172. Sub midInk (r1, g1, b1, r2, g2, b2, fr)
  173.     Color _RGB(r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr)
  174.  
  175. Function rand&& (lo&&, hi&&)
  176.     rand&& = Int(Rnd * (hi&& - lo&& + 1)) + lo&&
  177.  
  178. Sub drawfw (i)
  179.     'here's how to "save" a bunch of random numbers without data and arrays but tons of redundant calculations
  180.     Randomize Using fw(i).seed 'this repeats all random numbers generated by seed in same sequence
  181.     'recreate our firework from scratch!
  182.     red = rand&&(200, 255)
  183.     green = rand&&(200, 255)
  184.     blue = rand&&(200, 255)
  185.     x = rand&&(1, 4)
  186.     If x = 1 Then
  187.         red = 0
  188.     ElseIf x = 2 Then
  189.         green = 0
  190.     ElseIf x = 3 Then
  191.         blue = 0
  192.     Else
  193.         x = rand&&(1, 4)
  194.         If x = 1 Then
  195.             red = 0: green = 0
  196.         ElseIf x = 2 Then
  197.             green = 0: blue = 0
  198.         ElseIf x = 3 Then
  199.             blue = 0: red = 0
  200.         End If
  201.     End If
  202.     ne = rand&&(80, 300)
  203.     Dim embers(ne, 1)
  204.     For e = 0 To ne
  205.         r = Rnd * 3
  206.         embers(e, 0) = r * Cos(e * _Pi(2) / 101)
  207.         embers(e, 1) = r * Sin(e * _Pi(2) / 101)
  208.     Next
  209.     start = fw(i).age - lTail ' don't let tails get longer than lTail const
  210.     If start < 1 Then start = 1
  211.     For e = 0 To ne
  212.         cx = fw(i).x: cy = fw(i).y: dx = embers(e, 0): dy = embers(e, 1)
  213.         For t = 1 To fw(i).age
  214.             cx = cx + dx
  215.             cy = cy + dy
  216.             If t >= start Then
  217.                 'too much like a flower?
  218.                 midInk 60, 60, 60, red, green, blue, (t - start) / lTail
  219.                 'midInk 60, 60, 60, 128, 160, 150, (t - start) / lTail
  220.                 fcirc cx, cy, (t - start) / lTail
  221.             End If
  222.  
  223.             dx = dx * .99 'air resitance
  224.             dy = dy + .01 'gravity
  225.         Next
  226.         Color _RGB32(255, 255, 255)
  227.         'COLOR _RGB32(red, green, blue)
  228.         cx = cx + dx: cy = cy + dy
  229.         fcirc cx, cy, (t - start) / lTail
  230.     Next
  231.     fw(i).age = fw(i).age + 1
  232.  
  233. Sub initFireWork (i)
  234.     fw(i).x = rand&&(.1 * xmax, .9 * xmax)
  235.     fw(i).y = rand&&(.1 * ymax, .5 * ymax)
  236.     fw(i).seed = rand&&(0, 32000)
  237.     fw(i).age = 0
  238.     fw(i).life = rand&&(20, 120)
  239.  
  240. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  241. Sub fcirc (CX As Long, CY As Long, R As Long)
  242.     Dim subRadius As Long, RadiusError As Long
  243.     Dim X As Long, Y As Long
  244.  
  245.     subRadius = Abs(R)
  246.     RadiusError = -subRadius
  247.     X = subRadius
  248.     Y = 0
  249.  
  250.     If subRadius = 0 Then PSet (CX, CY): Exit Sub
  251.  
  252.     ' Draw the middle span here so we don't draw it twice in the main loop,
  253.     ' which would be a problem with blending turned on.
  254.     Line (CX - X, CY)-(CX + X, CY), , BF
  255.  
  256.     While X > Y
  257.         RadiusError = RadiusError + Y * 2 + 1
  258.         If RadiusError >= 0 Then
  259.             If X <> Y + 1 Then
  260.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  261.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  262.             End If
  263.             X = X - 1
  264.             RadiusError = RadiusError - X * 2
  265.         End If
  266.         Y = Y + 1
  267.         Line (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  268.         Line (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  269.     Wend
  270.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Happy New Year
« Reply #2 on: January 01, 2022, 06:46:51 pm »
Gotta love those particle demos!!

Have a great new year, guys!!
Logic is the beginning of wisdom.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Happy New Year
« Reply #3 on: January 02, 2022, 10:25:02 am »
Beautiful bplus...the reflection must have taken a lot of thought.

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Happy New Year
« Reply #4 on: January 02, 2022, 01:07:10 pm »
Code: QB64: [Select]
  1. _Title "Happy Trails 2022" 'from Happy Trails 2018
  2.  

i'm amazed how little code you guys need to get so much done.
my programs are always huge!
anyway this is very nice. happy new year!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Happy New Year
« Reply #5 on: January 02, 2022, 02:02:49 pm »
Hi @madscijr

I will give one tip that saved allot of saving of points for Fireworks:
I saved seed to randomly draw one firework. From that seed I reset Randomize and always got the exact same set of "randomly" chosen points, colors, dx, dy... the whole works are determined from one seed. That way I didn't have to track where each trail of flames goes for each frame the fireworks is "alive".

I too have always admired how some function can be done with as few lines as possible, perhaps with practice and a few years it becomes a skill. :) SMcNeill is a master of it IMHO :) others too of course, he had to learn from others as well!