Author Topic: Xmas 2019 Update  (Read 2287 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Xmas 2019 Update
« on: December 17, 2019, 11:42:31 pm »
Of Bonkers Symphony #37
Code: QB64: [Select]
  1. _TITLE "Bonkers Synphony #37 (2019 Xmas Update)         press spacebar for different view"
  2. '2019-11-24 complete overhall for Xmas 2019 B+ from
  3. ' Bonkers Symphony no 37.bas for QB64 fork (B+=MGA) trans 2017-09-15 from
  4. ' from: Bonkers Symphony Number 37.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-04-21
  5.  
  6. CONST xmax = 1000, ymax = 740
  7. CONST nB = 12, gravity = 4, speed = 12
  8. CONST maxLRow = 9 'lights
  9. TYPE ballType
  10.     x AS SINGLE
  11.     y AS SINGLE
  12.     r AS SINGLE
  13.     a AS SINGLE
  14.     c AS INTEGER
  15.     rr AS INTEGER
  16.     gg AS INTEGER
  17.     bb AS INTEGER
  18. REDIM SHARED L(0) AS ballType, B(0) AS ballType
  19.  
  20. SCREEN _NEWIMAGE(xmax, ymax, 32)
  21. DIM lc, nx, i, j, clrMode, dx, dy 'screen and "tree"
  22.  
  23. REDIM B(1 TO nB) AS ballType
  24. FOR i = 1 TO nB
  25.     newBall i
  26. initLights
  27. drawLandscape
  28. clrMode = 0: nx = 1
  29. WHILE _KEYDOWN(27) = 0
  30.     lc = (lc + 1) MOD 24000
  31.     IF _KEYHIT = 32 THEN
  32.         clrMode = 1 - clrMode
  33.         CLS
  34.         FOR i = 1 TO nB
  35.             newBall i
  36.         NEXT
  37.         initLights
  38.         drawLandscape
  39.         nx = 0
  40.     END IF
  41.     IF clrMode THEN LINE (0, 0)-(xmax, ymax), _RGBA32(0, 0, 0, 5), BF
  42.  
  43.     'draw lights
  44.     FOR i = 1 TO nL
  45.         drawOrb L(i).x, L(i).y, L(i).r, L(i).rr, L(i).gg, L(i).bb, 0
  46.     NEXT
  47.     IF lc MOD 100 = 0 THEN nx = nx + 1
  48.     IF nx > nB THEN nx = nB
  49.  
  50.     'calc collsions
  51.     FOR i = 1 TO nx
  52.         FOR j = 1 TO nL
  53.             IF SQR((B(i).x - L(j).x) ^ 2 + (B(i).y - L(j).y) ^ 2) < B(i).r + L(j).r THEN
  54.                 B(i).a = _ATAN2(B(i).y - L(j).y, B(i).x - L(j).x)
  55.                 L(j).c = L(j).c + 1
  56.                 IF L(j).c > 5 THEN L(j).a = 1 - L(j).a: L(j).c = 0
  57.                 snd L(j).y / ymax * maxLRow, L(j).x / xmax
  58.                 IF L(j).a = 0 THEN
  59.                     drawOrb L(j).x, L(j).y, L(j).r, L(j).rr, L(j).gg, L(j).bb, 1
  60.                     EXIT FOR
  61.                 ELSEIF L(j).a THEN
  62.                     drawOrb L(j).x, L(j).y, L(j).r, L(j).rr, L(j).gg, L(j).bb, 3
  63.                     EXIT FOR
  64.                 END IF
  65.             END IF
  66.         NEXT
  67.         FOR j = i + 1 TO nx
  68.             IF j <> i AND B(j).c <> 1 THEN
  69.                 IF SQR((B(i).x - B(j).x) ^ 2 + (B(i).y - B(j).y) ^ 2) < B(i).r + B(j).r THEN
  70.                     B(i).a = _ATAN2(B(i).y - B(j).y, B(i).x - B(j).x)
  71.                     B(j).a = _ATAN2(B(j).y - B(i).y, B(j).x - B(i).x)
  72.                     B(i).c = 1: B(j).c = 1
  73.                     EXIT FOR
  74.                 END IF
  75.             END IF
  76.         NEXT
  77.  
  78.         'update balls
  79.         dx = COS(B(i).a) * speed
  80.         dy = SIN(B(i).a) * speed + gravity
  81.         B(i).a = _ATAN2(dy, dx)
  82.         B(i).x = B(i).x + dx
  83.         B(i).y = B(i).y + dy
  84.  
  85.         IF B(i).x < 0 OR B(i).x > xmax OR B(i).y > ymax THEN
  86.             newBall i
  87.         END IF
  88.         'IF B(i).a > _PI(2) THEN B(i).a = B(i).a - _PI(2)
  89.         'IF B(i).a < 0 THEN B(i).a = B(i).a + _PI(2)
  90.  
  91.         drawOrb B(i).x, B(i).y, B(i).r, B(i).rr, B(i).gg, B(i).bb, 2
  92.         B(i).c = 0
  93.     NEXT
  94.     _DISPLAY
  95.     _LIMIT 20
  96.  
  97. SUB newBall (i)
  98.     IF RND < .5 THEN B(i).x = irnd(xmax / 2 - 30, xmax / 2 - 5) ELSE B(i).x = irnd(xmax / 2 + 5, xmax / 2 + 30)
  99.     B(i).y = irnd(-100, -10)
  100.     B(i).r = irnd(3, 10)
  101.     B(i).a = _PI(.5) + _PI(1 / 90) * rdir
  102.     B(i).gg = irnd(60, 120)
  103.     B(i).rr = irnd(0, .5 * B(i).gg)
  104.     B(i).bb = irnd(0, .4 * B(i).gg)
  105.  
  106. SUB initLights
  107.     DIM i, lxo, lyo, row, col, y
  108.     nL = maxLRow * (maxLRow + 1) * .5
  109.     lxo = xmax / (maxLRow + 1)
  110.     lyo = (ymax - 5 * (maxLRow + 1) * maxLRow / 2) / (maxLRow + 1) 'more space for lower rows
  111.     REDIM L(1 TO nL) AS ballType
  112.     i = 0: y = 0
  113.     FOR row = 1 TO maxLRow
  114.         y = y + lyo + 5 * row 'more space for lower rows
  115.         FOR col = 1 TO row
  116.             i = i + 1
  117.             L(i).x = lxo * col + (maxLRow - row) * .5 * lxo + irnd(-3 * row, 3 * row)
  118.             L(i).y = y + irnd(-15, 15)
  119.             L(i).r = 6 + irnd(row, row + 6) 'bigger for lower rows
  120.             L(i).rr = irnd(128, 255) 'red lights are great!
  121.             L(i).gg = irnd(128, 255) * irnd(0, 1) 'get rid of two many mixes
  122.             L(i).bb = irnd(128, 255) * irnd(0, 1)
  123.         NEXT
  124.     NEXT
  125.  
  126. SUB drawOrb (x, y, r, red, green, blue, litMode) 'make sphere if lit or not
  127.     DIM rr
  128.     IF litMode = 1 THEN
  129.         fcirc x, y, r, _RGB32(red, green, blue)
  130.         FOR rr = 36 TO 0 STEP -2
  131.             fcirc x, y, rr, _RGBA32(255, 255, 255, 1)
  132.         NEXT
  133.     ELSEIF litMode = 0 THEN
  134.         FOR rr = r TO 0 STEP -1
  135.             fcirc x, y, rr, _RGB32(red - rr * 7, green - rr * 7, blue - rr * 7)
  136.         NEXT
  137.     ELSEIF litMode = 2 THEN
  138.         FOR rr = r TO 0 STEP -1
  139.             fcirc x, y, rr, _RGB32(red * (1 - rr / r), green * (1 - rr / r), blue * (1 - rr / r))
  140.         NEXT
  141.     ELSEIF litMode = 3 THEN
  142.         fcirc x, y, r, _RGB32(red, green, blue)
  143.         FOR rr = 36 TO 0 STEP -2
  144.             fcirc x, y, rr, _RGBA32(0, 0, 0, 2)
  145.         NEXT
  146.     END IF
  147.  
  148. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  149.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  150.     DIM X AS INTEGER, Y AS INTEGER
  151.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  152.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  153.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  154.     WHILE X > Y
  155.         RadiusError = RadiusError + Y * 2 + 1
  156.         IF RadiusError >= 0 THEN
  157.             IF X <> Y + 1 THEN
  158.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  159.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  160.             END IF
  161.             X = X - 1
  162.             RadiusError = RadiusError - X * 2
  163.         END IF
  164.         Y = Y + 1
  165.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  166.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  167.     WEND
  168.  
  169. SUB snd (frq, dur)
  170.     SOUND 314.1592654 * (maxLRow - frq) + 220, dur + RND * .3
  171.  
  172. SUB drawLandscape 'needs midInk, irnd
  173.     DIM i AS INTEGER, startH AS SINGLE, rr AS INTEGER, gg AS INTEGER, bb AS INTEGER
  174.     DIM mountain AS INTEGER, Xright AS SINGLE, y AS SINGLE, upDown AS SINGLE, range AS SINGLE
  175.     DIM lastx AS SINGLE, X AS INTEGER
  176.     'the sky
  177.     FOR i = 0 TO ymax
  178.         midInk 0, 0, 25, 14, 0, 44, i / ymax
  179.         LINE (0, i)-(xmax, i)
  180.     NEXT
  181.     'the land
  182.     startH = ymax - 400
  183.     rr = 40: gg = 50: bb = 60
  184.     FOR mountain = 1 TO 6
  185.         Xright = 0
  186.         y = startH
  187.         WHILE Xright < xmax
  188.             ' upDown = local up / down over range, change along Y
  189.             ' range = how far up / down, along X
  190.             upDown = (RND * .8 - .35) * (mountain * .5)
  191.             range = Xright + irnd(15, 25) * 2.5 / mountain
  192.             lastx = Xright - 1
  193.             FOR X = Xright TO range
  194.                 y = y + upDown
  195.                 COLOR _RGB(rr, gg, bb)
  196.                 LINE (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  197.                 lastx = X
  198.             NEXT
  199.             Xright = range
  200.         WEND
  201.         rr = irnd(rr - 15, rr): gg = irnd(gg - 15, gg): bb = irnd(bb - 25, bb)
  202.         IF rr < 0 THEN rr = 0
  203.         IF gg < 0 THEN gg = 0
  204.         IF bb < 0 THEN bb = 0
  205.         startH = startH + irnd(5, 20)
  206.     NEXT
  207.  
  208. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  209.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  210.  
  211. FUNCTION irnd (n1, n2) 'return random in interval
  212.     DIM l, h
  213.     IF n1 > n2 THEN l = n2: h = n1 ELSE l = n1: h = n2
  214.     irnd = RND * (h - l) + l
  215.  
  216. FUNCTION rdir ()
  217.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  218.  
  219.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Xmas 2019 Update
« Reply #1 on: December 18, 2019, 11:52:09 pm »
Cool bplus! Total bonkers! You inspired me to dig out the old PLAY command tonight for the first time with QB64 and make Jingle Bells using simple notes I found online. I added the lyrics as it plays.

Code: QB64: [Select]
  1. _TITLE "Jingle Bells - by Ken G."
  2. SCREEN _NEWIMAGE(400, 200, 32)
  3. COLOR _RGB32(127, 249, 127)
  4. start:
  5. _LIMIT 100
  6. _PRINTSTRING (100, 100), "Jingle bells, jingle bells"
  7. PLAY "v10 O3 E E E P8 E E E P4"
  8. _PRINTSTRING (100, 100), "Jingle all the way"
  9. PLAY "V10 O3 E G C P12 D E P4"
  10. _PRINTSTRING (100, 100), "Oh, what fun it is to ride"
  11. PLAY "v10 O3 F F F P8 F F E E"
  12. _PRINTSTRING (100, 100), "In a one-horse open sleigh, Oh!"
  13. PLAY "v10 O3 L8 E L8 E L4 E D D E D P4 G"
  14. _PRINTSTRING (100, 100), "Jingle bells, jingle bells"
  15. PLAY "v10 O3 E E E P8 E E E"
  16. _PRINTSTRING (100, 100), "Jingle all the way"
  17. PLAY "v10 O3 E G C D E"
  18. _PRINTSTRING (100, 100), "Oh, what fun it is to ride"
  19. PLAY "v10 O3 P2 F F F F F E E"
  20. _PRINTSTRING (100, 100), "In a one-horse open sleigh"
  21. PLAY "v10 O3 L8 E L8 E L4 G G F D C"
  22. PRINT "Again (Y/N)?"
  23. again:
  24. ag$ = INKEY$
  25. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  26. IF ag$ = "n" OR ag$ = "N" THEN END
  27. GOTO again:
  28.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Xmas 2019 Update
« Reply #2 on: December 19, 2019, 01:01:09 am »
Nice one Ken, you've got me reading the PLAY command notes. I didn't know you could play several notes at once. Wow, I've got to dig into this for next Christmas!

Here is what it is supposed to look like tomorrow:
Code: QB64: [Select]
  1. _TITLE "Snowjob, drawn flakes" ' B+ mod 2018-12-5 (title before this mod)
  2.  
  3. ' screen
  4. CONST XMAX = 800
  5. CONST YMAX = 600
  6. SCREEN _NEWIMAGE(XMAX, YMAX, 32)
  7. _SCREENMOVE 200, 100
  8. 'snow making machine
  9. TYPE PARTICLE
  10.     x AS SINGLE
  11.     y AS SINGLE
  12.     dx AS SINGLE
  13.     dy AS SINGLE
  14.     size AS SINGLE
  15.     density AS SINGLE
  16.     angle AS SINGLE
  17.     dir AS SINGLE
  18.     maxy AS SINGLE
  19.  
  20. '  background, try 3 backgrounds
  21. wallpaper& = _NEWIMAGE(XMAX, YMAX, 32)
  22. _DEST wallpaper&
  23. drawLandscape
  24.  
  25. nLayers = 15
  26. flakes = 2 ^ (nLayers + 1) - 1
  27. DIM snow(flakes) AS PARTICLE
  28. horizon = .5 * YMAX
  29. FOR layer = nLayers TO 1 STEP -1
  30.     FOR flake = 0 TO 2 ^ layer
  31.         snow(flake).x = RND * 2 * XMAX - .5 * XMAX
  32.         snow(flake).y = RND * YMAX
  33.         snow(flake).dx = .1 * (nLayers + 1 - layer) * COS(RND * _PI(.6666) + _PI(.0833))
  34.         snow(flake).dy = .1 * (nLayers + 1 - layer) * SIN(RND * _PI(.6666) + _PI(.0833))
  35.         snow(flake).size = .5 * (nLayers - layer)
  36.         snow(flake).density = 2.3 + RND * .5
  37.         snow(flake).angle = RND * _PI
  38.         IF RND < .5 THEN snow(flake).dir = -1 ELSE snow(flake).dir = 1
  39.         snow(flake).maxy = horizon + (nLayers + 1 - layer) * 30
  40.     NEXT
  41.  
  42.  
  43.     _PUTIMAGE , wallpaper&, 0
  44.     FOR flake = flakes TO 0 STEP -1
  45.         snow(flake).x = snow(flake).x + snow(flake).dx
  46.         snow(flake).y = snow(flake).y + snow(flake).dy
  47.  
  48.         IF snow(flake).size <= 1 THEN
  49.             PSET (snow(flake).x, snow(flake).y), _RGBA32(255, 255, 255, 80)
  50.         ELSEIF snow(flake).size <= 2 THEN
  51.             CIRCLE (snow(flake).x, snow(flake).y), 1, _RGBA32(255, 255, 255, 100)
  52.         ELSE
  53.             snow(flake).angle = snow(flake).angle + snow(flake).dir * _PI(1 / 400)
  54.             rFlake snow(flake).x, snow(flake).y, snow(flake).size, snow(flake).density, snow(flake).angle
  55.         END IF
  56.         IF snow(flake).y > snow(flake).maxy OR snow(flake).x < -.5 * XMAX OR snow(flake).x > 1.5 * XMAX THEN
  57.             snow(flake).x = RND * 2 * XMAX - .5 * XMAX
  58.             snow(flake).y = RND * YMAX - 1.1 * YMAX
  59.         END IF
  60.     NEXT
  61.     _DISPLAY
  62.     _LIMIT 60
  63.  
  64. SUB rFlake (x, y, r, DV, rAng)
  65.     'DV = flake density
  66.     COLOR _RGBA32(225, 225, 245, r ^ 2 * 30)
  67.     FOR a = 0 TO 5
  68.         armX = x + r * COS(a * _PI(1 / 3) + rAng)
  69.         armY = y + r * SIN(a * _PI(1 / 3) + rAng)
  70.         LINE (x, y)-(armX, armY)
  71.         IF r > 2.5 THEN rFlake armX, armY, r / DV, DV, rAng
  72.     NEXT
  73.  
  74. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  75.     COLOR _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  76.  
  77. FUNCTION rand% (lo%, hi%)
  78.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  79.  
  80. SUB drawLandscape
  81.     'needs midInk, rand
  82.     'the sky
  83.     FOR i = 0 TO YMAX
  84.         midInk 200, 90, 158, 58, 28, 90, i / YMAX
  85.         LINE (0, i)-(XMAX, i)
  86.     NEXT
  87.     'the land
  88.     startH = YMAX - 300
  89.     rgb = 160
  90.     FOR mountain = 1 TO 6
  91.         Xright = 0
  92.         y = startH
  93.         WHILE Xright < XMAX
  94.             ' upDown = local up / down over range, change along Y
  95.             ' range = how far up / down, along X
  96.             upDown = (RND * .8 - .35) * (mountain * .5)
  97.             range = Xright + rand%(15, 35) * 3.5 / mountain
  98.             lastx = Xright - 1
  99.             COLOR _RGB32(rgb + 40, rgb - 30, rgb)
  100.             FOR X = Xright TO range
  101.                 y = y + upDown
  102.  
  103.                 LINE (lastx, y)-(X, YMAX), , BF 'just lines weren't filling right
  104.                 lastx = X
  105.             NEXT
  106.             Xright = range
  107.         WEND
  108.         '_DELAY 1
  109.         rgb = rand%(rgb, rgb + 20)
  110.         startH = startH + rand%(5, 20)
  111.     NEXT
  112.  
  113.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: Xmas 2019 Update
« Reply #3 on: December 19, 2019, 07:15:45 am »
Hi Bplus!
cool!
what concert of beep bop when the tree is full! :-)
Christmas bonce Bplus.jpg

moreover I think that there is the pole night in this snow landscape
« Last Edit: December 19, 2019, 07:19:10 am by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: Xmas 2019 Update
« Reply #4 on: December 19, 2019, 07:19:38 am »
 
pole north bplus.jpg
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Xmas 2019 Update
« Reply #5 on: December 19, 2019, 12:50:03 pm »
Awesome snow bplus! Yeah I learned the PLAY command back in the 90's but had forgotten how to use it since yesterday. :) It's best to know at least some of the commands for it from the Wiki page. They don't put spaces between the notes, but I do to make it easier to read. I'm not sure if I needed the v10's though for volume, I just added it anyway.
https://www.qb64.org/wiki/PLAY
 

« Last Edit: December 19, 2019, 12:51:33 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Xmas 2019 Update
« Reply #6 on: December 19, 2019, 03:47:12 pm »
This morning I made Jingle Bells again but this time with the SOUND command, so I put both together for people to choose what to hear. I'll make a new forum topic for it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Xmas 2019 Update
« Reply #7 on: December 19, 2019, 04:45:28 pm »
Just saw it LOL