Author Topic: Convert a BMP to dominos  (Read 4364 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Convert a BMP to dominos
« on: January 31, 2019, 11:28:18 pm »
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.  
  115.  
HEATH.BMP
* HEATH.BMP (Filesize: 301.05 KB, Dimensions: 640x480, Views: 450)
« Last Edit: February 01, 2019, 02:11:50 am by Richard Frost »
It works better if you plug it in.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Convert a BMP to dominos
« Reply #1 on: February 01, 2019, 12:00:51 am »
Hey Richard, welcome to forum!
domino heather.PNG
* domino heather.PNG (Filesize: 19.04 KB, Dimensions: 645x510, Views: 416)

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Convert a BMP to dominos
« Reply #2 on: February 01, 2019, 08:55:16 am »
This is a really cool utility Richard - thanks for posting!

Say, this example is so cute and to-the-point (no pun), I think it's a great candidate for our Samples section. If you say the code is 100% done then just say the word. We'll move it there when you're ready!
« Last Edit: February 01, 2019, 09:23:45 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Convert a BMP to dominos
« Reply #3 on: February 01, 2019, 04:26:25 pm »
No program is ever "done", IMO.  One should review/modify code on a regular basis as one learns more,
or thinks up neat new features to add.    I've forgotten what all the numbers are, but the one of the columns
is for estimating the cost to build it for real - how many box sets at some price....

Few BMPs I had on hand at the time worked out quite as nice as Heather Thomas.  You can't plug in a
different file and expect it to work.  It'd be way better if it could do that.  Also, I neglected to mention the source
of the idea.  It's from seeing a picture of Martin Gardner (Scientific American) with a domino pix in the
background. 

I's gotta ploglam to convert the same picture to best ASCII too, which I may upload.  I's gittin' worried I'll be
banned from the site for sending too much!
It works better if you plug it in.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Convert a BMP to dominos
« Reply #4 on: February 06, 2019, 11:26:05 am »
I think it's a great candidate for our Samples section.

Certainly a worthy entry, nice work R. Frost