Author Topic: A Simple Graphics To Text Converter  (Read 4484 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #15 on: July 12, 2020, 07:21:05 pm »
Quote
One thing I did notice that was strange... Scanning with point(), on the grey-scaled image, then using "color yahda", produces an almost sepia colour. Not a deal breaker. Just an observation. If I can get a colour image to happen then this won't be a problem.

Try this:
Code: QB64: [Select]
  1. DIM pixel(100, 120) AS _UNSIGNED LONG
The best Type to use with color is _UNSIGNED LONG.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #16 on: July 12, 2020, 08:12:43 pm »
Great B+, it has gray scale now. I added it to my own version of Johnno's version. I also fixed a duplication problem it had from my other one, that showed the picture again a little bit on top. Plus I added the ASCII character number in the _TITLE and slowed it down to change once a second.

Code: QB64: [Select]
  1. 'Made by SierraKen and Johnno56
  2.  
  3. SCREEN _NEWIMAGE(800, 960, 32)
  4. _LIMIT 100
  5. '---------------------------------------------------
  6. 'Draw anything you want here with graphic commands.
  7. 'Here are some boxes.
  8.  
  9. spock& = _LOADIMAGE("spock100x120.png")
  10. _PUTIMAGE (0, 0), spock&
  11. _DELAY 1 '   short delay to view image source
  12. '---------------------------------------------------
  13. DIM pixel(100, 120) AS _UNSIGNED LONG '<<<< Added AS _UNSIGNED LONG to make gray scale. Thanks B+!
  14.  
  15. '   Selected a small font to remove vertical "stretching"
  16.  
  17. '   Separate loops for 'reading' and 'writing' - could be combined?
  18.  
  19. FOR y = 0 TO 119
  20.     FOR x = 0 TO 99
  21.         pixel(x, y) = POINT(x, y)
  22.     NEXT x
  23.  
  24.     _LIMIT 100
  25.     cc = INT(RND * 2) + 1
  26.     IF cc = 1 THEN ch = INT(RND * 93) + 33
  27.     IF cc = 2 THEN ch = INT(RND * 126) + 128
  28.     ch$ = STR$(ch): _TITLE "ASCII: " + ch$
  29.     FOR y = 0 TO 119
  30.         FOR x = 0 TO 99
  31.             COLOR pixel(x, y)
  32.             letter$ = CHR$(ch)
  33.             PRINT letter$;
  34.         NEXT
  35.         PRINT ""
  36.     NEXT
  37.     _DELAY 1
  38.     _DISPLAY
  39.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #17 on: July 12, 2020, 10:19:07 pm »
... adding the "_unsigned long" has also corrected the colour version as well ...

Change ch to 219... just a suggestion... ;)
« Last Edit: July 12, 2020, 10:22:52 pm by johnno56 »
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #18 on: July 12, 2020, 10:26:35 pm »
Johno, I still don't understand your code completely. I haven't used those kinds of arrays that much. How did you get it to only display black and white? To me, logic would assume that it would show color already. But it doesn't.

Edit: Duh me, I just remembered that it scans a black and white picture first. LOL
« Last Edit: July 12, 2020, 10:30:59 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #19 on: July 12, 2020, 11:42:07 pm »
Here is 3 Avatarios:

bot sample:
Code: QB64: [Select]
  1. 'Made by bplus 2020-07-12
  2.  
  3. SCREEN _NEWIMAGE(560, 328, 32)
  4. _DELAY .25
  5. t& = _LOADIMAGE("Avatar.PNG")
  6. b& = _NEWIMAGE(_WIDTH(t&), _HEIGHT(t&), 32)
  7. _PUTIMAGE , t&, b&
  8. FOR y = 1 TO _HEIGHT(t&) - 3
  9.     FOR x = 1 TO _WIDTH(t&) - 1
  10.         COLOR , POINT(x, y)
  11.         PRINT " ";
  12.     NEXT
  13.     PRINT

Ken looks like he is drinking from a glass of light!
* Avatarios.zip (Filesize: 32.32 KB, Downloads: 159)
« Last Edit: July 12, 2020, 11:49:41 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #20 on: July 13, 2020, 12:31:28 am »
LOL That is pretty fun to use! I replaced " " with "." and it looks like the movie Tron. Or I replaced it with "-" and it looks like I'm looking through a screen. :) Awesome.

