AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fake ASCII art

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
PurloinedHeart



Joined: 04 Apr 2008
Posts: 114
Location: Canada

PostPosted: Sun Jul 06, 2008 11:59 pm    Post subject: Fake ASCII art Reply with quote

Now you can pretend to be an ASCII artist!

Code:

;Needed On Next Version:
;2nd GUI with options
 ;Speed
 ;Colors
 ;Eraser
 ;Shapes (Later Version?)
 ;Text Selection (Range)
 ;Text Selection (Specific Text)
;Focus Check
Gui +Resize +ToolWindow
Gui, Show, w200 h200
Gui, Color, FFFFFF
return

MButton::
Loop
{
 GetKeyState, Down, MButton, P
 if Down = D
  {
   Random, Rand, 97, 122
   Transform, Rand, Chr, %Rand%
   MouseGetPos, X, Y
   x:=x-10, y:=y-25
   Gui, Add, Text, x%X% y%Y%, %Rand%
   Sleep, 50
  }
}
return
GuiClose:
ExitApp
Back to top
View user's profile Send private message
Icarus



Joined: 24 Nov 2005
Posts: 440

PostPosted: Mon Jul 07, 2008 9:11 am    Post subject: Reply with quote

Dont mean to crash your party, but I saw a big problem with your approach.
You will not be able to copy it, and then paste it as text file, since you did not use rows and columns.

Took your code and changed it a little so it can now copy, and you can also erase characters as you go (right click)

Hows this?
Code:
/* 
                                  ª          ª                                 
                        _    Ñ    x   {  {   x    Ñ    _                       
              ë    Õ    g    š ¾RßJ:‰AKõõKA‰:JßR¾ š    g    Õ    ë             
         T          œ÷ÔÐRÑslë o+•ýö~øIIø~öý•+o ëlsÑRÐÔ÷œ          T         
      ~ûµQç`°÷e϶Ûq{uîófQÀO¹™íÓ?8qÞ]ºèÖÖèº]Þq8?Ó홹OÀQfóîu{qÛ¶Ïe÷°`çQµû~     
     P§ÇDq$9                                                        9$qDǧP     
    çªBhwi        OUrea ME?do    ead E?doY    adM                     iwhBªç   
    µÀJ—        YOUread E?doY    adM ?doYO    dME                       —JÀµ   
   ^‹˜         YOUreadM ?doYO    dME doYOU    ME?   1.2                   ˜‹^   
   E²         YOUre dME doYOU    ME? oYOUr    E?d                          ²E   
  Ñ”        oYOUre  ME? oYOUr    E?d YOUre   E?d    readME? oYOUre dME ead  ”Ñ 
  å       doYOUre   E?d YOUre    ?do OUrea   ?do    e       Y       E   d    å 
  ‡      doYOUreadME?do OUreadME?doY UreadME?d      adME?do O       ?   M    ‡ 
  ‡    ?doYOUre     doY Uread    oYO readM   oYO          Y U       d   E    ‡ 
  å   ?doYOUr       oYO readM    YOU eadME    OUr   ME?doYO readME doY E?d   å 
  ÄÍ                YOU          OUr           rea                          ÍÄ 
   b                OUr          Ure           ead                          b   
   T}OB¹Ë            re           ea            dM                     Ë¹BO}T   
    —Š?†(/            a            d             E                    /(†?Š—   
    ÇI| Ü›eþ                                                      þe›ÂÜ |IÇ   
     P§W ®Â3YˆaN³j2¢                                        ¢2j³NaˆY3® W§P     
      ~ûµï`¬’e϶Ûq{uîófQÀO¹™íÓ?8qÞ]ºèÖÖèº]Þq8?Ó홹OÀQfóîu{qÛ¶Ïe’¬`ïµû~     
                      œ÷ÔÐRÑslë o+•ýö~øIIø~öý•+o ëlsÑRÐÔ÷œ                     
                               ¾RßJ:‰AKõõKA‰:JßR¾                               
                                                                               
    Left Click   = Draw
    Right Click  = Erase
    Ctrl+C       = Copy
    Ctrl+Shift+C = Copy Inverted
    Escape       = Copy and Close
    Del          = Clear All
    F12          = Toggle Mirror X
    F11          = Toggle Mirror Y
    F10          = Toggle Fixed Word (On/Off)
   
    You may copy any text to the clipboard before running this
    script in order to copy it to the matrix
                                                           
*/

