Author Topic: 🎄🎁✨ Holiday Season - are you ready to code?  (Read 18442 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #60 on: December 14, 2020, 05:47:10 pm »
@Petr that was completely amazing! Well done.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #61 on: December 14, 2020, 05:51:40 pm »
Thanks guys. Awesome ornaments Dav!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #62 on: December 14, 2020, 07:31:03 pm »
Anyone made Rudolf or Olive, yet?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #63 on: December 15, 2020, 04:54:34 am »
You finish off the bauble with a rectangle of the same rgb colour. I was thinking... stop laughing... What if the rectangles were 'center-gradient-based". The left-hand side of the rectangle starts off as pale grey; blends to a darker grey in the center; blends to a lighter grey towards the right-hand side. To give the "top" the illusion of being cylindrical... I don't know the correct way to explain it. I hope I am making sense? Just a thought...
Logic is the beginning of wisdom.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #64 on: December 15, 2020, 07:25:21 am »
Why invent something new when I can release a greatest hits album?

My (first?) holiday contribution comes as a FluidCraft level. Compile the code below to an EXE, and then drag+drop the attached file.

Code: QB64: [Select]
  1. ' Version 2020-12-15
  2.  
  3.  
  4. _TITLE "FluidCraft"
  5.  
  6. SCREEN _NEWIMAGE(1024, 768, 32)
  7. '_FULLSCREEN , _SMOOTH
  8.  
  9.  
  10. TYPE Vector
  11.     x AS DOUBLE
  12.     y AS DOUBLE
  13.  
  14. TYPE ShadeVector
  15.     shadered AS DOUBLE
  16.     shadegreen AS DOUBLE
  17.     shadeblue AS DOUBLE
  18.     shadealpha AS DOUBLE
  19.  
  20. TYPE ShadeElement
  21.     TheName AS STRING
  22.     TheShade AS ShadeVector
  23.  
  24. TYPE Pixel
  25.     position AS Vector
  26.     velocity AS Vector
  27.     acceleration AS Vector
  28.     size AS DOUBLE
  29.     TheShade AS ShadeVector
  30.  
  31. DIM SHARED ShadeData(8) AS ShadeElement
  32. DIM SHARED ActiveShade AS ShadeVector
  33. DIM SHARED PixelCloud(3000) AS Pixel
  34. DIM SHARED ObjectSize AS DOUBLE
  35. DIM SHARED GridSize AS Vector
  36. ObjectSize = 6
  37. GridSize.x = 1 + INT(_WIDTH / ObjectSize)
  38. GridSize.y = 1 + INT(_HEIGHT / ObjectSize)
  39. DIM SHARED Level(GridSize.x, GridSize.y) AS ShadeVector
  40.  
  41. CALL InitializeAll
  42. CALL LoadFile
  43.     CALL UserInput
  44.     CLS
  45.     CALL DrawBorder
  46.     CALL DrawPixels
  47.     CALL DrawLevel
  48.     CALL Dynamics
  49.     CALL DrawOverlay
  50.     _DISPLAY
  51.     _LIMIT 30
  52.  
  53.  
  54. SUB DrawBorder
  55.     DIM k AS INTEGER
  56.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(255, 0, 255, 255), BF
  57.     FOR k = 6 TO _HEIGHT - 1 - 6
  58.         LINE (6, k)-(_WIDTH - 6, k), _RGB32(255 * k / _HEIGHT, 0, 255 * (1 - k / _HEIGHT), 255)
  59.     NEXT
  60.     LINE (12, 12)-(_WIDTH - 12, _HEIGHT - 12), _RGB32(0, 0, 0, 255), BF
  61.     LINE (12, 12)-(18 * (UBOUND(ShadeData) + 1) - 1 + 6 + 12, 38 + 12), _RGB32(0, 0, 255, 255), BF
  62.     LINE (12, 12)-(18 * (UBOUND(ShadeData) + 1) - 1 + 6 + 6, 38 + 6), _RGB32(255, 0, 255, 255), BF
  63.     LINE (12, 12)-(18 * (UBOUND(ShadeData) + 1) - 1 + 6, 38), _RGB32(0, 0, 0, 255), BF
  64.  
  65. SUB DrawPixels
  66.     DIM k AS INTEGER
  67.     DIM x AS DOUBLE
  68.     DIM y AS DOUBLE
  69.     DIM s AS DOUBLE
  70.     FOR k = 1 TO UBOUND(PixelCloud)
  71.         x = PixelCloud(k).position.x
  72.         y = PixelCloud(k).position.y
  73.         s = PixelCloud(k).size
  74.         CALL clinebf(x - s, y - s, x + s, y + s, _RGBA(PixelCloud(k).TheShade.shadered, PixelCloud(k).TheShade.shadegreen, PixelCloud(k).TheShade.shadeblue, PixelCloud(k).TheShade.shadealpha))
  75.     NEXT
  76.  
  77. SUB DrawLevel
  78.     DIM i AS INTEGER
  79.     DIM j AS INTEGER
  80.     DIM x AS DOUBLE
  81.     DIM y AS DOUBLE
  82.     DIM s AS DOUBLE
  83.     s = ObjectSize
  84.     FOR i = 1 TO GridSize.x
  85.         FOR j = 1 TO GridSize.y
  86.             x = (i - 1) * s
  87.             y = (j - 1) * s
  88.             IF (Level(i, j).shadered > 5) OR (Level(i, j).shadegreen > 5) OR (Level(i, j).shadeblue > 5) THEN
  89.                 CALL slinebf(x - s / 2, y - s / 2, x + s / 2 - 1, y + s / 2 - 1, _RGBA(Level(i, j).shadered, Level(i, j).shadegreen, Level(i, j).shadeblue, Level(i, j).shadealpha))
  90.             END IF
  91.         NEXT
  92.     NEXT
  93.  
  94. SUB DrawOverlay
  95.     DIM k AS INTEGER
  96.     IF ActiveShade.shadered < 5 AND ActiveShade.shadegreen < 5 AND ActiveShade.shadeblue < 5 THEN
  97.         LINE (ObjectSize * INT(_MOUSEX / ObjectSize) - ObjectSize / 2 - 1, ObjectSize * INT(_MOUSEY / ObjectSize) - ObjectSize / 2 - 1)-(ObjectSize * INT(_MOUSEX / ObjectSize) + ObjectSize / 2 - 1 + 1, ObjectSize * INT(_MOUSEY / ObjectSize) + ObjectSize / 2 - 1 + 1), _RGBA(255, 255, 255, 255), B
  98.     END IF
  99.     LINE (ObjectSize * INT(_MOUSEX / ObjectSize) - ObjectSize / 2, ObjectSize * INT(_MOUSEY / ObjectSize) - ObjectSize / 2)-(ObjectSize * INT(_MOUSEX / ObjectSize) + ObjectSize / 2 - 1, ObjectSize * INT(_MOUSEY / ObjectSize) + ObjectSize / 2 - 1), _RGBA(ActiveShade.shadered, ActiveShade.shadegreen, ActiveShade.shadeblue, ActiveShade.shadealpha), BF
  100.     FOR k = 1 TO UBOUND(ShadeData)
  101.         LINE (18 * k + 1, 18)-(18 * (k + 1) - 1, 32), _RGB32(ShadeData(k).TheShade.shadered, ShadeData(k).TheShade.shadegreen, ShadeData(k).TheShade.shadeblue, ShadeData(k).TheShade.shadealpha), BF
  102.         LINE (18 * k + 1, 18)-(18 * (k + 1) - 1, 32), _RGB32(255, 255, 255, 255), B
  103.     NEXT
  104.  
  105. SUB InitializeAll
  106.     DIM k AS INTEGER
  107.     ShadeData(1).TheName = "Red"
  108.     ShadeData(1).TheShade.shadered = 255
  109.     ShadeData(1).TheShade.shadegreen = 0
  110.     ShadeData(1).TheShade.shadeblue = 0
  111.     ShadeData(1).TheShade.shadealpha = 255
  112.     ShadeData(2).TheName = "Blue"
  113.     ShadeData(2).TheShade.shadered = 0
  114.     ShadeData(2).TheShade.shadegreen = 0
  115.     ShadeData(2).TheShade.shadeblue = 255
  116.     ShadeData(2).TheShade.shadealpha = 255
  117.     ShadeData(3).TheName = "Green"
  118.     ShadeData(3).TheShade.shadered = 0
  119.     ShadeData(3).TheShade.shadegreen = 255
  120.     ShadeData(3).TheShade.shadeblue = 0
  121.     ShadeData(3).TheShade.shadealpha = 255
  122.     ShadeData(4).TheName = "White"
  123.     ShadeData(4).TheShade.shadered = 255
  124.     ShadeData(4).TheShade.shadegreen = 255
  125.     ShadeData(4).TheShade.shadeblue = 255
  126.     ShadeData(4).TheShade.shadealpha = 255
  127.     ShadeData(5).TheName = "Yellow"
  128.     ShadeData(5).TheShade.shadered = 255
  129.     ShadeData(5).TheShade.shadegreen = 255
  130.     ShadeData(5).TheShade.shadeblue = 0
  131.     ShadeData(5).TheShade.shadealpha = 255
  132.     ShadeData(6).TheName = "Aqua"
  133.     ShadeData(6).TheShade.shadered = 0
  134.     ShadeData(6).TheShade.shadegreen = 255
  135.     ShadeData(6).TheShade.shadeblue = 255
  136.     ShadeData(6).TheShade.shadealpha = 255
  137.     ShadeData(7).TheName = "Violet"
  138.     ShadeData(7).TheShade.shadered = 255
  139.     ShadeData(7).TheShade.shadegreen = 0
  140.     ShadeData(7).TheShade.shadeblue = 255
  141.     ShadeData(7).TheShade.shadealpha = 255
  142.     ShadeData(8).TheName = "Black"
  143.     ShadeData(8).TheShade.shadered = 0
  144.     ShadeData(8).TheShade.shadegreen = 0
  145.     ShadeData(8).TheShade.shadeblue = 0
  146.     ShadeData(8).TheShade.shadealpha = 255
  147.  
  148.     FOR k = 1 TO UBOUND(PixelCloud)
  149.         PixelCloud(k).size = 3
  150.         PixelCloud(k).acceleration.x = 0
  151.         PixelCloud(k).acceleration.y = 0
  152.         PixelCloud(k).velocity.x = 0
  153.         PixelCloud(k).velocity.y = 0
  154.         PixelCloud(k).position.x = (RND - .5) * _WIDTH * .8
  155.         PixelCloud(k).position.y = (RND - .5) * _HEIGHT * .8
  156.         CALL SetPixelShade(k, 0, 0, 255, 150)
  157.     NEXT
  158.  
  159.     ActiveShade.shadered = 255
  160.     ActiveShade.shadegreen = 0
  161.     ActiveShade.shadeblue = 0
  162.     ActiveShade.shadealpha = 255
  163.  
  164.  
  165. SUB SetPixelShade (i AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER, a AS INTEGER)
  166.     PixelCloud(i).TheShade.shadered = r
  167.     PixelCloud(i).TheShade.shadegreen = g
  168.     PixelCloud(i).TheShade.shadeblue = b
  169.     PixelCloud(i).TheShade.shadealpha = a
  170.  
  171. SUB UserInput
  172.     DIM mb1 AS INTEGER
  173.     DIM mb2 AS INTEGER
  174.     DIM mb3 AS INTEGER
  175.     DIM i AS INTEGER
  176.     DIM j AS INTEGER
  177.     DIM k AS INTEGER
  178.     mb1 = 0
  179.     mb2 = 0
  180.     mb3 = 0
  181.         IF (_MOUSEBUTTON(1) = -1) AND (mb1 <> 1) THEN
  182.             mb1 = -1
  183.             i = 1 + INT(_MOUSEX / ObjectSize)
  184.             j = 1 + INT(_MOUSEY / ObjectSize)
  185.             Level(i, j).shadered = ActiveShade.shadered
  186.             Level(i, j).shadegreen = ActiveShade.shadegreen
  187.             Level(i, j).shadeblue = ActiveShade.shadeblue
  188.             Level(i, j).shadealpha = ActiveShade.shadealpha
  189.         END IF
  190.         IF ((_MOUSEBUTTON(2) = -1) AND (mb2 <> -1)) THEN
  191.             mb2 = -1
  192.             i = ObjectSize * INT(_MOUSEX / ObjectSize)
  193.             j = ObjectSize * INT(_MOUSEY / ObjectSize)
  194.             ActiveShade.shadered = _RED32(POINT(i, j))
  195.             ActiveShade.shadegreen = _GREEN32(POINT(i, j))
  196.             ActiveShade.shadeblue = _BLUE32(POINT(i, j))
  197.             ActiveShade.shadealpha = _ALPHA32(POINT(i, j))
  198.         END IF
  199.     LOOP
  200.         CASE ASC("e"), ASC("E")
  201.             CALL Export
  202.         CASE ASC("r"), ASC("R")
  203.             FOR k = 1 TO UBOUND(PixelCloud)
  204.                 PixelCloud(k).TheShade.shadered = 255
  205.                 PixelCloud(k).TheShade.shadegreen = 0
  206.                 PixelCloud(k).TheShade.shadeblue = 0
  207.             NEXT
  208.         CASE ASC("b"), ASC("B")
  209.             FOR k = 1 TO UBOUND(PixelCloud)
  210.                 PixelCloud(k).TheShade.shadered = 0
  211.                 PixelCloud(k).TheShade.shadegreen = 0
  212.                 PixelCloud(k).TheShade.shadeblue = 255
  213.             NEXT
  214.         CASE ASC("0")
  215.             FOR k = 1 TO UBOUND(PixelCloud)
  216.                 PixelCloud(k).position.x = (RND - .5) * _WIDTH * .8
  217.                 PixelCloud(k).position.y = (RND - .5) * _HEIGHT * .8
  218.             NEXT
  219.         CASE 27
  220.             FOR i = 1 TO GridSize.x
  221.                 FOR j = 1 TO GridSize.y
  222.                     Level(i, j).shadered = 0
  223.                     Level(i, j).shadegreen = 0
  224.                     Level(i, j).shadeblue = 0
  225.                     Level(i, j).shadealpha = 0
  226.                 NEXT
  227.             NEXT
  228.     END SELECT
  229.     'DO WHILE _MOUSEINPUT: LOOP
  230.  
  231. SUB Export
  232.     DIM i AS INTEGER
  233.     DIM j AS INTEGER
  234.     OPEN "FluidCraft" + LTRIM$(RTRIM$(STR$(INT(TIMER)))) + ".txt" FOR OUTPUT AS #1
  235.     FOR i = 1 TO UBOUND(Level, 1)
  236.         FOR j = 1 TO UBOUND(Level, 2)
  237.             PRINT #1, i, j, Level(i, j).shadered, Level(i, j).shadegreen, Level(i, j).shadeblue, Level(i, j).shadealpha
  238.         NEXT
  239.     NEXT
  240.     CLOSE #1
  241.  
  242. SUB Dynamics
  243.     DIM k AS INTEGER
  244.     FOR k = 1 TO UBOUND(PixelCloud)
  245.         CALL CalculateInfluence(k)
  246.         CALL UpdatePosition(k)
  247.     NEXT
  248.  
  249. SUB UpdatePosition (i AS INTEGER)
  250.     DIM dt AS DOUBLE
  251.     DIM damp AS DOUBLE
  252.     DIM brownian AS DOUBLE
  253.     dt = 1
  254.     damp = 0.8
  255.     brownian = .65
  256.     PixelCloud(i).velocity.x = damp * PixelCloud(i).velocity.x + dt * PixelCloud(i).acceleration.x
  257.     PixelCloud(i).velocity.y = damp * PixelCloud(i).velocity.y + dt * PixelCloud(i).acceleration.y
  258.     PixelCloud(i).position.x = PixelCloud(i).position.x + dt * PixelCloud(i).velocity.x + (RND - .5) * brownian
  259.     PixelCloud(i).position.y = PixelCloud(i).position.y + dt * PixelCloud(i).velocity.y + (RND - .5) * brownian
  260.     IF (PixelCloud(i).position.y <= -_HEIGHT / 2 + 2 * PixelCloud(i).size + 1) THEN
  261.         PixelCloud(i).position.y = _HEIGHT / 2 - 2 * PixelCloud(i).size
  262.     END IF
  263.  
  264. SUB CalculateInfluence (i AS INTEGER)
  265.     DIM x AS DOUBLE
  266.     DIM y AS DOUBLE
  267.     DIM dx AS DOUBLE
  268.     DIM dy AS DOUBLE
  269.     DIM xr AS DOUBLE
  270.     DIM yr AS DOUBLE
  271.     DIM xg AS DOUBLE
  272.     DIM yg AS DOUBLE
  273.     DIM xb AS DOUBLE
  274.     DIM yb AS DOUBLE
  275.     DIM WPoint(9) AS _UNSIGNED LONG
  276.     x = PixelCloud(i).position.x
  277.     y = PixelCloud(i).position.y
  278.     dx = 2 * PixelCloud(i).size
  279.     dy = 2 * PixelCloud(i).size
  280.     WPoint(7) = cpoint(x - dx, y + dy)
  281.     WPoint(8) = cpoint(x, y + dy)
  282.     WPoint(9) = cpoint(x + dx, y + dy)
  283.     WPoint(4) = cpoint(x - dx, y)
  284.     WPoint(6) = cpoint(x + dx, y)
  285.     WPoint(1) = cpoint(x - dx, y - dy)
  286.     WPoint(2) = cpoint(x, y - dy)
  287.     WPoint(3) = cpoint(x + dx, y - dy)
  288.  
  289.     DIM k AS INTEGER
  290.     DIM WShade(9) AS DOUBLE
  291.     DIM xc AS DOUBLE
  292.     DIM yc AS DOUBLE
  293.     DIM cs AS INTEGER
  294.     cs = 0
  295.     x = 0
  296.     y = 0
  297.  
  298.     ' red
  299.     FOR k = 1 TO 9
  300.         IF (k <> 5) THEN
  301.             IF ((_RED32(WPoint(k)) > 25) AND (_GREEN32(WPoint(k)) < 5) AND (_BLUE32(WPoint(k)) < 25)) THEN
  302.                 WShade(k) = _RED32(WPoint(k)) + _GREEN32(WPoint(k)) + _BLUE32(WPoint(k))
  303.             ELSE
  304.                 WShade(k) = 0
  305.             END IF
  306.         END IF
  307.     NEXT
  308.     xr = (WShade(6) - WShade(4) + (WShade(9) + WShade(3)) / SQR(2) - (WShade(7) + WShade(1)) / SQR(2))
  309.     yr = (WShade(8) - WShade(2) + (WShade(7) + WShade(9)) / SQR(2) - (WShade(1) + WShade(3)) / SQR(2))
  310.     x = x + xr
  311.     y = y + yr
  312.  
  313.     ' blue
  314.     FOR k = 1 TO 9
  315.         IF (k <> 5) THEN
  316.             IF ((_RED32(WPoint(k)) < 25) AND (_GREEN32(WPoint(k)) < 5) AND (_BLUE32(WPoint(k)) > 25)) THEN
  317.                 WShade(k) = _RED32(WPoint(k)) + _GREEN32(WPoint(k)) + _BLUE32(WPoint(k))
  318.             ELSE
  319.                 WShade(k) = 0
  320.             END IF
  321.         END IF
  322.     NEXT
  323.     xb = (WShade(6) - WShade(4) + (WShade(9) + WShade(3)) / SQR(2) - (WShade(7) + WShade(1)) / SQR(2))
  324.     yb = (WShade(8) - WShade(2) + (WShade(7) + WShade(9)) / SQR(2) - (WShade(1) + WShade(3)) / SQR(2))
  325.     x = x + xb
  326.     y = y + yb
  327.  
  328.     ' green
  329.     FOR k = 1 TO 9
  330.         IF (k <> 5) THEN
  331.             IF ((_RED32(WPoint(k)) < 5) AND (_GREEN32(WPoint(k)) > 250) AND (_BLUE32(WPoint(k)) < 5)) THEN
  332.                 WShade(k) = _RED32(WShade(k)) + _GREEN32(WPoint(k)) + _BLUE32(WPoint(k))
  333.                 cs = 1
  334.             ELSE
  335.                 WShade(k) = 0
  336.             END IF
  337.         END IF
  338.     NEXT
  339.     xg = -(WShade(6) - WShade(4) + (WShade(9) + WShade(3)) / SQR(2) - (WShade(7) + WShade(1)) / SQR(2))
  340.     yg = (0 - WShade(2) + (0 + 0) / SQR(2) - (WShade(1) + WShade(3)) / SQR(2))
  341.     x = x + xg
  342.     y = y + yg
  343.  
  344.     ' custom yellow
  345.     FOR k = 1 TO 9
  346.         IF (k <> 5) THEN
  347.             IF ((_RED32(WPoint(k)) > 250) AND (_GREEN32(WPoint(k)) > 250) AND (_BLUE32(WPoint(k)) < 5)) THEN
  348.                 WShade(k) = _RED32(WShade(k)) + _GREEN32(WPoint(k)) + _BLUE32(WPoint(k))
  349.                 cs = 1
  350.             ELSE
  351.                 WShade(k) = 0
  352.             END IF
  353.         END IF
  354.     NEXT
  355.     xc = (WShade(6) - 0 + (WShade(9) + WShade(3)) / SQR(2) - (0 + 0) / SQR(2))
  356.     yc = 0
  357.     x = x + xc
  358.     y = y + yc
  359.  
  360.     ' custom aqua
  361.     FOR k = 1 TO 9
  362.         IF (k <> 5) THEN
  363.             IF ((_RED32(WPoint(k)) < 5) AND (_GREEN32(WPoint(k)) > 250) AND (_BLUE32(WPoint(k)) > 250)) THEN
  364.                 WShade(k) = _RED32(WShade(k)) + _GREEN32(WPoint(k)) + _BLUE32(WPoint(k))
  365.                 cs = 1
  366.             ELSE
  367.                 WShade(k) = 0
  368.             END IF
  369.         END IF
  370.     NEXT
  371.     xc = -(WShade(6) - 0 + (WShade(9) + WShade(3)) / SQR(2) - (0 + 0) / SQR(2))
  372.     yc = 0
  373.     x = x + xc
  374.     y = y + yc
  375.  
  376.     ' custom white
  377.     FOR k = 1 TO 9
  378.         IF (k <> 5) THEN
  379.             IF ((_RED32(WPoint(k)) > 250) AND (_GREEN32(WPoint(k)) > 250) AND (_BLUE32(WPoint(k)) > 250)) THEN
  380.                 WShade(k) = _RED32(WShade(k)) + _GREEN32(WPoint(k)) + _BLUE32(WPoint(k))
  381.                 cs = 1
  382.             ELSE
  383.                 WShade(k) = 0
  384.             END IF
  385.         END IF
  386.     NEXT
  387.     xc = -(WShade(6) - WShade(4) + (WShade(9) + WShade(3)) / SQR(2) - (WShade(7) + WShade(1)) / SQR(2))
  388.     yc = -(0 - WShade(2) + (0 + 0) / SQR(2) - (WShade(1) + WShade(3)) / SQR(2))
  389.     x = x + xc
  390.     y = y + yc
  391.  
  392.     ' custom violet
  393.     FOR k = 1 TO 9
  394.         IF (k <> 5) THEN
  395.             IF ((_RED32(WPoint(k)) > 250) AND (_GREEN32(WPoint(k)) < 5) AND (_BLUE32(WPoint(k)) > 250)) THEN
  396.                 WShade(k) = _RED32(WShade(k)) + _GREEN32(WPoint(k)) + _BLUE32(WPoint(k))
  397.                 cs = 1
  398.             ELSE
  399.                 WShade(k) = 0
  400.             END IF
  401.         END IF
  402.     NEXT
  403.     xc = (WShade(6) - WShade(4) + (WShade(9) + WShade(3)) / SQR(2) - (WShade(7) + WShade(1)) / SQR(2))
  404.     yc = (WShade(8) - WShade(2) + (WShade(7) + WShade(9)) / SQR(2) - (WShade(1) + WShade(3)) / SQR(2))
  405.     x = x + xc
  406.     y = y + yc
  407.  
  408.     ' Conductivity
  409.     IF (cs = 0) THEN
  410.         IF ((xr * xr + yr * yr) > (xb * xb + yb * yb)) THEN
  411.             PixelCloud(i).TheShade.shadered = PixelCloud(i).TheShade.shadered + 64
  412.             IF (PixelCloud(i).TheShade.shadered >= 255) THEN PixelCloud(i).TheShade.shadered = 255
  413.             PixelCloud(i).TheShade.shadeblue = PixelCloud(i).TheShade.shadeblue - 64
  414.             IF (PixelCloud(i).TheShade.shadeblue <= 0) THEN PixelCloud(i).TheShade.shadeblue = 0
  415.         END IF
  416.         IF ((xb * xb + yb * yb) > (xr * xr + yr * yr)) THEN
  417.             PixelCloud(i).TheShade.shadered = PixelCloud(i).TheShade.shadered - 64
  418.             IF (PixelCloud(i).TheShade.shadered <= 0) THEN PixelCloud(i).TheShade.shadered = 0
  419.             PixelCloud(i).TheShade.shadeblue = PixelCloud(i).TheShade.shadeblue + 64
  420.             IF (PixelCloud(i).TheShade.shadeblue >= 255) THEN PixelCloud(i).TheShade.shadeblue = 255
  421.         END IF
  422.     END IF
  423.  
  424.     ' Gravity vs. levity
  425.     IF (cs = 0) THEN
  426.         y = y - (PixelCloud(i).TheShade.shadered - PixelCloud(i).TheShade.shadeblue) / 255
  427.     END IF
  428.  
  429.     ' Normalize acceleration
  430.     IF (ABS(x) < .001) THEN
  431.         PixelCloud(i).acceleration.x = 0
  432.     ELSE
  433.         PixelCloud(i).acceleration.x = -x / SQR(x * x + y * y)
  434.     END IF
  435.     IF (ABS(y) < .001) THEN
  436.         PixelCloud(i).acceleration.y = 0
  437.     ELSE
  438.         PixelCloud(i).acceleration.y = -y / SQR(x * x + y * y)
  439.     END IF
  440.  
  441.     ' Auto-cooling
  442.     IF (cs = 0) THEN
  443.         PixelCloud(i).TheShade.shadered = PixelCloud(i).TheShade.shadered - 2
  444.         IF (PixelCloud(i).TheShade.shadered <= 0) THEN PixelCloud(i).TheShade.shadered = 0
  445.         PixelCloud(i).TheShade.shadeblue = PixelCloud(i).TheShade.shadeblue + 2
  446.         IF (PixelCloud(i).TheShade.shadeblue >= 255) THEN PixelCloud(i).TheShade.shadeblue = 255
  447.     END IF
  448.  
  449. FUNCTION cpoint& (x1 AS DOUBLE, y1 AS DOUBLE)
  450.     DIM TheReturn AS _UNSIGNED LONG
  451.     TheReturn = POINT(_WIDTH / 2 + x1, -y1 + _HEIGHT / 2)
  452.     cpoint = TheReturn
  453.  
  454. SUB clinebf (x1 AS DOUBLE, y1 AS DOUBLE, x2 AS DOUBLE, y2 AS DOUBLE, col AS _UNSIGNED LONG)
  455.     LINE (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2)-(_WIDTH / 2 + x2 - 0, -y2 + _HEIGHT / 2 + 0), col, BF
  456.  
  457. SUB slinebf (x1 AS DOUBLE, y1 AS DOUBLE, x2 AS DOUBLE, y2 AS DOUBLE, col AS _UNSIGNED LONG)
  458.     LINE (x1, y1)-(x2, y2), col, BF
  459.  
  460. SUB cprintstring (y1 AS DOUBLE, a AS STRING)
  461.     _PRINTSTRING (_WIDTH / 2 - (LEN(a) * 8) / 2, -y1 + _HEIGHT / 2), a
  462.  
  463. SUB LoadFile
  464.     DIM i AS INTEGER
  465.     DIM j AS INTEGER
  466.     DIM r AS INTEGER
  467.     DIM g AS INTEGER
  468.     DIM b AS INTEGER
  469.     DIM a AS INTEGER
  470.     IF (COMMAND$ <> "") THEN
  471.         PRINT "Loading..."
  472.         OPEN COMMAND$ FOR INPUT AS #1
  473.         DO WHILE NOT EOF(1)
  474.             INPUT #1, i, j, r, g, b, a
  475.             Level(i, j).shadered = r
  476.             Level(i, j).shadegreen = g
  477.             Level(i, j).shadeblue = b
  478.             Level(i, j).shadealpha = a
  479.         LOOP
  480.         CLOSE #1
  481.     END IF
  482.  
* Christmas2020.txt (Filesize: 1.58 MB, Downloads: 116)
ss.png
* ss.png (Filesize: 76.32 KB, Dimensions: 1024x768, Views: 185)
You're not done when it works, you're done when it's right.

Offline Dav

  • Forum Resident
  • Posts: 792
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #65 on: December 15, 2020, 08:55:47 am »
@johnno56: That sounds good to me.  The top was as afterthought.  I should have made it silver or something before posting.

@STxAxTIC: That looks pretty cool...

Here is something I started working on last night, a multi-note PLAY like system using sound files.  Since it's Christmas I made it play a Christmas song and will post it here.  I wanted to make PLAY songs that used real sounds and play chords, so here it is playing Silent Night. The sound files I ripped from my TankDrum thing.

NOTE: .OGG Alert for those who have problems opening files with .OGG files...

Download       (385k)

Here's the source code, but you will need the SPLAY.ZIP above to run it...

- Dav

Note: Edited code to v1.02. (12/15/2020)
Code: QB64: [Select]
  1. '=========
  2. 'SPLAY.BAS v1.02
  3. '=========
  4. 'A multi-note PLAY-like method using sound files to
  5. 'play notes, and allow more than one note at a time.
  6. 'This demo plays Silent Night.
  7. 'Coded By Dav, DEC/2020
  8.  
  9. 'Added: Added Rests (RN).
  10. 'Fixed: Replace delay routine. Actually works now.
  11. 'Fixed: Allows spaces in note groups ( )
  12. 'Added: Added inkey$ bail-out of SUB playing notes
  13.  
  14. 'Over time I'll adapt this to math PLAY commands as
  15. 'much as possible, but for now heres how you use it:
  16.  
  17. 'For now, there only 15 notes playable, about 2 octaves.
  18. ' e1 f1 g1 a1 b1 | c2 d2 e2 f2 g2 a2 b2 | c3 d3 e3
  19.  
  20. 'You can play a chord of notes by grouping inside ()
  21. ' (c2 e2 g2)
  22.  
  23. 'Assign current note/rest length values like this...
  24. 'WN = Whole note, HN = Half note, DQ = Dotted quarter note
  25. 'QN = Quarter note, EN = Eighth note, SN = Sixteenth note
  26.  
  27. 'Rests - nothing played, but time continues
  28. 'RN = Rest note.  Uses current note length value set.
  29. 'For example, to rest a quarter note, do this:
  30. 'QN RN
  31.  
  32. 'Assign Tempos like this (always must be in 4 characters):
  33. 'T120  ... or T060   ...  or  T100
  34.  
  35. 'Assign current meter (for whole length value to work)
  36. 'M3  (thats for 3/4)....  M4   (Thats for 4/4)
  37.  
  38.  
  39. '=========================================================
  40.  
  41. 'Sound file handles
  42. DIM SHARED e1&, f1&, g1&, a1&, b1&, c2&, d2&
  43. DIM SHARED e2&, f2&, g2&, a2&, b2&, c3&, d3&, e3&
  44. DIM SHARED Tempo, Meter, NoteValue 'playing values
  45.  
  46. 'Load sound samples
  47. e1& = _SNDOPEN("ogg/e1.ogg"): f1& = _SNDOPEN("ogg/f1.ogg")
  48. g1& = _SNDOPEN("ogg/g1.ogg"): a1& = _SNDOPEN("ogg/a1.ogg")
  49. b1& = _SNDOPEN("ogg/b1.ogg"): c2& = _SNDOPEN("ogg/c2.ogg")
  50. d2& = _SNDOPEN("ogg/d2.ogg"): e2& = _SNDOPEN("ogg/e2.ogg")
  51. f2& = _SNDOPEN("ogg/f2.ogg"): g2& = _SNDOPEN("ogg/g2.ogg")
  52. a2& = _SNDOPEN("ogg/a2.ogg"): b2& = _SNDOPEN("ogg/b2.ogg")
  53. c3& = _SNDOPEN("ogg/c3.ogg"): d3& = _SNDOPEN("ogg/d3.ogg")
  54. e3& = _SNDOPEN("ogg/e3.ogg")
  55.  
  56.  
  57. PRINT "Testing all notes...e1 to e3"
  58. 'Set tempo 120, meter 4/4, set sixteen note value, play all notes
  59. SPLAY "t120 m4 sn e1f1g1a1b1c2d2e2f2g2a2b2c3d3e3"
  60.  
  61. 'Note: You don't have to include spaces, but I did here...
  62.  
  63. PRINT "Playing chords..."
  64. 'Note: tempo and meter already set in earlier call, so
  65. '      below will play with that, but you can change it...
  66. SPLAY "qn (c2 e2 g2) rn rn (f2a2c3) (g2b2d3) wn (c3g2e2c2g1)"
  67.  
  68. 'Now, since it's Christmas, play a Christmas song...
  69.  
  70.     CLS: PRINT
  71.     PRINT "Silent night...";
  72.     SPLAY "t100m3dq(c2e2g2)en(c2f2a2)qn(c2e2g2)wn(g1c2e2)"
  73.     PRINT "Holy night..."
  74.     SPLAY "dq(c2e2g2)en(c2f2a2)qn(c2e2g2)wn(g1c2e2)"
  75.     PRINT "All is calm....";
  76.     SPLAY "hn(d3b2g2)qnd3(g2b2)c3(d3g2f2)"
  77.     PRINT "All is bright..."
  78.     SPLAY "hn(c3g2e2)en(c3g2)f2qn(c2e2g3)d2e2"
  79.     PRINT "Round 'yon virgin...";
  80.     SPLAY "en(a2f2)g2f2g2(a2f2)(g2b2)qn(c3a2f2)(b2g2)(a2f2)"
  81.     PRINT "Mother and child...."
  82.     SPLAY "dq(g2e2c2)en(a2f2)qn(g2e2)(e2c2)d2e2"
  83.     PRINT "Holy Infant so ";
  84.     SPLAY "en(a2f2)g2f2g2(a2f2)(g2b2)qn(c3a2f2)(b2g2)(a2f2)"
  85.     PRINT "Tender and mild."
  86.     SPLAY "dq(g2e2c2)en(a2f2)qn(g2e2)(e2c2)a1g1"
  87.     PRINT "Sleep in heavenly peace...."
  88.     SPLAY "hn(d3b2bg2f2)qn(d2b2)dq(d2f2g2)enc3qn(b2g2f2)wn(e2g2c3)(e3c3g3)"
  89.     PRINT "Sleep in heavenly peace."
  90.     SPLAY "qn(c3g2e2c2)g2e2dq(g2f2d2b1)enf2qnd2wn(c2g1e1)qnc3g2d2"
  91.  
  92.  
  93. SUB SPLAY (Music$)
  94.  
  95.     'Set Defaults, just in case empty
  96.     IF Tempo = 0 THEN Tempo = 60
  97.     IF Meter = 0 THEN Meter = 3
  98.     IF NoteValue = 0 THEN NoteValue = 1
  99.  
  100.     Music$ = UCASE$(Music$)
  101.     cur = 1
  102.  
  103.     DO
  104.  
  105.         'skip any spaces
  106.         IF MID$(Music$, cur, 1) = " " THEN cur = cur + 1
  107.  
  108.         'Check for tempo
  109.         IF MID$(Music$, cur, 1) = "T" THEN
  110.             cur = cur + 1
  111.             Tempo = VAL(MID$(Music$, cur, 3)): cur = cur + 3
  112.         END IF
  113.  
  114.         'Check for Meter
  115.         IF MID$(Music$, cur, 1) = "M" THEN
  116.             cur = cur + 1
  117.             Meter = VAL(MID$(Music$, cur, 1)): cur = cur + 1
  118.         END IF
  119.  
  120.         'Get notevalue
  121.         SELECT CASE MID$(Music$, cur, 2)
  122.             CASE IS = "DQ": cur = cur + 2: NoteValue = 1.5
  123.             CASE IS = "EN": cur = cur + 2: NoteValue = .5
  124.             CASE IS = "QN": cur = cur + 2: NoteValue = 1
  125.             CASE IS = "HN": cur = cur + 2: NoteValue = 2
  126.             CASE IS = "WN": cur = cur + 2
  127.                 IF Meter = 3 THEN NoteValue = 3 ELSE NoteValue = 4
  128.             CASE IS = "SN": cur = cur + 2: NoteValue = .25
  129.         END SELECT
  130.  
  131.         'If regular note/rest found (not a group)
  132.         SELECT CASE MID$(Music$, cur, 2)
  133.             CASE IS = "E1": _SNDPLAYCOPY e1&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  134.             CASE IS = "F1": _SNDPLAYCOPY f1&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  135.             CASE IS = "G1": _SNDPLAYCOPY g1&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  136.             CASE IS = "A1": _SNDPLAYCOPY a1&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  137.             CASE IS = "B1": _SNDPLAYCOPY b1&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  138.             CASE IS = "C2": _SNDPLAYCOPY c2&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  139.             CASE IS = "D2": _SNDPLAYCOPY d2&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  140.             CASE IS = "E2": _SNDPLAYCOPY e2&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  141.             CASE IS = "F2": _SNDPLAYCOPY f2&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  142.             CASE IS = "G2": _SNDPLAYCOPY g2&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  143.             CASE IS = "A2": _SNDPLAYCOPY a2&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  144.             CASE IS = "B2": _SNDPLAYCOPY b2&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  145.             CASE IS = "C3": _SNDPLAYCOPY c3&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  146.             CASE IS = "D3": _SNDPLAYCOPY d3&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  147.             CASE IS = "E3": _SNDPLAYCOPY e3&: cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  148.             CASE IS = "RN": cur = cur + 2: _DELAY (60 * NoteValue / Tempo)
  149.         END SELECT
  150.  
  151.         'if group of notes found
  152.         IF MID$(Music$, cur, 1) = "(" THEN
  153.             cur = cur + 1
  154.             'Grab up until ')' found
  155.             Group$ = ""
  156.             DO
  157.                 a$ = MID$(Music$, cur, 1): cur = cur + 1
  158.                 IF a$ = ")" THEN EXIT DO
  159.                 IF a$ <> " " THEN Group$ = Group$ + a$
  160.             LOOP
  161.             FOR N = 1 TO LEN(Group$) STEP 2
  162.                 note$ = MID$(Group$, N, 2)
  163.                 IF note$ = "E1" THEN _SNDPLAYCOPY e1&
  164.                 IF note$ = "F1" THEN _SNDPLAYCOPY f1&
  165.                 IF note$ = "G1" THEN _SNDPLAYCOPY g1&
  166.                 IF note$ = "A1" THEN _SNDPLAYCOPY a1&
  167.                 IF note$ = "B1" THEN _SNDPLAYCOPY b1&
  168.                 IF note$ = "C2" THEN _SNDPLAYCOPY c2&
  169.                 IF note$ = "D2" THEN _SNDPLAYCOPY d2&
  170.                 IF note$ = "E2" THEN _SNDPLAYCOPY e2&
  171.                 IF note$ = "F2" THEN _SNDPLAYCOPY f2&
  172.                 IF note$ = "G2" THEN _SNDPLAYCOPY g2&
  173.                 IF note$ = "A2" THEN _SNDPLAYCOPY a2&
  174.                 IF note$ = "B2" THEN _SNDPLAYCOPY b2&
  175.                 IF note$ = "C3" THEN _SNDPLAYCOPY c3&
  176.                 IF note$ = "D3" THEN _SNDPLAYCOPY d3&
  177.                 IF note$ = "E3" THEN _SNDPLAYCOPY e3&
  178.             NEXT
  179.             _DELAY (60 * NoteValue / Tempo)
  180.         END IF
  181.  
  182.         IF cur >= LEN(Music$) THEN EXIT DO
  183.  
  184.         IF INKEY$ <> "" THEN EXIT SUB
  185.  
  186.     LOOP
  187.  
  188.     EXIT SUB
  189.  
  190.  