Edit: Or even a better screen, CHR$(216)  LOL.
« Last Edit: July 13, 2020, 12:34:30 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #21 on: July 13, 2020, 12:38:52 am »
Well yeah of course I tried this:
 
Avatar +.PNG


And I liked this but it's using circles:
 
avatar circle mod.PNG

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #22 on: July 13, 2020, 12:53:13 am »
Dang I can't quit :-))
 
avatar mod b+.PNG

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #23 on: July 13, 2020, 12:53:25 am »
Or upside down...

Code: QB64: [Select]
  1. 'Made by bplus 2020-07-12
  2. 'Mod by SierraKen
  3.  
  4. SCREEN _NEWIMAGE(576, 424, 32)
  5. _DELAY .25
  6. t& = _LOADIMAGE("Ken.PNG")
  7. b& = _NEWIMAGE(_WIDTH(t&), _HEIGHT(t&), 32)
  8. _PUTIMAGE , t&, b&
  9. FOR y = _HEIGHT(t&) - 3 TO 0 STEP -1
  10.     FOR x = _WIDTH(t&) - 1 TO 0 STEP -1
  11.         COLOR , POINT(x, y)
  12.         PRINT " ";
  13.     NEXT
  14.     PRINT
  15.  
« Last Edit: July 13, 2020, 01:27:00 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #24 on: July 13, 2020, 12:57:12 am »
I got the upside down one on accident, goofing around with the numbers. lol

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #25 on: July 13, 2020, 01:03:17 am »
Well see it was a glass of light otherwise you'd be soaking wet!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #26 on: July 13, 2020, 01:26:29 am »
LOL! Yep... Very bad TV reception Mod...

Code: QB64: [Select]
  1. 'Made by bplus 2020-07-12
  2. 'mod by SierraKen
  3.  
  4. SCREEN _NEWIMAGE(576, 424, 32)
  5. _DELAY .25
  6. t& = _LOADIMAGE("Ken.PNG")
  7. b& = _NEWIMAGE(_WIDTH(t&), _HEIGHT(t&), 32)
  8. _PUTIMAGE , t&, b&
  9.     FOR t = 1 TO 10 STEP .25
  10.         FOR y = 0 TO _HEIGHT(t&) - 3 STEP t
  11.             FOR x = 1 TO _WIDTH(t&) - 1
  12.                 COLOR , POINT(x, y)
  13.                 PRINT " ";
  14.             NEXT
  15.             PRINT
  16.         NEXT
  17.         _DELAY .05
  18.     NEXT t
  19.     FOR t = 10 TO 1 STEP -.25
  20.         FOR y = 0 TO _HEIGHT(t&) - 3 STEP t
  21.             FOR x = 1 TO _WIDTH(t&) - 1
  22.                 COLOR , POINT(x, y)
  23.                 PRINT " ";
  24.             NEXT
  25.             PRINT
  26.         NEXT
  27.         _DELAY .05
  28.     NEXT t
  29.     _DELAY .25
  30.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #27 on: July 13, 2020, 01:30:25 am »
SierraKen,

The greyscale image was created by desaturating the colour image with Gimp. I looked up a greyscale algorithm (which reduces the 'red' channel to 21%, green to 72% and blue to 7%) but all it did was produce a greenish image. Spock looked more like a Martian than a Vulcan.... lol  I was spending to much time on this so I opted for the Gimp procedure... Lazy or what? (Rhetorical. Answer not required. lol)

To be able to reproduce the colour of each pixel, the pixel(x,y) array, was used to store the point(x,y) values.

QB64 Help: Point
The POINT function returns the pixel COLOR attribute at a specified graphics coordinate or the current graphic cursor position.
color_attribute% = POINT (column%, row%)
In our case: pixel(x,y) = point(x,y)

Of course, the larger the source image, the greater the size of the array's dimensions.

Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Graphics To Text Converter
« Reply #28 on: July 13, 2020, 02:09:25 pm »
Thanks Johnno, I understand it now. It was just hard to visualize 3 different items in 1 single array. But I'll get used to it someday. :)