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

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #15 on: December 07, 2020, 12:13:21 pm »
Thanks Felippe :).

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #16 on: December 08, 2020, 12:12:00 am »
What's more rewarding than having your work featured for the whole community to gasp in awe?

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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #17 on: December 08, 2020, 07:40:24 pm »
OK some pine trees in winter:
Code: QB64: [Select]
  1. _TITLE "Pine Trees mod, any key for another scene..." ' b+ 2020-12-08   mod from
  2. 'Original IFS fractal by Andy Amaya   copy 2019-12-09
  3. 'ap3-191209-216
  4.  
  5. CONST nTrees = 3, sy = 424
  6. REDIM SHARED ox(1 TO nTrees), oy(1 TO nTrees), sx(1 TO nTrees)
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. COLOR , &HFFFFFFFF
  9.     CLS
  10.     FOR y = 0 TO _HEIGHT
  11.         LINE (0, y)-(_WIDTH, y), Ink~&(&HFF332266, &H88FFFFFF, y / _HEIGHT)
  12.     NEXT
  13.     FOR i = 1 TO nTrees
  14.         NewTree i
  15.     NEXT
  16.     FOR t = 1 TO nTrees
  17.         FOR i = 0 TO 40000 ' orig 1 million
  18.             SELECT CASE RND
  19.                 CASE 0 TO .60
  20.                     nx = -0.858985 * lastX + 0.008944 * lastY + 0.092336
  21.                     ny = 0.012263 * lastX + 0.84816 * lastY + -0.04103
  22.                 CASE .60 TO .96
  23.                     nx = -0.373759 * lastX + -0.353068 * lastY + 0.296535
  24.                     ny = 0.353068 * lastX + -0.373759 * lastY + 0.704598
  25.                 CASE ELSE
  26.                     nx = 0.010276 * lastX + 0 * lastY + 0.053328
  27.                     ny = -0.05138 * lastX + 0.313416 * lastY + 0.576552
  28.             END SELECT
  29.             IF i > 36000 THEN
  30.                 PSET (nx * sx(t) + ox(t), ny * sy + oy(t)), &HFFFFFFFF
  31.             ELSEIF i > 30 THEN
  32.                 PSET (nx * sx(t) + ox(t), ny * sy + oy(t)), &HFF116611
  33.             END IF
  34.             lastX = nx
  35.             lastY = ny
  36.         NEXT
  37.     NEXT
  38.     SLEEP
  39.  
  40. SUB NewTree (i)
  41.     ox(i) = RND * (_WIDTH - 300)
  42.     oy(i) = RND * 100 + 150
  43.     sx(i) = RND * 300 + 624
  44.  
  45. SUB cAnalysis (c AS _UNSIGNED LONG, outRed, outGrn, outBlu, outAlp)
  46.     outRed = _RED32(c): outGrn = _GREEN32(c): outBlu = _BLUE32(c): outAlp = _ALPHA32(c)
  47.  
  48. FUNCTION Ink~& (c1 AS _UNSIGNED LONG, c2 AS _UNSIGNED LONG, fr##)
  49.     DIM R1, G1, B1, A1, R2, G2, B2, A2
  50.     cAnalysis c1, R1, G1, B1, A1
  51.     cAnalysis c2, R2, G2, B2, A2
  52.     Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
  53.  

 
Pine trees mod.PNG

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #18 on: December 08, 2020, 09:36:51 pm »
Word Search for Christmas 2020:

No input files, the list is internal but this code outputs 3 txt files:
1. A word List
2. A Letters Grid to Search Words in
3. A Solution of where the words are.
All these are text files that you can print out from your favorite Text Editor. These files are supplemental paper versions, the game itself you can play entirely on the computer.

"Make it beautiful"  ;-))   Well if sound of kids busy with a puzzle is beautiful this might fill the bill. :)