« Last Edit: December 15, 2020, 01:04:17 pm by Dav »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #66 on: December 15, 2020, 11:06:55 am »
I see Santa's elves have been busy :)

@STxAxTIC  what fun to modify a Christmas Card or animation!
 

I suspect Dav's been smitten by the Christmas spirits ;-))

Offline Dav

  • Forum Resident
  • Posts: 792
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #67 on: December 15, 2020, 11:30:52 am »
I suspect Dav's been smitten by the Christmas spirits ;-))

Trying to get in the mood I guess.  Finding it harder to do that this year for some reason.

I just updated the SPLAY program posted above.  Fixed something, added something.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #68 on: December 15, 2020, 11:53:15 am »
@Dav are the oggs all in separate folder? I have no problems with Explorer if I know where not to go with it but of course I use it to access the bas source. I find it easier to navigate (and perform file maintenance, like Delete, Copy, Move Files and Folders) in Explorer than QB64 IDE so I am in habit of using that specially for downloads. PS I don't visit my BlackJack files except through QB64 IDE because of the oggs.

Offline Dav

  • Forum Resident
  • Posts: 792
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #69 on: December 15, 2020, 11:56:17 am »
No folders in the zip, just the .OGG files and the BAS zipped up altogether.  I forget whats the right way to include the .OGG files -- put them in a separate folder?

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #70 on: December 15, 2020, 12:05:32 pm »
No folders in the zip, just the .OGG files and the BAS zipped up altogether.  I forget whats the right way to include the .OGG files -- put them in a separate folder?