#SingleInstance Force

; Configuration ----------------------------------------------------------------
FIXED_CHAR   := "doYOUreadME?"  ; Set to any word or character. blank for random
MATRIX_WIDTH  = 80              ; How many columns
MATRIX_HEIGHT = 40              ; How many rows
FONT_SIZE     = 9
; Configuration ----------------------------------------------------------------

Gosub Init 

Return

Init:
  FixedLen := StrLen( FIXED_CHAR )
  FixedChar := FIXED_CHAR

  ; Reset all cell values to " "
  Loop %MATRIX_HEIGHT% {
    i := A_Index
    Loop %MATRIX_WIDTH% {
      j := A_Index
      Cell_%i%_%j% := " "
    }
  }
 
  ; If we have something in the clipboard, put it inside our cells
  If( Clipboard <> "" ) {
    StringSplit Row_, Clipboard, `n, `r
    Loop %Row_0%
      StringSplit Cell_%A_Index%_, Row_%A_Index%
  }
 
  Gui Color, FFFFFF
  Gui Font, s%FONT_SIZE%,Lucida Console   ; Monospace font needed here
  Gui Margin, 0, 0
 
  ; Create the GUI matrix
  Loop %MATRIX_HEIGHT% {
    i := A_Index
    Loop %MATRIX_WIDTH% {
      j := A_Index
      ;Gui Add, Text, x%X% y%Y% vCell_%i%_%j%, % Cell_%i%_%j%
      Gui Add, Text, % "x" . ( A_Index = 1 ? "0" : "+0" ) . "y" . ( A_Index = 1 ? "+0" : "p" ) . " vCell_" . i . "_" . j, % Cell_%i%_%j%
    }
  }
  Gui Show,,ASCII
Return

GuiEscape:
GuiClose:
  Gosub ^c
  ExitApp
Return

GetChar( X, Y ) {
  Global FixedChar, FixedLen
 
  If( FixedChar = "" )
    Result := GetRandChar()
  Else {
    SubChar := Mod( X+Mod( Y, FixedLen ), FixedLen )+1
    Result := SubStr( FixedChar, SubChar, 1 )
  }
  Return Result
}

GetRandChar() {
  Random Result, 33, 255
 
  If( Result = 38 ) or ( Result = 127 ) or ( Result = 129 ) or ( Result = 141 ) or ( Result = 143 ) or ( Result = 144 ) or ( Result = 157 )
    Result := GetRandChar()

  Transform, Result, Chr, %Result% 
  If( Result = "" )
    Result := GetRandChar() 

  Return Result
}

Draw( erase=false ) {
  Global MirrorX, MirrorY, MATRIX_WIDTH, MATRIX_HEIGHT
 
  MouseGetPos MX, MY, WinID, MControl
  WinGetTitle WinTitle, ahk_ID %WinID%
  If( WinTitle <> "ASCII" )
    Return
   
  GuiControl Focus, %MControl%
  GuiControlGet GuiVarName, FocusV
  If( InStr( GuiVarName, "Cell" ) ) {
    GuiControlGet GuiValue,, %GuiVarName%
   
    StringSplit Token, GuiVarName, _
    OriginalX := Token3
    OriginalY := Token2
    MirroredX := MATRIX_WIDTH-OriginalX+1
    MirroredY := MATRIX_HEIGHT-OriginalY+1
   
    ThisChar := erase ? " " : GetChar( OriginalX, OriginalY )
   
    %GuiVarName% := ThisChar
    GuiControl,,%GuiVarName%, % %GuiVarName%   
   
    If( MirrorX ) {
      MirrorVarName = Cell_%OriginalY%_%MirroredX%
      %MirrorVarName% := ThisChar
      GuiControl,,%MirrorVarName%, % %MirrorVarName%
     
    }
    If( MirrorY ) {
      MirrorVarName = Cell_%MirroredY%_%OriginalX%
      %MirrorVarName% := ThisChar
      GuiControl,,%MirrorVarName%, % %MirrorVarName%
     
      If( MirrorX ) {
        MirrorVarName = Cell_%MirroredY%_%MirroredX%
        %MirrorVarName% := ThisChar
        GuiControl,,%MirrorVarName%, % %MirrorVarName%       
      }
    }
  }
}