Code: QB64: [Select]
  1. _TITLE "Word Search for Christmas 2020" 'by b+ mod 2020-12-06 modified from:
  2. ' Puzzle Builder #4 sort lists 2020-12-05.bas but no input files!
  3. ' 3 output files will be created in case you want kids the play same game from:
  4. ' 1. A list of search words
  5. ' 2. The Letter Puzzle grid
  6. ' 3. Solution of words start location and direction.
  7.  
  8. DEFLNG A-Z
  9. CONST AscA = 97, WordLengthLimit = 15
  10. CONST ScreenWidth = 1000, ScreenHeight = 640
  11.  
  12. TYPE WordSearch 'having trouble tracking all Global shared variables for puzzle so here is that container
  13.     FileTheme AS STRING ' the theme name for + " Word List.txt" file we are doing
  14.     GridSide AS LONG ' number of letters per side of square grid
  15.     GridSideM1 AS LONG ' grid size - 1
  16.     GridSideP2M1 AS LONG ' grid size ^ 2 - 1
  17.     GridLabel AS STRING ' top and side labeling of letters grid
  18.     NumWords AS LONG ' number of words
  19.     PlaceWordIndex AS LONG ' current index of word we are working
  20.     NumPlacedWords AS LONG ' current number of placed words
  21.     NumUnplacedWords AS LONG 'count the disasters
  22.     UnfilledCellF AS LONG 'there are still unfilled cells F = Flag
  23.     NumBestPlacedWords AS LONG ' best number of placed words here is goal  = NumWords
  24.     Filler AS STRING
  25.  
  26. TYPE WordType
  27.     S AS STRING ' the word  S for String
  28.     Len AS LONG ' it's length
  29.     Placed AS LONG
  30.     X AS LONG ' placements
  31.     Y AS LONG
  32.     D AS LONG ' direction 0 to 7 ie  North, NorthEast, East, SouthEast... NorthWest
  33.  
  34. REDIM SHARED WS AS WordSearch ' this is all shared variables of puzzle in a container
  35. REDIM SHARED Words(1 TO 250) AS WordType ' essential info about each search word
  36. REDIM SHARED AscWord(1 TO 250, WordLengthLimit) ' break the word done to ASC numbers for each letter, speed up processing
  37. REDIM SHARED BestWords(1 TO 250) AS WordType ' best set of words placed
  38. REDIM SHARED AscLetters(0 TO WS.GridSideM1, 0 TO WS.GridSideM1) ' this is the ASC of the letters on the grid
  39. REDIM SHARED AscBestLetters(0 TO WS.GridSideM1, 0 TO WS.GridSideM1) ' this is the ASC of the letters in the Best grid using the most words
  40. REDIM SHARED DX(0 TO 7), DY(0 TO 7), DString$(0 TO 7) ' these are direction "adders" to x, y position to search in directions
  41. REDIM SHARED DirectionTotals(0 TO 7) ' check direction counts for quality puzzle.
  42.  
  43.  
  44. '======================================= Word Search File Base Name and Grid Size ================================================
  45.  
  46. '   Make your word list file with: Some base name for theme + " Word List.txt"
  47.  
  48. ' test file 2 Richard Frost started this theme to test his puzzles from which I learned much :)
  49. 'WS.FileTheme = "Elements" ' add suffix to your file " Word List.txt"    <<<<<<<<<<<<<<<<<<<<<<<<<    Input
  50. 'WS.GridSide = 30 ' <<<<<<<<<<<<<<<<<<<<<<<<<    Input later    30 the maximum grid size
  51. 'WS.Filler = "bplus" ' <<<<<<<<<<<<<<< Input a personalization to hide in the puzzle
  52.  
  53. ' test file 1  The reason this Word Builder was Built! for the naughty and nice nephews and nieces.
  54. WS.FileTheme = "Christmas 2020" 'add suffix to your file " Word List.txt"   <<<<<<<<<<<<<<<<<<<<<<<<<    Input
  55. WS.GridSide = 19 ' <<<<<<<<<<<<<<<<<<<<<<<<<    Input later    30 the maximum grid size
  56. WS.Filler = "SECRET" ' <<<<<<<<<<<<<<< Input a personalization to hide in the puzzle
  57.  
  58. '' test file 3  check a tiny puzzle
  59. 'WS.FileTheme = "The First Four Elements"
  60. 'WS.GridSide = 5 ' <<<<<<<<<<<<<<<<<<<<<<<<<    Input later    30 the maximum grid size
  61. 'WS.Filler = "BPLUS" ' <<<<<<<<<<<<<<< Input a personalization to hide in the puzzle
  62.  
  63. SCREEN _NEWIMAGE(ScreenWidth, ScreenHeight, 32)
  64. _DELAY .25
  65.  
  66. DIM try, c, r, y$, puzzleFiled
  67.  
  68. InitializeOnce
  69. WHILE try < 100 'for long runs uncomment BEEP
  70.     try = try + 1
  71.     RestartPuzzleFill
  72.     IF WS.PlaceWordIndex > 0 THEN ShowPuzzle
  73.     WHILE WS.PlaceWordIndex < WS.NumWords
  74.         WS.PlaceWordIndex = WS.PlaceWordIndex + 1
  75.         WS.UnfilledCellF = 0 ' set F that all are filled
  76.         PlaceWord
  77.         IF WS.UnfilledCellF = 0 OR (WS.NumPlacedWords = WS.NumWords) THEN EXIT WHILE
  78.     WEND
  79.     LOCATE 2, 1: PRINT "Try:"; try
  80.     IF try MOD 25 = 0 THEN _DISPLAY: ShowBestPuzzle
  81.     IF WS.NumPlacedWords > WS.NumBestPlacedWords THEN 'copy Letters$ into Best$
  82.         REDIM AscBestLetters(0 TO WS.GridSideM1, 0 TO WS.GridSideM1)
  83.         FOR r = 0 TO WS.GridSideM1
  84.             FOR c = 0 TO WS.GridSideM1
  85.                 AscBestLetters(c, r) = AscLetters(c, r)
  86.             NEXT
  87.         NEXT
  88.         WS.NumBestPlacedWords = WS.NumPlacedWords
  89.  
  90.         FOR r = 1 TO WS.NumWords '                 copy everything because we shuffle each time
  91.             BestWords(r).S = Words(r).S: BestWords(r).Len = Words(r).Len: BestWords(r).Placed = Words(r).Placed
  92.             BestWords(r).X = Words(r).X: BestWords(r).Y = Words(r).Y: BestWords(r).D = Words(r).D
  93.         NEXT
  94.         Sort BestWords()
  95.         IF WS.NumBestPlacedWords = WS.NumWords THEN '    automatic file if all words positioned in puzzle
  96.             ShowBestPuzzle
  97.             LOCATE 37, 1: PRINT " After "; TS$(try); " tries, this complete puzzle was made."
  98.             FilePuzzle
  99.             LOCATE 39, 1: PRINT " Puzzle Filed, next up is word search.";
  100.             LOCATE 40, 1: PRINT "      press any to continue.";
  101.             puzzleFiled = -1
  102.             LOCATE 1, 1
  103.             _DISPLAY
  104.             SLEEP
  105.             EXIT WHILE
  106.         END IF
  107.     END IF
  108. IF puzzleFiled = 0 THEN
  109.     ShowBestPuzzle
  110.     LOCATE 37, 1: PRINT " After "; TS$(try); " tries, this was best puzzle."
  111.     _DISPLAY
  112.     LOCATE 38, 1: INPUT " Enter y for yes, to save the best to file."; y$
  113.     IF y$ = "y" THEN
  114.         FilePuzzle
  115.         LOCATE 39, 1: PRINT " Puzzle Filed.";
  116.     END IF
  117.     LOCATE 40, 1: PRINT " Next up is word search, press any to continue.";
  118.     LOCATE 1, 1
  119.     _DISPLAY
  120.     SLEEP
  121.  
  122. ' Now to find words in our best puzzle
  123. DIM bestPuz, mx, my, mb, mIndex, wIndex, cnt, hx, hy, wd, sx, sy, navX$, navY$, navD$, i
  124.  
  125. ShowBestPuzzle 'get a snapshot
  126. bestPuz = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)
  127. _PUTIMAGE , 0, bestPuz
  128. WHILE _KEYDOWN(27) = 0
  129.     _PUTIMAGE , bestPuz, 0
  130.     LOCATE 38, 1: PRINT "Move mouse over a word to find."
  131.     mb = _MOUSEBUTTON(1) 'wait for a word to be clicked
  132.     mx = INT(_MOUSEX / 8) + 1: my = INT(_MOUSEY / 16) + 1
  133.     IF mx >= 65 AND mx <= 84 THEN
  134.         mIndex = my
  135.     ELSEIF mx >= 85 AND mx <= 104 THEN
  136.         mIndex = my + 40
  137.     ELSEIF mx >= 105 AND mx <= 125 THEN
  138.         mIndex = my + 80
  139.     ELSE
  140.         mIndex = 0
  141.     END IF
  142.     wIndex = 0: cnt = 0 '                 convert mIndex to wIndex of BestWords
  143.     FOR i = 1 TO WS.NumWords
  144.         IF BestWords(i).Placed THEN
  145.             cnt = cnt + 1
  146.             IF cnt = mIndex THEN wIndex = i: EXIT FOR
  147.         END IF
  148.     NEXT
  149.     IF wIndex THEN
  150.         IF Found(BestWords(wIndex).S, hx, hy, wd) THEN 'high lite it black, yellow
  151.             ConvertCR2Screen hx, hy, sx, sy '    tranlate array location to screen location and navigate column, row
  152.             ConvertCR2Nav hx, hy, wd, navX$, navY$, navD$
  153.             LOCATE 38, 1: PRINT BestWords(wIndex).S; " found at ("; navX$; ", "; navY$; ") going "; navD$
  154.             COLOR &HFF0000BB, &HFFFFFF00
  155.             LOCATE sy, sx: PRINT CHR$(AscBestLetters(hx, hy));
  156.             FOR i = 2 TO BestWords(wIndex).Len
  157.                 hx = hx + DX(wd): hy = hy + DY(wd)
  158.                 ConvertCR2Screen hx, hy, sx, sy
  159.                 LOCATE sy, sx: PRINT CHR$(AscBestLetters(hx, hy));
  160.             NEXT
  161.             COLOR &HFFFFFFFF, &HFF000000
  162.         ELSE
  163.             LOCATE 38, 1: PRINT "Sorry, something is screwed up!";
  164.         END IF
  165.     END IF
  166.     _DISPLAY
  167.     _LIMIT 60
  168.  
  169. SUB InitializeOnce ' everything that needs to be done once to get going
  170.     REDIM wd$, i, j, fName$, pLine$
  171.  
  172.     'new order to favor diagonals placements first if possible
  173.     DX(0) = 1: DY(0) = 0: DString$(0) = "East"
  174.     DX(1) = 0: DY(1) = 1: DString$(1) = "South"
  175.     DX(2) = -1: DY(2) = 0: DString$(2) = "West"
  176.     DX(3) = 0: DY(3) = -1: DString$(3) = "North"
  177.     DX(4) = -1: DY(4) = 1: DString$(4) = "South West"
  178.     DX(5) = -1: DY(5) = -1: DString$(5) = "North West"
  179.     DX(6) = 1: DY(6) = 1: DString$(6) = "South East"
  180.     DX(7) = 1: DY(7) = -1: DString$(7) = "North East"
  181.  
  182.     WS.GridSideM1 = WS.GridSide - 1
  183.     WS.GridSideP2M1 = WS.GridSide * WS.GridSide - 1
  184.     WS.GridLabel = MID$("   0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z", 1, WS.GridSide * 2 + 2)
  185.  
  186.     WS.NumWords = 0
  187.     WHILE wd$ <> "YULETIDE"
  188.         READ wd$
  189.         wd$ = _TRIM$(UCASE$(wd$))
  190.         IF LEN(wd$) <= WordLengthLimit AND wd$ <> "" THEN
  191.             WS.NumWords = WS.NumWords + 1
  192.             Words(WS.NumWords).S = wd$
  193.         END IF
  194.     WEND
  195.     Sort Words()
  196.     FOR j = 1 TO WS.NumWords
  197.         FOR i = 1 TO LEN(Words(j).S)
  198.             Words(j).Len = LEN(Words(j).S)
  199.             AscWord(j, i) = ASC(Words(j).S, i)
  200.         NEXT
  201.     NEXT
  202.  
  203.     REDIM AscLetters(0 TO WS.GridSideM1, 0 TO WS.GridSideM1) 'now that we have the right size
  204.  
  205.     'Now make a Sorted Word List file of up to 3 Columns of 40 words from the capitalized, trimmed, sorted word list
  206.     fName$ = WS.FileTheme + " Sorted 3 Column Search Words.txt"
  207.     OPEN fName$ FOR OUTPUT AS #1
  208.     FOR i = 1 TO 40
  209.         pLine$ = SPACE$(60)
  210.         IF i <= WS.NumWords THEN MID$(pLine$, 1, 20) = TS$(i) + ") " + Words(i).S
  211.         IF i + 40 <= WS.NumWords THEN MID$(pLine$, 21, 20) = TS$(i + 40) + ") " + Words(i + 40).S
  212.         IF i + 80 <= WS.NumWords THEN MID$(pLine$, 41, 20) = TS$(i + 80) + ") " + Words(i + 80).S
  213.         PRINT #1, pLine$
  214.     NEXT
  215.     CLOSE #1
  216.     EXIT SUB
  217.  
  218.     DATA baby,bethlehem,cards,carols,coal,cookies,december,decorate,eggnog,elf,eve,festivities,garland,gifts,green
  219.     DATA grinch,holiday,holly,joseph,joy,lights,mary,magi,manger,nativity,ornaments,poinsettia,red,reindeer,rudolph
  220.     DATA santa,scrooge,shepherd,sleigh,star,stockings,tidings,tinsel,tree,toys,wreath,mistletoe,candycane,angel
  221.     DATA chimney,fruitcake,gingerbread,greetings,goodwill,jingle,jolly,noel,naughty,nice,party
  222.     DATA partridge,ribbon,bow,helpers,sweater,wrap,vacation,workshop,yuletide
  223.  
  224. SUB RestartPuzzleFill
  225.     DIM i, j, k, r, c
  226.  
  227.     WS.PlaceWordIndex = 0
  228.     WS.NumUnplacedWords = 0 'count the disasters
  229.     WS.NumPlacedWords = 0
  230.     FOR i = 1 TO WS.NumWords 'clear positions of words
  231.         Words(i).Placed = 0: Words(i).X = -1: Words(i).Y = -1: Words(i).D = -1
  232.     NEXT
  233.     FOR r = 0 TO WS.GridSideM1 ' clear the letter numbers
  234.         FOR c = 0 TO WS.GridSideM1
  235.             AscLetters(c, r) = 32
  236.         NEXT
  237.     NEXT
  238.     FOR i = WS.NumWords TO 2 STEP -1 'shuffle the list of Words to load
  239.         r = INT(RND * i) + 1
  240.         SWAP Words(i), Words(r)
  241.         FOR j = 0 TO WordLengthLimit
  242.             SWAP AscWord(i, j), AscWord(r, j)
  243.         NEXT
  244.     NEXT
  245.     i = 0
  246.     WHILE i < WS.NumWords - 1 'order by word length
  247.         i = i + 1
  248.         FOR j = i + 1 TO WS.NumWords
  249.             IF Words(j).Len > Words(i).Len THEN
  250.                 SWAP Words(i), Words(j)
  251.                 FOR k = 0 TO WordLengthLimit
  252.                     SWAP AscWord(i, k), AscWord(j, k)
  253.                 NEXT
  254.             END IF
  255.         NEXT
  256.     WEND
  257.  
  258. SUB ShowPuzzle 'this was needed to make sure finding the best puzzle was working correctly
  259.     DIM i, x, y, cnt, notPlaced$, cntUnplaced
  260.     notPlaced$ = ""
  261.     CLS
  262.     LOCATE 1, 1: PRINT WS.GridLabel$
  263.     FOR i = 3 TO 2 + WS.GridSide
  264.         LOCATE i, 1: PRINT MID$(WS.GridLabel$, i * 2 - 2, 1);
  265.     NEXT
  266.     FOR y = 0 TO WS.GridSide - 1
  267.         FOR x = 0 TO WS.GridSide - 1
  268.             LOCATE y + 3, 2 * x + 4: PRINT CHR$(AscLetters(x, y))
  269.         NEXT
  270.     NEXT
  271.     FOR i = 1 TO WS.PlaceWordIndex
  272.         IF Words(i).Placed THEN
  273.             cnt = cnt + 1
  274.             IF cnt <= 40 THEN
  275.                 LOCATE cnt, 65: PRINT TS$(cnt); " "; Words(i).S;
  276.             ELSEIF cnt <= 80 THEN
  277.                 LOCATE cnt - 40, 85: PRINT TS$(cnt); " "; Words(i).S;
  278.             ELSEIF i <= 120 THEN
  279.                 LOCATE cnt - 80, 105: PRINT TS$(cnt); " "; Words(i).S;
  280.             END IF
  281.         ELSE
  282.             cntUnplaced = cntUnplaced + 1
  283.             notPlaced$ = notPlaced$ + Words(i).S + " "
  284.         END IF
  285.     NEXT
  286.     LOCATE 36, 1: PRINT "Words placed:"; WS.NumPlacedWords
  287.     LOCATE 37, 1: PRINT "Unplaced: "; WS.NumUnplacedWords
  288.     LOCATE 38, 1: PRINT "Not placed words: "; notPlaced$; cntUnplaced
  289.     LOCATE 39, 1: PRINT "Last word: "; TS$(WS.PlaceWordIndex); " "; Words(WS.PlaceWordIndex).S;
  290.     'SLEEP
  291.  
  292. SUB PlaceWord
  293.     DIM bestScore, headScore, tailScore, y, x, d, b1, b2, i, spaceHeadF, spaceTailF
  294.  
  295.     bestScore = -1 ' going through entire array of AscLetters try every direction looking for best score = placement
  296.     FOR y = 0 TO WS.GridSideM1
  297.         FOR x = 0 TO WS.GridSideM1
  298.             spaceHeadF = 0 'every new word do this must be certain we have at least one cell empty
  299.             IF AscWord(WS.PlaceWordIndex, 1) = AscLetters(x, y) OR AscLetters(x, y) = 32 THEN
  300.                 IF AscWord(WS.PlaceWordIndex, 1) = AscLetters(x, y) THEN headScore = 15
  301.                 IF AscLetters(x, y) = 32 THEN headScore = 0: WS.UnfilledCellF = -1: spaceHeadF = -1 'no points for blanks but may proceed
  302.                 FOR d = 0 TO 7
  303.                     spaceTailF = 0: tailScore = 0
  304.                     b1 = x + DX(d) * (Words(WS.PlaceWordIndex).Len - 1) >= 0 AND x + DX(d) * (Words(WS.PlaceWordIndex).Len - 1) <= WS.GridSideM1
  305.                     b2 = y + DY(d) * (Words(WS.PlaceWordIndex).Len - 1) >= 0 AND y + DY(d) * (Words(WS.PlaceWordIndex).Len - 1) <= WS.GridSideM1
  306.                     IF b1 AND b2 THEN 'we're in
  307.                         FOR i = 2 TO Words(WS.PlaceWordIndex).Len
  308.                             IF AscWord(WS.PlaceWordIndex, i) = AscLetters(x + DX(d) * (i - 1), y + DY(d) * (i - 1)) THEN
  309.                                 tailScore = tailScore + 10 + (d <= 3) * -1 + (d > 3) * -(INT(RND * 4) + 1)
  310.                             ELSEIF AscLetters(x + DX(d) * (i - 1), y + DY(d) * (i - 1)) = 32 THEN
  311.                                 WS.UnfilledCellF = -1
  312.                                 spaceTailF = -1
  313.                                 tailScore = tailScore + (d > 1) * -1 + (d > 3) * -1 + (d > 6) * -.5
  314.                             ELSE
  315.                                 GOTO skip
  316.                             END IF
  317.                         NEXT
  318.                         IF headScore + tailScore > bestScore AND (spaceHeadF OR spaceTailF) THEN 'make sure placing word over at least one empty spot
  319.                             Words(WS.PlaceWordIndex).X = x: Words(WS.PlaceWordIndex).Y = y: Words(WS.PlaceWordIndex).D = d
  320.                             bestScore = headScore + tailScore 'local
  321.                         END IF
  322.                     END IF
  323.                     skip:
  324.                 NEXT
  325.             END IF
  326.         NEXT
  327.     NEXT
  328.     'BEEP
  329.     IF bestScore > -1 THEN 'we have a good place for this word put it there and update stuff
  330.         FOR i = 1 TO Words(WS.PlaceWordIndex).Len
  331.             AscLetters(DX(Words(WS.PlaceWordIndex).D) * (i - 1) + Words(WS.PlaceWordIndex).X,_
  332.              DY(Words(WS.PlaceWordIndex).D) * (i - 1) + Words(WS.PlaceWordIndex).Y) = ascWord(WS.PlaceWordIndex, i)
  333.         NEXT
  334.         Words(WS.PlaceWordIndex).Placed = -1
  335.         WS.NumPlacedWords = WS.NumPlacedWords + 1
  336.     ELSE
  337.         Words(WS.PlaceWordIndex).Placed = 0
  338.         WS.NumUnplacedWords = WS.NumUnplacedWords + 1
  339.     END IF
  340.  
  341. SUB ShowBestPuzzle
  342.     REDIM mMod, m, i, j, x, y, DirectionTotals(0 TO 7), s$(1 TO 4)
  343.  
  344.     mMod = LEN(WS.Filler) '     FillBlanksInBest
  345.     FOR y = 0 TO WS.GridSide - 1
  346.         FOR x = 0 TO WS.GridSide - 1
  347.             IF AscBestLetters(x, y) = 32 THEN
  348.                 AscBestLetters(x, y) = ASC(WS.Filler, m + 1)
  349.                 m = (m + 1) MOD mMod
  350.             END IF
  351.         NEXT
  352.     NEXT
  353.  
  354.     CLS '                                redraw screen
  355.     LOCATE 1, 1: PRINT WS.GridLabel$
  356.     FOR i = 3 TO 2 + WS.GridSide
  357.         LOCATE i, 1: PRINT MID$(WS.GridLabel$, i * 2 - 2, 1);
  358.     NEXT
  359.     FOR y = 0 TO WS.GridSide - 1
  360.         FOR x = 0 TO WS.GridSide - 1
  361.             LOCATE y + 3, 2 * x + 4: PRINT CHR$(AscBestLetters(x, y))
  362.         NEXT
  363.     NEXT
  364.  
  365.     FOR i = 1 TO WS.NumWords
  366.         IF BestWords(i).Placed THEN
  367.             j = j + 1
  368.             IF j <= 40 THEN
  369.                 LOCATE j, 65: PRINT TS$(j); " "; BestWords(i).S;
  370.             ELSEIF j <= 80 THEN
  371.                 LOCATE j - 40, 85: PRINT TS$(j); " "; BestWords(i).S;
  372.             ELSEIF j <= 120 THEN
  373.                 LOCATE j - 80, 105: PRINT TS$(j); " "; BestWords(i).S
  374.             END IF
  375.             DirectionTotals(BestWords(i).D) = DirectionTotals(BestWords(i).D) + 1
  376.         END IF
  377.     NEXT
  378.     s$(1) = " Total Norths: " + TS$(DirectionTotals(3)) + ", Total Souths: " + TS$(DirectionTotals(1))
  379.     s$(2) = " Total Easts: " + TS$(DirectionTotals(0)) + ", Total Wests: " + TS$(DirectionTotals(2))
  380.     s$(3) = " Total NWs: " + TS$(DirectionTotals(5)) + ", Total SWs: " + TS$(DirectionTotals(4))
  381.     s$(4) = " Total NEs: " + TS$(DirectionTotals(7)) + ", Total SEs: " + TS$(DirectionTotals(6))
  382.     FOR i = 1 TO 4
  383.         LOCATE 32 + i, 1: PRINT s$(i);
  384.     NEXT
  385.  
  386. SUB FilePuzzle
  387.     REDIM i, j, r, c, b$, x$, y$, d$, s$(1 TO 4)
  388.  
  389.     OPEN WS.FileTheme + " Word Search Puzzle.txt" FOR OUTPUT AS #1
  390.     PRINT #1, WS.GridLabel$
  391.     PRINT #1, ""
  392.     FOR r = 0 TO WS.GridSideM1
  393.         b$ = MID$(WS.GridLabel$, r * 2 + 4, 1) + "  "
  394.         FOR c = 0 TO WS.GridSideM1
  395.             b$ = b$ + CHR$(AscBestLetters(c, r)) + " "
  396.         NEXT
  397.         PRINT #1, b$
  398.     NEXT
  399.     CLOSE #1
  400.  
  401.     OPEN WS.FileTheme + " Word Search Solutions.txt" FOR OUTPUT AS #1
  402.     PRINT #1, ""
  403.     PRINT #1, " Search Word Solutions:"
  404.     PRINT #1, "            Words from: " + WS.FileTheme + " Word List.txt"
  405.     PRINT #1, ""
  406.     PRINT #1, " First Letter Location and Direction:"
  407.     PRINT #1, ""
  408.     FOR i = 1 TO WS.NumWords
  409.         IF BestWords(i).Placed THEN
  410.             j = j + 1
  411.             ConvertCR2Nav BestWords(i).X, BestWords(i).Y, BestWords(i).D, x$, y$, d$
  412.             PRINT #1, RIGHT$("    " + TS$(j), 4) + ") " + RIGHT$(SPC(15) + BestWords(i).S, 15) + " (" + x$ + ", " + y$ + ") >>>---> " + d$
  413.         END IF
  414.     NEXT
  415.     PRINT #1, " "
  416.     s$(1) = " Total Norths: " + TS$(DirectionTotals(3)) + ", Total Souths: " + TS$(DirectionTotals(1))
  417.     s$(2) = " Total Easts: " + TS$(DirectionTotals(0)) + ", Total Wests: " + TS$(DirectionTotals(2))
  418.     s$(3) = " Total NWs: " + TS$(DirectionTotals(5)) + ", Total SWs: " + TS$(DirectionTotals(4))
  419.     s$(4) = " Total NEs: " + TS$(DirectionTotals(7)) + ", Total SEs: " + TS$(DirectionTotals(6))
  420.     FOR i = 1 TO 4
  421.         PRINT #1, s$(i)
  422.     NEXT
  423.     PRINT #1, " "
  424.     PRINT #1, " Message in unused letters: " + WS.Filler
  425.     CLOSE #1
  426.  
  427. FUNCTION Found (word$, headX, headY, direction)
  428.     'First find a letter that matches the first letter in word$,
  429.     'then at that x, y try each of 8 directions to see if find a match.
  430.     'See if enough room to fit the find word before heading out to match letters.
  431.  
  432.     DIM first$, lenFind, x, y, d, b1, b2, xx, yy, b$, i
  433.  
  434.     first$ = MID$(word$, 1, 1): lenFind = LEN(word$) - 1
  435.     FOR y = 0 TO WS.GridSideM1
  436.         FOR x = 0 TO WS.GridSideM1
  437.             IF AscBestLetters(x, y) = ASC(first$) THEN
  438.                 FOR d = 0 TO 7 'will word fit in this direction? 2 booleans True condition
  439.                     b1 = lenFind * DX(d) + x >= 0 AND lenFind * DX(d) + x <= WS.GridSideM1
  440.                     b2 = lenFind * DY(d) + y >= 0 AND lenFind * DY(d) + y <= WS.GridSideM1
  441.                     IF b1 AND b2 THEN 'word fits,
  442.                         ' build word from Letters block to see if matches word to find
  443.                         b$ = first$: xx = x + DX(d): yy = y + DY(d)
  444.                         FOR i = 2 TO LEN(word$)
  445.                             b$ = b$ + CHR$(AscBestLetters(xx, yy))
  446.                             xx = xx + DX(d): yy = yy + DY(d)
  447.                         NEXT
  448.                         xx = x: yy = y 'copy x, y for rebuilding word on screen
  449.                         IF b$ = word$ THEN 'found one show our result
  450.                             headX = x: headY = y: direction = d: Found = -1
  451.                             EXIT SUB
  452.                         END IF
  453.                     END IF
  454.                 NEXT
  455.             END IF
  456.         NEXT
  457.     NEXT
  458.  
  459. SUB ConvertCR2Screen (c, r, screenC, screenR)
  460.     screenC = 2 * c + 4: screenR = r + 3
  461.  
  462. SUB ConvertCR2Nav (c, r, d, navX$, navY$, navD$)
  463.     IF c > 9 THEN navX$ = CHR$(c - 9 + AscA - 1) ELSE navX$ = TS$(c)
  464.     IF r > 9 THEN navY$ = CHR$(r - 9 + AscA - 1) ELSE navY$ = TS$(r)
  465.     navD$ = DString$(d)
  466.  
  467. SUB Sort (arr() AS WordType)
  468.     DIM i, j
  469.     FOR i = 1 TO WS.NumWords - 1
  470.         FOR j = i + 1 TO WS.NumWords
  471.             IF arr(j).S < arr(i).S THEN SWAP arr(j), arr(i)
  472.         NEXT
  473.     NEXT
  474.  
  475. FUNCTION TS$ (n) ' this shorthand for TrimString and I want it shorthand!
  476.     TS$ = _TRIM$(STR$(n))
  477.  
  478.  


Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #19 on: December 08, 2020, 11:26:42 pm »
Cool pine trees B+! Good job!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #20 on: December 09, 2020, 02:13:47 am »
Here is my Christmas Tree ornament. It's not as fancy as B+'s, but I thought I would throw this in tonight. Feel free to use any of the code for your own. Below is a picture. The program itself changes the colors of the parallel circles (ovals).

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. _TITLE "SierraKen's Christmas Tree Ornament - Press Esc to quit."
  3. c3 = 255
  4. FOR cir = .01 TO 130 STEP .1
  5.     c3 = c3 - .1
  6.     CIRCLE (400, 300), cir, _RGB32(0, 0, c3)
  7. NEXT cir
  8.     _LIMIT 30
  9.     yy = 300
  10.     c4 = INT(RND * 155) + 100
  11.     c5 = INT(RND * 155) + 100
  12.     c6 = INT(RND * 155) + 100
  13.     CIRCLE (400, yy), 130, _RGB32(c4, c5, c6), , , .5
  14.     yy = yy - 22.5
  15.     CIRCLE (400, yy), 125, _RGB32(c4, c5, c6), , , .5
  16.     yy = yy - 22.5
  17.     CIRCLE (400, yy), 120, _RGB32(c4, c5, c6), , , .5
  18.     yy = yy - 22.5
  19.     CIRCLE (400, yy), 105, _RGB32(c4, c5, c6), , , .5
  20.     yy = yy - 22.5
  21.     CIRCLE (400, yy), 75, _RGB32(c4, c5, c6), , , .5
  22.     yy = yy - 22.5
  23.     CIRCLE (400, yy), 15, _RGB32(c4, c5, c6), , , .5
  24.     yy = 300
  25.     yy = yy + 22.5
  26.     CIRCLE (400, yy), 125, _RGB32(c4, c5, c6), , , .5
  27.     yy = yy + 22.5
  28.     CIRCLE (400, yy), 120, _RGB32(c4, c5, c6), , , .5
  29.     yy = yy + 22.5
  30.     CIRCLE (400, yy), 105, _RGB32(c4, c5, c6), , , .5
  31.     yy = yy + 22.5
  32.     CIRCLE (400, yy), 75, _RGB32(c4, c5, c6), , , .5
  33.     yy = yy + 22.5
  34.     CIRCLE (400, yy), 15, _RGB32(c4, c5, c6), , , .5
  35.     _DELAY .5
  36.  