- Dav

Yes Oggs in separate and marked folder, for me and I suspect for Windows users that aren't very tech savvy (two v's ??). It's just Windows 10 (only?) Explorer without the downloaded patch you have to get at the Windows Store which means getting an account and possibly being barraged with more Windows updates, notifications or spam.
« Last Edit: December 15, 2020, 12:07:06 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #71 on: December 15, 2020, 12:41:49 pm »
@Dav Very nice work. For me, this is a very exemplary explanation of notes. I saved the program, I have to study it properly in the future.

@STxAxTIC very nice program. Do I see it supposed to simulate something like thermal flow? So I wouldn't dare do that. Just the idea of doing this is just brilliant.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #72 on: December 15, 2020, 12:57:22 pm »
Quote
@STxAxTIC very nice program. Do I see it supposed to simulate something like thermal flow? So I wouldn't dare do that. Just the idea of doing this is just brilliant.

Yeah when I just ran FluidCraft without any drawing, I was reminded of my Particles Fountain only taken to a way higher level.

Offline Dav

  • Forum Resident
  • Posts: 792
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #73 on: December 15, 2020, 01:06:53 pm »
@Petr: Thanks!

@bplus: I repackaged the ZIP, putting the ogg files in a separate folder named ogg/.

I also added the option of including rests in the songs now. New ZIP and code.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #74 on: December 15, 2020, 01:12:01 pm »
Quote
@bplus: I repackaged the ZIP, putting the ogg files in a separate folder named ogg/.

Thanks @Dav what's your favorite charity?

Update: Beautiful! Soothing for the kind of year we've all had.
« Last Edit: December 15, 2020, 02:19:11 pm by bplus »