GetControlUnderMouse( ByRef X, ByRef Y ) {
  MouseGetPos MX, MY, WinID, MControl
  WinGetTitle WinTitle, ahk_ID %WinID%
  If( WinTitle <> "ASCII" )
    Return
   
  GuiControl Focus, %MControl%
  GuiControlGet GuiVarName, FocusV
 
  If( InStr( GuiVarName, "Cell" ) ) {
    StringSplit Token, GuiVarName, _
    X := Token3
    Y := Token2
  } 
}

MyTooltip( text ) {
  Tooltip %text%
  SetTimer RemoveTooltip, -1000
}

RemoveTooltip:
  Tooltip
Return

#IfWinActive ASCII
~RButton::
  Loop {
    Draw( true )
    If( Not GetKeyState( "RButton", "D" ) )
      Break
  }
Return

~LButton::
  Loop {
    Draw()
    If( Not GetKeyState( "LButton", "D" ) )
      Break
  }
Return

^c::
^+c::
  Result := ""
  Loop %MATRIX_HEIGHT% {
    i := A_Index
    Loop %MATRIX_WIDTH% {
      j := A_Index
      Result .= A_ThisHotkey <> "^+c" ? Cell_%i%_%j% : ( Cell_%i%_%j% = " " ? GetChar( i, j ) : " " )
    }
    Result .= "`r`n"
  }
  Clipboard = %Result% 
  MyTooltip( "Copied" . ( A_ThisHotkey = "^+c" ? " (Inverted)" : "" ) )
Return

Del::
  Loop %MATRIX_HEIGHT% {
    i := A_Index
    Loop %MATRIX_WIDTH% {
      j := A_Index
      Cell_%i%_%j% := " "
      GuiControl,,Cell_%i%_%j%, % " "
    }
  }
Return

F12::
  MirrorX := !MirrorX
  MyTooltip( "Mirror X is " . ( MirrorX ? "ON" : "OFF" ) )
Return

F11::
  MirrorY := !MirrorY
  MyTooltip( "Mirror Y is " . ( MirrorY ? "ON" : "OFF" ) )
Return

F10::
  TempFixedChar1 := FixedChar
  FixedChar := TempFixedChar2
  TempFixedChar2 := TempFixedChar1
Return

; Debug: Loop for copying all ascii table to clipboard
Debug:
  String := ""
  Loop 255 {
    If( A_Index > 32 ) {
      String .= A_Index . ":"
      Transform, ThisChar, Chr, %A_Index%
      String .= ThisChar . "`n"
    }
  }
  Clipboard = %String%
Return




EDIT:
You can call it AHKscii... Smile
(Pronounced A.H.K.ski)

EDIT2:
Updated the code, with more functions and some fixes
Now you can copy any text beforehand, and "edit" it with AHKscii Smile
_________________
Sector-Seven (Music and Utilities)


Last edited by Icarus on Sat Jul 12, 2008 9:49 am; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
PurloinedHeart



Joined: 04 Apr 2008
Posts: 114
Location: Canada

PostPosted: Mon Jul 07, 2008 4:34 pm    Post subject: Reply with quote

That is amazing. Surprised
Back to top
View user's profile Send private message
Icarus



Joined: 24 Nov 2005
Posts: 440

PostPosted: Mon Jul 07, 2008 4:42 pm    Post subject: Reply with quote

Glad you like it, I thought you might get mad...
_________________
Sector-Seven (Music and Utilities)
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Icarus



Joined: 24 Nov 2005
Posts: 440

PostPosted: Mon Jul 07, 2008 5:46 pm    Post subject: Reply with quote

Posted an updated version - now allows you to copy inverted result.
Plus some fixes and efficiency modifications.
_________________
Sector-Seven (Music and Utilities)
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
RIST



Joined: 08 May 2008
Posts: 8
Location: C:\ESTONIA\adavere\RIST.rar

PostPosted: Fri Jul 11, 2008 10:25 pm    Post subject: Reply with quote

great 10/10
_________________
Keegi Siin ka Eestlane? Smile
Back to top
View user's profile Send private message
Icarus



Joined: 24 Nov 2005
Posts: 440

PostPosted: Sat Jul 12, 2008 9:50 am    Post subject: Reply with quote

Version 1.2 - now allows to use a fixed word or character as the drawing "color"
_________________
Sector-Seven (Music and Utilities)
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group