Author Topic: 🎄🎁✨ Holiday Season Code Sampler 2021  (Read 15688 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

FellippeHeitor

  • Guest
🎄🎁✨ Holiday Season Code Sampler 2021
« on: December 02, 2021, 02:25:46 pm »
🎄☃️🔔

Lights and jingly bells are already all around.

If you're already feeling inspired by @SMcNeill's season project, get it going so you can also be featured in this year's traditional sampler.

Let's group entries under this thread. Rules are the same as last year's: Make it beautiful, preferably with no extra files.

Who'll start?
✨🎁
« Last Edit: December 02, 2021, 02:37:30 pm by FellippeHeitor »

FellippeHeitor

  • Guest
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #1 on: December 02, 2021, 02:26:31 pm »
It's also time to remember last year's samples, which can be viewed in the video below, with the delightful soundtrack provided by our very own @Dav:


FellippeHeitor

  • Guest
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #2 on: December 02, 2021, 02:46:01 pm »
Also notice that by sharing your works of art in this thread, you hereby grant me the right to include your entry in the video we'll feature in our YouTube channel.

🤩

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #3 on: December 02, 2021, 02:59:54 pm »
Lol, had I’d known it was going to be a soundtrack I’d had prepared something better than that,  it it was fun last year participating with everyone though. 

- Dav

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #4 on: December 02, 2021, 04:02:13 pm »
It's also time to remember last year's samples, which can be viewed in the video below, with the delightful soundtrack provided by our very own @Dav:

This is great!
I'm so glad to have found QB64 and the wonderful community around it...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #5 on: December 02, 2021, 04:23:12 pm »
More Lights:
Code: QB64: [Select]
  1. _Title "More Lights" 'b+ 2021-11-28
  2. ' ref:   https://justbasiccom.proboards.com/thread/759/polinom-interpolation-3-points
  3. ' mod to xmax tree ?
  4. ' 2021-12-02 start More Lights mod
  5.  
  6.  
  7. Const sw = 600, sh = 700, cx = sw / 2, cy = sh / 2, treeAreaDvPI = 22707
  8. Screen _NewImage(sw, sh, 32)
  9. _ScreenMove 320, 40
  10. Dim As Integer topLight
  11. lastTopLight = 2
  12. topLight = 50
  13. Dim Shared pX(1 To 3), pY(1 To 3)
  14. ReDim lx(1 To topLight), ly(1 To topLight)
  15.  
  16. moreLights:
  17. 'tree
  18. stepper = .75 * sh / 12
  19. For y = .125 * sh To .875 * sh Step stepper
  20.     r = (y - .125 * sh) * Sin(_Pi(1 / 12))
  21.     pX(1) = cx - r: pX(2) = cx: pX(3) = cx + r
  22.     pY(1) = y: pY(2) = y - 1.5 * stepper: pY(3) = y
  23.     'Line (pX(1), pY(1))-(pX(3), pY(3)), &HFF00FF00
  24.     For x = pX(1) To pX(3)
  25.         If Rnd < .75 Then PSet (x, para(x)), &HFF005500
  26.     Next
  27.     pY(2) = y - .5 * stepper
  28.     For x = pX(1) To pX(3)
  29.         If Rnd < .15 Then PSet (x, para(x)), &HFF005500
  30.     Next
  31.  
  32. 'lights
  33.  
  34. lx(1) = cx: ly(1) = .125 * sh - .5 * stepper - 5
  35. Circle (lx(1), ly(1)), 4, &HFFFFFF88 ' topper
  36. Circle (lx(1), ly(1)), 6, &HFFFFFFFF
  37. For r = 3 To 30 Step 1
  38.     fcirc lx(1), ly(1), r, &H03FFFFFF
  39. dTopSq = Sqr(treeAreaDvPI / (topLight - .5 * topLight)) ' best spread of lights
  40. For i = lastTopLight To topLight ' save 1 for top of tree
  41.     If i Mod 100 = 0 Then 'light the whole area around the tree
  42.         If i > 1200 Then
  43.             For rr = 0 To sh Step 1
  44.                 fcirc cx, cy, rr, _RGB32(255, 255 - rr / 2, 200 - rr, 20)
  45.                 _Limit 250 + 2 * rr
  46.             Next
  47.             GoTo finished
  48.         Else
  49.             For rr = cy To 0 Step -20
  50.                 fcirc cx, cy, rr, _RGB32(255, 255, 255, 1)
  51.             Next
  52.         End If
  53.     End If
  54.  
  55.     again:
  56.     x = Rnd * sw + 1: y = Rnd * sh + 1
  57.     If y > .125 * sh And y <= .875 * sh Then
  58.         If x > cx - (y - .125 * sh) * Sin(_Pi(1 / 12)) And x < cx + (y - .125 * sh) * Sin(_Pi(1 / 12)) Then
  59.  
  60.             ' dang have to space them out better
  61.             If i > 2 Then
  62.                 ok = -1
  63.                 For j = 1 To i - 1
  64.                     d = ((lx(j) - x) ^ 2 + (ly(j) - y) ^ 2) ^ .5
  65.                     If d < dTopSq Then ok = 0: Exit For
  66.                 Next
  67.                 If ok Then
  68.                     rc~& = _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
  69.                     For r = 0 To 2 Step .5
  70.                         Circle (x, y), r, rc~&
  71.                     Next
  72.                     For r = 3 To 10 Step 1
  73.                         fcirc x, y, r, &H03FFFFFF
  74.                     Next
  75.  
  76.                     lx(i) = x: ly(i) = y ' save the place
  77.                 Else
  78.                     GoTo again
  79.                 End If
  80.             End If
  81.         Else
  82.             GoTo again
  83.         End If
  84.     Else
  85.         GoTo again
  86.     End If
  87. ' Beep ' make sure we finish in reasonable amount of time  ie balance number of lights to distance d
  88. startLights = Timer
  89. pause = pause + 2
  90. While Timer - startLights < (3 + pause) And _KeyDown(27) = 0
  91.     Locate 1, 1: Print topLight ', dTopSq
  92.     rl = Int(Rnd * (topLight - 1)) + 1
  93.     rc~& = _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
  94.     For r = 0 To 2 Step .5
  95.         If lx(rl) <> 0 And ly(rl) <> 0 Then Circle (lx(rl), ly(rl)), r, rc~&
  96.     Next
  97.     _Limit 15
  98. s$ = "More lights!"
  99. _PrintString ((_Width - Len(s$) * 8) / 2, _Height / 2 - 8), s$
  100. topLight = topLight + .5 * topLight
  101. ReDim lx(1 To topLight), ly(1 To topLight)
  102. GoTo moreLights
  103.  
  104. finished:
  105. s$ = "Oops,  ZZZ..."
  106. _PrintString ((_Width - Len(s$) * 8) / 2, _Height / 2 - 8), s$
  107. s$ = "Have a Merry (and safe) Christmas!"
  108. _PrintString ((_Width - Len(s$) * 8) / 2, _Height / 2 - 8), s$
  109.  
  110.  
  111.  
  112. Function para (x)
  113.     'uses shared arrays  pX(), pY()
  114.     y = 0
  115.     For i = 1 To 3
  116.         p = 1
  117.         For j = 1 To 3
  118.             If i <> j Then
  119.                 p = p * (x - pX(j)) / (pX(i) - pX(j))
  120.             End If
  121.         Next
  122.         y = y + pY(i) * p
  123.     Next
  124.     para = y
  125.  
  126. 'from Steve Gold standard
  127. Sub fcirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
  128.     Dim Radius As Long, RadiusError As Long
  129.     Dim X As Long, Y As Long
  130.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  131.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  132.     Line (CX - X, CY)-(CX + X, CY), C, BF
  133.     While X > Y
  134.         RadiusError = RadiusError + Y * 2 + 1
  135.         If RadiusError >= 0 Then
  136.             If X <> Y + 1 Then
  137.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  138.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  139.             End If
  140.             X = X - 1
  141.             RadiusError = RadiusError - X * 2
  142.         End If
  143.         Y = Y + 1
  144.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  145.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  146.     Wend
  147.  
  148.  

FellippeHeitor

  • Guest
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #6 on: December 02, 2021, 04:39:10 pm »
Thanks for getting it started, bplus! That was gorgeous (and fun)!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #7 on: December 02, 2021, 05:32:36 pm »
Beautiful tree & lights, @bplus! Nice subtle twinkles.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #8 on: December 02, 2021, 06:28:05 pm »
Thanks guys, the fun is why I am ruined for any other PL! ;-))

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #9 on: December 03, 2021, 08:48:05 pm »
Well, I want to contribute something at least this year, so here's a couple things I posted earlier this year combined to make a simple Christmas puzzle.  It's a a Picture un-scrambler with falling snowflakes effect and some background music.  BAS Code is too big to post, so it's attached.  It's big because it has encode files in the code.  It will create 3 files on first run in the current directory, xmasdav2021.jpg,  xmasdav2021.png,  xmasdav2021.ogg.

