Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Capture From Screen To ASCII Art


  • Please log in to reply
34 replies to this topic
tinypig
  • Members
  • 16 posts
  • Last active: Aug 29 2014 12:36 AM
  • Joined: 12 Mar 2005
Position mouse in upper-left corner of image to be copied and press ctrl-alt-b (for "begin"). Then position mouse in the lower-right corner of the image to be copied and press ctrl-alt-e (end). Wait for message saying it is complete. The bigger the image, the longer it will take. Go to Notepad and make sure you are using a fixed-width font (as a suggestion, go to Format->Font, select Terminal font, Regular style, and the smallest size you can). Then paste from the clipboard.

It's a fun toy, but I eventually want to use it to locate stuff. Let me know what you think. Refactoring/criticism/comments welcome.

Note: Using the font I suggest here (on my machine at least), the colon (:) contains 2 pixels and the comma (,) contains 3, so I have switched them. However, depending on your font, you may get a better picture if you switch them in the code below ("%scan_current_line%:" and "%scan_current_line%," respectively).

^!e::
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
MouseGetPos, scan_x_end, scan_y_end

scan_current_y=%scan_y_start%
scan_current_x=%scan_x_start%
scan_current_line=
Loop
{
    scan_current_x := scan_current_x + 1
    if scan_current_x > %scan_x_end%
    {
        scan_current_line =%scan_current_line%`r`n
        scan_current_y := scan_current_y + 1
        if scan_current_y > %scan_y_end%
            break
        scan_current_x = %scan_x_start%
        continue
    }
    PixelGetColor, found_color, %scan_current_x%, %scan_current_y%
    StringMid, scan_rgb_r, found_color, 3, 2
    StringMid, scan_rgb_g, found_color, 5, 2
    StringMid, scan_rgb_b, found_color, 7, 2
    scan_rgb_r=0x%scan_rgb_r%
    scan_rgb_g=0x%scan_rgb_g%
    scan_rgb_b=0x%scan_rgb_b%
    SetFormat, integer, hex
    scan_rgb_sum:=scan_rgb_r + scan_rgb_g + scan_rgb_b
    if scan_rgb_sum > 0x280
    {
      scan_current_line =%scan_current_line%.
    }
    else if scan_rgb_sum > 0x200
    {
      scan_current_line =%scan_current_line%:
    }
    else if scan_rgb_sum > 0x180
    {
      scan_current_line =%scan_current_line%,
    }
    else if scan_rgb_sum > 0x100
    {
      scan_current_line =%scan_current_line%+
    }
    else if scan_rgb_sum > 0x80
    {
      scan_current_line =%scan_current_line%8
    }
    else 
    {
      scan_current_line =%scan_current_line%#
    }
}
Clipboard=%scan_current_line%
MsgBox, Scan Complete
return

^!b::
CoordMode, Mouse, Screen
MouseGetPos, scan_x_start, scan_y_start
return

(edited to make instructions more clear and remove extra code tag)
(edited again to add note)
(edited again due to OCD and that 3 is better replaced by +)

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
Posted Image
very nice!

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Neat thinking! Wkd script :D

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
very nice :)


I have modified it to allow you to hold control and then click and drag to select an area instead.

~^LButton::

stop=0

#persistent
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
MouseGetPos, scan_x_start, scan_y_start 
currentXpos=%scan_x_start%
currentYpos=%scan_y_start%
ToolTip, ., scan_x_start, scan_y_start

WinSet, Transparent, 100, ahk_class tooltips_class32

loop
{


MouseGetPos, scan_x, scan_y
scan_x-=%currentXpos%
scan_y-=%currentYpos%
WinMove, ahk_class tooltips_class32, , , , %scan_x%, %scan_y%

GetKeyState, state, LButton

if state=u
{
tooltip
break
}

}

MouseGetPos, scan_x_end, scan_y_end

TrayTip, , Scanning...., , 1


CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
MouseGetPos, scan_x_end, scan_y_end

scan_current_y=%scan_y_start%
scan_current_x=%scan_x_start%
scan_current_line=
Loop
{
    scan_current_x := scan_current_x + 1
    if scan_current_x > %scan_x_end%
    {
        scan_current_line =%scan_current_line%`r`n
        scan_current_y := scan_current_y + 1
        if scan_current_y > %scan_y_end%
            break
        scan_current_x = %scan_x_start%
        continue
    }
    PixelGetColor, found_color, %scan_current_x%, %scan_current_y%
    StringMid, scan_rgb_r, found_color, 3, 2
    StringMid, scan_rgb_g, found_color, 5, 2
    StringMid, scan_rgb_b, found_color, 7, 2
    scan_rgb_r=0x%scan_rgb_r%
    scan_rgb_g=0x%scan_rgb_g%
    scan_rgb_b=0x%scan_rgb_b%
    SetFormat, integer, hex
    scan_rgb_sum:=scan_rgb_r + scan_rgb_g + scan_rgb_b
    if scan_rgb_sum > 0x280
    {
      scan_current_line =%scan_current_line%.
    }
    else if scan_rgb_sum > 0x200
    {
      scan_current_line =%scan_current_line%,
    }
    else if scan_rgb_sum > 0x180
    {
      scan_current_line =%scan_current_line%:
    }
    else if scan_rgb_sum > 0x100
    {
      scan_current_line =%scan_current_line%3
    }
    else if scan_rgb_sum > 0x80
    {
      scan_current_line =%scan_current_line%8
    }
    else
    {
      scan_current_line =%scan_current_line%#
    }
}
Clipboard=%scan_current_line%
TrayTip, , Scan complete, , 1
sleep, 1000
TrayTip
return 


Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
You could also use a GUI to display the results instead of using the clipboard. Something like this-

gui, font,s1, Terminal
Gui, Add, Edit, x0 y0 w600 h400 -wrap +HScroll +VScroll, %scan_current_line%
Gui, Show, h400 w600, Ascii Art


Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
I've played with alot of ascii art apps, the rendering is really nice with this script. :) Thanks for sharing. Nice revisions Jon, I'll have to pinch that draw rectangle routine. ;)
"Anything worth doing is worth doing slowly." - Mae West
Posted Image

tinypig
  • Members
  • 16 posts
  • Last active: Aug 29 2014 12:36 AM
  • Joined: 12 Mar 2005
Thanks for the comments, all. I have already begun using your version with the transparent window, Jon. Nice. :)

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
That's a great effect: An almost magical transformation from graphics to ascii characters.

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
This is an amazing script. Might I suggest that it be considered for the showcase? There's some unique and interesting stuff in here that could prove useful to anyone reading up on the Pixel commands.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I considered adding it to the showcase but it seems a little obscure in terms of practical uses. The rule of thumb is that a script should be at least mildly interesting to 10% of site visitors.

Maybe in this case the coolness factor is enough to generate interest even though few would actually use the script regularly. So I'm open to the idea if others think it should be put in the showcase.

fsnow55
  • Guests
  • Last active:
  • Joined: --

I considered adding it to the showcase but it seems a little obscure in terms of practical uses. The rule of thumb is that a script should be at least mildly interesting to 10% of site visitors.

Maybe in this case the coolness factor is enough to generate interest even though few would actually use the script regularly. So I'm open to the idea if others think it should be put in the showcase.


Definitely has my vote!

meod
  • Guests
  • Last active:
  • Joined: --
is there any way of making the final ascii art smaller...i realize the original size matters, but it comes out too big even with a small image

1991
  • Members
  • 29 posts
  • Last active: Jun 04 2007 03:05 AM
  • Joined: 20 Jan 2006
~^LButton:: 

stop=0 

