Author Topic: Convert BMP to Dominoes by Richard Frost  (Read 6736 times)

0 Members and 1 Guest are viewing this topic.

Offline Junior Librarian

  • Moderator
  • Newbie
  • Posts: 19
    • View Profile
Convert BMP to Dominoes by Richard Frost
« on: September 25, 2021, 05:46:49 am »
Convert BMP to Dominoes

Author: @Richard Frost
Source: qb64.org Forum
URL: https://www.qb64.org/forum/index.php?topic=1023.0
Version: 2019

Description:
[This] is an image converter that takes a picture a small block at a time and finds the "best fit" domino for that space. (The woman is Heather Thomas.)

Source Code:
Code: QB64: [Select]
  1. ' The woman is Heather Thomas
  2.  
  3. DEFINT A-Z
  4. DIM dots(7), x(7, 7), y(7, 7), c1(7), c2(28), pixel(7, 7), w(3), y$(30)
  5. cps! = 12.83 ' cost per set
  6. FOR i = 1 TO 28: READ y$(i): NEXT i
  7. FOR n = 1 TO 7
  8.     READ dots(n)
  9.     FOR dot = 1 TO dots(n)
  10.         READ x(n, dot), y(n, dot)
  11.     NEXT dot
  12. xb = 10: xe = 350 ' x begin and end
  13. yb = 0: ye = 470 ' y begin and end
  14. OPEN "heath.bmp" FOR RANDOM AS #1 LEN = 1: FIELD #1, 1 AS t$
  15. FOR y1 = yb TO ye STEP 8
  16.     FOR x1 = xb TO xe STEP 8
  17.         n = 0
  18.         FOR y2 = 0 TO 7
  19.             FOR x2 = 0 TO 7
  20.                 x3 = x1 + x2
  21.                 y3 = y1 + y2
  22.                 r& = CDBL(479 - y3) * 640 + x3 + 441
  23.                 GET #1, r&
  24.                 d = ASC(t$) \ 13
  25.                 IF d > 15 THEN d = 15
  26.                 pixel(x2, y2) = -(d > 7) ' for 3 problem
  27.                 n = n + d
  28.             NEXT x2
  29.         NEXT y2
  30.         n = n / 155 ' 175
  31.         IF n > 6 THEN n = 6
  32.         x$ = x$ + CHR$(48 + n) ' for counting tiles used
  33.         IF LEN(x$) = 2 THEN ' got left & right
  34.             FOR i = 1 TO 28
  35.                 IF x$ = y$(i) THEN c2(i) = c2(i) + 1: EXIT FOR
  36.             NEXT i
  37.             x$ = ""
  38.         END IF
  39.         IF n = 3 THEN ' default bottom left - top right
  40.             IF (l = 3) OR (l = 7) THEN ' can't change direction if the
  41.                 n = l ' last piece was also a 3
  42.             ELSE
  43.                 FOR zi = 0 TO 3
  44.                     w(zi) = 0
  45.                 NEXT zi
  46.                 FOR y2 = 0 TO 7
  47.                     FOR x2 = 0 TO 7
  48.                         xi = x2 \ 4 ' 0 or 1
  49.                         yi = y2 \ 4 ' 0 or 1
  50.                         zi = xi * 2 + yi ' 0-3
  51.                         ' LOCATE zi + 1, 1: PRINT zi;
  52.                         w(zi) = w(zi) + pixel(x2, y2)
  53.                     NEXT x2
  54.                 NEXT y2
  55.                 IF (w(1) + w(2)) > (w(0) + w(3)) THEN n = 7
  56.             END IF
  57.         END IF
  58.         l = n ' save last used (for 3)
  59.         d = dots(n)
  60.         c1(n) = c1(n) + 1
  61.         FOR dot = 1 TO d
  62.             tx = (x1 + 4) + x(n, dot) * 2 - xb
  63.             ty = (y1 + 4) + y(n, dot) * 2 - yb
  64.             PSET (tx, ty), 15
  65.         NEXT dot
  66.         IF INKEY$ = CHR$(27) THEN CLOSE: SCREEN 0, 0, 0, 0: END
  67.         nd = nd + 1
  68.     NEXT x1
  69.     GOSUB Status
  70. NEXT y1
  71.  
  72. Status:
  73. FOR i = 0 TO 7
  74.     'COLOR i
  75.     LOCATE i + 2, 49: PRINT USING "####"; i; c1(i);
  76. RESTORE count
  77. FOR i = 1 TO 28
  78.     LOCATE i + 1, 60: PRINT " ";
  79.     LOCATE i + 1, 60
  80.     IF c2(i) >= max THEN
  81.         max = c2(i)
  82.         PRINT "*";
  83.     ELSE
  84.         PRINT " ";
  85.     END IF
  86.     PRINT y$(i);
  87.     PRINT USING " #### "; c2(i);
  88.     c! = c2(i) * cps!
  89.     c! = c! + c! * .07
  90.     PRINT USING "####.##"; c!;
  91. xn = (xe - xb) / 16
  92. yn = (ye - yb) / 8
  93. LOCATE 27, 52: PRINT xn;
  94. LOCATE 28, 52: PRINT yn;
  95. LOCATE 29, 52: PRINT xn * yn;
  96.  
  97. count:
  98. DATA 00,01,02,03,04,05,06
  99. DATA 11,12,13,14,15,16
  100. DATA 22,23,24,25,26
  101. DATA 33,34,35,36
  102. DATA 44,45,46
  103. DATA 55,56
  104. DATA 66
  105.  
  106. dots:
  107. DATA 1,0,0
  108. DATA 2,0,-1,0,1
  109. DATA 3,-1,-1,0,0,1,1
  110. DATA 4,-1,1,-1,-1,1,-1,1,1
  111. DATA 5,-1,1,-1,-1,1,-1,1,1,0,0
  112. DATA 6,-1,1,-1,0,-1,-1,1,1,1,0,1,-1
  113. DATA 3,1,-1,0,0,-1,1
  114.  

Attachments:
Requires HEATH.BMP

 
                                                                                                                                         (219 downloads previously)
 
HEATH.BMP


BMP2Dominoes.png
« Last Edit: September 25, 2021, 05:56:04 am by Junior Librarian »