Merry Christmas!

- Dav

  [ You are not allowed to view this attachment ]   (465k)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #10 on: December 03, 2021, 11:23:48 pm »
Nice one Dav!

I like the snow fall while doing the puzzle and the Christmas music is a nice break from regular car radio stuff repeated more than TV commercials.

FellippeHeitor

  • Guest
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #11 on: December 07, 2021, 09:06:14 pm »
Well, I want to contribute something at least this year, so here's a couple things I posted earlier this year combined to make a simple Christmas puzzle.  It's a a Picture un-scrambler with falling snowflakes effect and some background music.  BAS Code is too big to post, so it's attached.  It's big because it has encode files in the code.  It will create 3 files on first run in the current directory, xmasdav2021.jpg,  xmasdav2021.png,  xmasdav2021.ogg.

Merry Christmas!

- Dav

  [ You are not allowed to view this attachment ]   (465k)

So much fun, Dav!

Damn, you guys are already setting the bar pretty high this year! 🤩

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #12 on: December 08, 2021, 07:39:42 am »
Thanks, @bplus & @FellippeHeitor.  I should have thanked @SMcNeill in the code for his contribution to my snowflake code - he fixed it earlier this year to help it work fast enough to be used in this way. (Thanks, Steve!)

- Dav

FellippeHeitor

  • Guest
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #13 on: December 12, 2021, 10:56:47 am »
Here's my lazy first submission, the Lazy Laser Xmas Tree:

Code: QB64: [Select]
  1. Screen _NewImage(600, 600, 32)
  2.  
  3. Dim m$
  4. m$ = "*** Merry Christmas, QB64 Community! ***"
  5.  
  6. Type coord
  7.     As Integer x, y, size
  8.     As _Unsigned Long c
  9.     As Single inc, angle
  10. Dim As coord this, ornament(50), tree(1 To 3)
  11.  
  12. tree(1).x = _Width / 2
  13. tree(1).y = 30
  14. tree(2).x = 0
  15. tree(2).y = _Height - 10
  16. tree(3).x = _Width
  17. tree(3).y = _Height - 10
  18.  
  19. ornament(1).x = tree(1).x
  20. ornament(1).y = tree(1).y
  21. ornament(1).size = 30
  22. ornament(1).c = _RGB32(211, 183, 22)
  23. ornament(1).inc = .5
  24.     'fade to black cls
  25.     Line (0, 0)-(_Width - 1, _Height - 1), _RGB32(0, 15), BF
  26.  
  27.     'tree
  28.     Line (tree(1).x, tree(1).y)-(Rnd * _Width, _Height - 10), _RGB32(0, 255, 0, 100)
  29.  
  30.     'ornaments
  31.     For i = 1 To UBound(ornament)
  32.         'initialize as needed
  33.         If ornament(i).c = 0 Then
  34.             Do
  35.                 ornament(i).y = tree(1).y + (_Height - (10 + tree(1).y)) * Rnd
  36.                 ornament(i).x = _Width * Rnd
  37.             Loop Until isInside(tree(1), tree(2), tree(3), ornament(i))
  38.             ornament(i).size = 10 * Rnd
  39.             ornament(i).c = _RGB32(255 * Rnd, 255 * Rnd, 255 * Rnd)
  40.             ornament(i).inc = _Pi(.3)
  41.             ornament(i).angle = _Pi(Rnd)
  42.         End If
  43.  
  44.         ornament(i).angle = ornament(i).angle + ornament(i).inc
  45.         If ornament(i).angle > _Pi(2) Then ornament(i).angle = ornament(i).angle - (_Pi(2))
  46.  
  47.         this = ornament(i)
  48.         Line (this.x, this.y)-Step(Cos(this.angle) * this.size, Sin(this.angle) * this.size), this.c
  49.     Next
  50.  
  51.     printMessage m$
  52.  
  53.     _Limit 15
  54.  
  55. Sub printMessage (text$)
  56.     Static x As Integer, setup As _Byte
  57.     Dim As Integer y, i, tempX
  58.     If setup = 0 Then x = _Width - _FontWidth: setup = -1
  59.     tempX = x
  60.     For i = 1 To Len(text$)
  61.         If tempX < 0 Then tempX = tempX + _FontWidth: _Continue
  62.         y = _Height / 2 + Sin(tempX)
  63.         Color _RGB32(255), _RGB32(0, 100)
  64.         _PrintString (tempX, y), Mid$(text$, i, 1)
  65.         tempX = tempX + _FontWidth
  66.     Next
  67.     x = x - 1
  68.     If x < -(_PrintWidth(text$)) Then x = _Width - _FontWidth
  69.  
  70. Function area! (t1 As coord, t2 As coord, t3 As coord)
  71.     'from https://www.geeksforgeeks.org/check-whether-a-given-point-lies-inside-a-triangle-or-not/
  72.     '/* A utility function to calculate area of triangle formed by (x1, y1),
  73.     '   (x2, y2) and (x3, y3) */
  74.     area! = Abs((t1.x * (t2.y - t3.y) + t2.x * (t3.y - t1.y) + t3.x * (t1.y - t2.y)) / 2.0)
  75.  
  76. Function isInside%% (t1 As coord, t2 As coord, t3 As coord, p As coord)
  77.     'from https://www.geeksforgeeks.org/check-whether-a-given-point-lies-inside-a-triangle-or-not/
  78.     '/* A function to check whether point P(x, y) lies inside the triangle formed
  79.     '   by A(x1, y1), B(x2, y2) and C(x3, y3) */
  80.     Dim As Single A, A1, A2, A3 'area of triangles ABC, PBC, PAC, PAB
  81.  
  82.     A = area!(t1, t2, t3)
  83.     A1 = area!(p, t2, t3)
  84.     A2 = area!(t1, p, t3)
  85.     A3 = area!(t1, t2, p)
  86.  
  87.     isInside%% = (A = A1 + A2 + A3)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 🎄🎁✨ Holiday Season Code Sampler 2021
« Reply #14 on: December 12, 2021, 12:53:41 pm »
@FellippeHeitor That's pretty neat how you determine if a point is inside a triangle.

More ornaments! ;-))