#persistent 
CoordMode, Mouse, Screen 
CoordMode, Tooltip, Screen 
MouseGetPos, scan_x_start, scan_y_start 
currentXpos=%scan_x_start% 
currentYpos=%scan_y_start% 
ToolTip, ., scan_x_start, scan_y_start 

WinSet, Transparent, 100, ahk_class tooltips_class32 

loop 
{ 


MouseGetPos, scan_x, scan_y 
scan_x-=%currentXpos% 
scan_y-=%currentYpos% 
WinMove, ahk_class tooltips_class32, , , , %scan_x%, %scan_y% 

GetKeyState, state, LButton 

if state=u 
{ 
tooltip 
break 
} 

} 

MouseGetPos, scan_x_end, scan_y_end 

TrayTip, , Scanning...., , 1 


CoordMode, Pixel, Screen 
CoordMode, Mouse, Screen 
MouseGetPos, scan_x_end, scan_y_end 

scan_current_y=%scan_y_start% 
scan_current_x=%scan_x_start% 
scan_current_line= 
Loop 
{ 
    scan_current_x := scan_current_x + 1 
    if scan_current_x > %scan_x_end% 
    { 
        scan_current_line =%scan_current_line%`r`n 
        scan_current_y := scan_current_y + 1 
        if scan_current_y > %scan_y_end% 
            break 
        scan_current_x = %scan_x_start% 
        continue 
    } 
    PixelGetColor, found_color, %scan_current_x%, %scan_current_y% 
    StringMid, scan_rgb_r, found_color, 3, 2 
    StringMid, scan_rgb_g, found_color, 5, 2 
    StringMid, scan_rgb_b, found_color, 7, 2 
    scan_rgb_r=0x%scan_rgb_r% 
    scan_rgb_g=0x%scan_rgb_g% 
    scan_rgb_b=0x%scan_rgb_b% 
    SetFormat, integer, hex 
    scan_rgb_sum:=scan_rgb_r + scan_rgb_g + scan_rgb_b 
    if scan_rgb_sum > 0x2d9 
    { 
      scan_current_line =%scan_current_line%. 
    } 
    else if scan_rgb_sum > 0x294 
    { 
      scan_current_line =%scan_current_line%: 
    } 
    else if scan_rgb_sum > 0x273 
    { 
      scan_current_line =%scan_current_line%; 
    } 
    else if scan_rgb_sum > 0x258
    { 
      scan_current_line =%scan_current_line%t
    } 
    else if scan_rgb_sum > 0x1b9
    { 
      scan_current_line =%scan_current_line%j
    }
    else if scan_rgb_sum > 0x1a7
    { 
      scan_current_line =%scan_current_line%f
    } 
    else if scan_rgb_sum > 0x1b3
    { 
      scan_current_line =%scan_current_line%L
    } 
    else if scan_rgb_sum > 0x138
    { 
      scan_current_line =%scan_current_line%G
    } 
    else if scan_rgb_sum > 0x108
    { 
      scan_current_line =%scan_current_line%D
    } 
    else if scan_rgb_sum > 0xe1
    { 
      scan_current_line =%scan_current_line%K
    } 
    else if scan_rgb_sum > 0xbd
    { 
      scan_current_line =%scan_current_line%W
    } 
    else 
    { 
      scan_current_line =%scan_current_line%#
    } 
} 
Clipboard=%scan_current_line% 
TrayTip, , Scan complete, , 1 
sleep, 1000 
TrayTip 
return 

^this variant adds more possible color variants
13 compared to 6. :shock:

TODO:create a sig
TODO:make more posts

1991
  • Members
  • 29 posts
  • Last active: Jun 04 2007 03:05 AM
  • Joined: 20 Jan 2006
also:

Use lucinda console regular for best results.
:wink:

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

is there any way of making the final ascii art smaller...i realize the original size matters, but it comes out too big even with a small image

It needs some work...
You can take a pixel out of n, with poor results.
Or you can make an average of n x n pixels (eg. a square of 2x2 pixels), which can be better.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")