SierraKen's Christmas Tree Ornament.jpg
* SierraKen's Christmas Tree Ornament.jpg (Filesize: 70.94 KB, Dimensions: 805x625, Views: 242)
« Last Edit: December 09, 2020, 02:17:06 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #21 on: December 09, 2020, 01:02:58 pm »
Thanks Ken, only one gasp in awe ;-))

Ken I just noticed your ornament, I can't tell which side is toward me top or bottom? When I look at top then that side, when I look at bottom, that side, I love it and with different lights too.

I wonder if we could make it flip: It goes from light to dark, dark to light then flips...
You'd draw half circles one way (except at top you can see whole cicle and at bottom no circle, then the other half circles the other way.

Well on 2nd thought, it's harder than that because it's more or less than half circles.
Maybe _vince or STx can figure it out, Ashish can probably draw it wobbling like the Earth in it's orbits with GL stuff.

« Last Edit: December 09, 2020, 02:40:59 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #22 on: December 09, 2020, 02:44:07 pm »
Bplus,

Possible answer for "which side".

As you know, all surface points are equidistant from its centre. So technically, a sphere, has no "sides". Unless it is hollow... Inside and outside...

To answer your query, 'which side is toward me', for want of a better word, the 'outside' is toward you....

But, you have to admit, it's a very nice blue.
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #23 on: December 09, 2020, 02:55:58 pm »
Thanks guys :). Yeah the only way to explain it would be that it's blue glass and you can see right through it. I also thought about half-circles but I came to the same conclusion, it wouldn't look right for all of them, unless I figured out the right shape on each of them... dang now I want to see if I can do it..... :)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #24 on: December 09, 2020, 03:09:48 pm »
I have also something in progress... i think this is done by 7 days or so... :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #25 on: December 09, 2020, 04:19:15 pm »
Here we go. I did all the lines manually by trial and error and I added a glowing blue the pulsates. Now you can't see the other side and you can only see from about a 45 degree angle from the bottom (or 315 degrees if you want to be technical :)). This is a better Christmas Tree ornament than my last one.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. _TITLE "SierraKen's Christmas Tree Ornament - Press Esc to quit."
  3. t = 1
  4.     _LIMIT 60
  5.     IF col > 100 THEN t = 0
  6.     IF col < 50 THEN t = 1
  7.     IF t = 0 THEN col = col - 25
  8.     IF t = 1 THEN col = col + 25
  9.     c3 = 255
  10.     FOR cir = .01 TO 130 STEP .1
  11.         c3 = c3 - .1
  12.         CIRCLE (400, 300), cir, _RGB32(0, 0, c3 - col)
  13.     NEXT cir
  14.     yy = 300
  15.     c4 = INT(RND * 155) + 100
  16.     c5 = INT(RND * 155) + 100
  17.     c6 = INT(RND * 155) + 100
  18.     CIRCLE (400, yy), 130, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  19.     yy = yy - 40.5
  20.     CIRCLE (400, yy), 124, _RGB32(c4, c5, c6), 2 * _PI, _PI, .4
  21.     yy = yy - 30.5
  22.     CIRCLE (400, yy), 105, _RGB32(c4, c5, c6), 2 * _PI, _PI, .39
  23.     yy = 300
  24.     yy = yy + 22.5
  25.     CIRCLE (400, yy), 130, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  26.     yy = yy + 22.5
  27.     CIRCLE (400, yy), 125, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  28.     yy = yy + 22.5
  29.     CIRCLE (400, yy), 110, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  30.     yy = yy + 22.5
  31.     CIRCLE (400, yy), 75, _RGB32(c4, c5, c6), , , .5
  32.     yy = yy + 22.5
  33.     CIRCLE (400, yy), 15, _RGB32(c4, c5, c6), , , .5
  34.     _DELAY .25
  35.     _DISPLAY
  36.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #26 on: December 09, 2020, 05:22:27 pm »
