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

0 Members and 1 Guest are viewing this topic.

#### Junior Librarian

• Moderator
• Newbie
• Posts: 19
##### 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
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.         IF n = 3 THEN ' default bottom left - top right
39.             IF (l = 3) OR (l = 7) THEN ' can't change direction if the
40.                 n = l ' last piece was also a 3
41.                 FOR zi = 0 TO 3
42.                     w(zi) = 0
43.                 NEXT zi
44.                 FOR y2 = 0 TO 7
45.                     FOR x2 = 0 TO 7
46.                         xi = x2 \ 4 ' 0 or 1
47.                         yi = y2 \ 4 ' 0 or 1
48.                         zi = xi * 2 + yi ' 0-3
49.                         ' LOCATE zi + 1, 1: PRINT zi;
50.                         w(zi) = w(zi) + pixel(x2, y2)
51.                     NEXT x2
52.                 NEXT y2
53.                 IF (w(1) + w(2)) > (w(0) + w(3)) THEN n = 7
54.         l = n ' save last used (for 3)
55.         d = dots(n)
56.         c1(n) = c1(n) + 1
57.         FOR dot = 1 TO d
58.             tx = (x1 + 4) + x(n, dot) * 2 - xb
59.             ty = (y1 + 4) + y(n, dot) * 2 - yb
60.             PSET (tx, ty), 15
61.         NEXT dot
62.         IF INKEY\$ = CHR\$(27) THEN CLOSE: SCREEN 0, 0, 0, 0: END
63.         nd = nd + 1
64.     NEXT x1
65.     GOSUB Status
66. NEXT y1
67.
68. Status:
69. FOR i = 0 TO 7
70.     'COLOR i
71.     LOCATE i + 2, 49: PRINT USING "####"; i; c1(i);
72. RESTORE count
73. FOR i = 1 TO 28
74.     LOCATE i + 1, 60: PRINT " ";
75.     LOCATE i + 1, 60
76.     IF c2(i) >= max THEN
77.         max = c2(i)
78.         PRINT "*";
79.         PRINT " ";
80.     PRINT y\$(i);
81.     PRINT USING " #### "; c2(i);
82.     c! = c2(i) * cps!
83.     c! = c! + c! * .07
84.     PRINT USING "####.##"; c!;
85. xn = (xe - xb) / 16
86. yn = (ye - yb) / 8
87. LOCATE 27, 52: PRINT xn;
88. LOCATE 28, 52: PRINT yn;
89. LOCATE 29, 52: PRINT xn * yn;
90.
91. count:
92. DATA 00,01,02,03,04,05,06
93. DATA 11,12,13,14,15,16
94. DATA 22,23,24,25,26
95. DATA 33,34,35,36
96. DATA 44,45,46
97. DATA 55,56
98. DATA 66
99.
100. dots:
101. DATA 1,0,0
102. DATA 2,0,-1,0,1
103. DATA 3,-1,-1,0,0,1,1
104. DATA 4,-1,1,-1,-1,1,-1,1,1
105. DATA 5,-1,1,-1,-1,1,-1,1,1,0,0
106. DATA 6,-1,1,-1,0,-1,-1,1,1,1,0,1,-1
107. DATA 3,1,-1,0,0,-1,1
108.

Attachments:
Requires HEATH.BMP