@SierraKen NICE! you did the hard work, now you can take snapshots at different light levels and play a round upside down and the next right side up AND/OR grab our old favorite RotoZoom and do...

oh heck! then you can do any size and at any place!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #27 on: December 09, 2020, 08:25:53 pm »
Thanks B+. But from what I know, I couldn't copy it to other places without having a lot of black erase parts of them because the _COPYIMAGE (0) and ROTOZOOM turns the entire screen and not a part of it that I know of. I tried using the old GET command without luck. But I was able to make this one that just snaps a photo of it and then goes in a ROTOZOOM loop with it turning non-stop. :) It doesn't change colors but it looks really cool! Notice I put the ornament in its own SUB. :) It does have a random color on the lines though for each time you run the program. I like this one even more than the others. :) 

Code: QB64: [Select]
  1. _TITLE "SierraKen's Christmas Tree Ornament - Press Esc to quit."
  2. DIM x AS LONG, y AS LONG, Image AS LONG, Scale AS SINGLE, Rotation AS SINGLE
  3. DIM orn AS LONG
  4. t = 1
  5. i& = _NEWIMAGE(800, 600, 32)
  6. ornament
  7. orn = _COPYIMAGE(0)
  8.     _LIMIT 60
  9.     RotoZoom 400, 300, orn&, 1, turn 'Angle
  10.     _DELAY .01
  11.     _DISPLAY
  12.     CLS
  13.     turn = turn + 1
  14.  
  15. SUB ornament
  16.     c3 = 255
  17.     FOR cir = .01 TO 130 STEP .1
  18.         c3 = c3 - .1
  19.         CIRCLE (400, 300), cir, _RGB32(0, 0, c3)
  20.     NEXT cir
  21.     yy = 300
  22.     c4 = INT(RND * 155) + 100
  23.     c5 = INT(RND * 155) + 100
  24.     c6 = INT(RND * 155) + 100
  25.     CIRCLE (400, yy), 130, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  26.     yy = yy - 40.5
  27.     CIRCLE (400, yy), 124, _RGB32(c4, c5, c6), 2 * _PI, _PI, .4
  28.     yy = yy - 30.5
  29.     CIRCLE (400, yy), 105, _RGB32(c4, c5, c6), 2 * _PI, _PI, .39
  30.     yy = 300
  31.     yy = yy + 22.5
  32.     CIRCLE (400, yy), 130, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  33.     yy = yy + 22.5
  34.     CIRCLE (400, yy), 125, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  35.     yy = yy + 22.5
  36.     CIRCLE (400, yy), 110, _RGB32(c4, c5, c6), 2 * _PI, _PI, .5
  37.     yy = yy + 22.5
  38.     CIRCLE (400, yy), 75, _RGB32(c4, c5, c6), , , .5
  39.     yy = yy + 22.5
  40.     CIRCLE (400, yy), 15, _RGB32(c4, c5, c6), , , .5
  41.  
  42.  
  43.  
  44. SUB RotoZoom (X AS LONG, Y AS LONG, Image AS LONG, Scale AS SINGLE, Rotation AS SINGLE)
  45.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  46.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  47.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  48.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  49.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  50.     FOR i& = 0 TO 3
  51.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  52.         px(i&) = x2&: py(i&) = y2&
  53.     NEXT
  54.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  55.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  56.  
  57.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #28 on: December 09, 2020, 08:41:35 pm »
@SierraKen  Dang that's NICER! Rotating it, makes it more 3D IMHO.

With _PUTIMAGE, you can put snapshot anywhere you want, any size you want.

Making an ornament sub is really good then you can give ornament a center(x, y) coodinate and it will draw there instead of the center of the screen, same with color, same with radius (but the stuff you did by hand has to be in relation to the center of the screen = center (x, y) of ornament. Let me know if your head is starting to ache ;-))


Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: 🎄🎁✨ Holiday Season - are you ready to code?
« Reply #29 on: December 09, 2020, 10:48:51 pm »
LOL thanks B+, but I think that's all my brain can take for now. I might look into this more soon. :) I do agree that it looks more 3D :).