Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Set the location of Sprite
Dean's Director Resources
Streaming Media
Case sensitive string comparison
sound volum
zOpen
Coloring Book
.HLP
Navegacion y colision 3d - 3d Collision Navigation
DirectInteraction Xtra.
 

 

 

Behavior JTMR Image to Text

Added on 4/17/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: ElianChrebor

Converts an image to ascii text. You can find the complete JTMR Img2Txt software at the following address http://services.worldnet.fr/elian-c/?part=Resources

Download PC Source    Download Mac Source
-- JTMR
-- IMG2TXT
-- GRAY
-- ==================================================
-- JTMR Img2Txt GrayScale Behavior
-- Converts bitmap in raw text
-- Use with Field or Text members.
-- ==================================================
-- © 2000 - JTMR
-- ==================================================

-- globals

-- properties
property modelMember, pasteMatrixWidth, pasteMatrixHeight
property grayTonesCharList, status

-- scripts
on beginSprite me
  -- checks whether sprite(me.spriteNum).member is a valid member
  if not(getOne([#Text, #Field], sprite(me.spriteNum).member.type)) then
    alert "JTMR Img2Txt #1" & Return & "Use this behavior with a text or a field member."
    me.status = #done
    return 0
  end if
  -- checks whether modelMember is a valid member
  if me.modelMember.type <> #Bitmap then
    alert "JTMR Img2Txt #1" & Return & "Member Ref must be a valid 8bits depth bitmap"
    me.status = #done
    return 0
  end if
  if me.modelMember.depth > 8 then
    alert "JTMR Img2Txt #1" & Return & "Member Ref must be a valid 8bits depth bitmap"
    me.status = #done
    return 0
  end if
  -- Initializes...
  me.grayTonesCharList = [" ", ".", ",", "!", ":", ";", "@", "#"]
  sprite(me.spriteNum).member.wordWrap = false
  sprite(me.spriteNum).member.text = "JTMR Img2Txt #1" & Return & "wait a few seconds ..."
end beginSprite

on exitFrame me
  if me.status = #done then return 0
  me.modelMember.paletteRef = #grayscale
  sprite(me.spriteNum).member.text = JTMRCompute(me)
  me.status = #done
end exitFrame

on JTMRCompute me
  myComputedStr = ""
  myXPos = 1
  myYPos = 1
  repeat while TRUE
    myPValue = []
    repeat with y = myYPos to myYPos + me.pasteMatrixHeight - 1
      myPValue[y-myYPos+1] = []
      repeat with x = myXPos to myXPos + me.pasteMatrixWidth - 1
        myPValue[y-myYPos+1][x-myXPos+1] = getPixel(me.modelMember, x, y)
      end repeat
    end repeat
    myGrayValue = JTMRgetSumFromList(myPValue)/(myPValue[1].count * myPValue.count)
    
    myGrayList = [32, 64, 96, 128,  160, 192, 224, 256]
    append myGrayList, myGrayValue
    sort myGrayList
    
    myChar = me.grayTonesCharList[getOne(myGraylist, myGrayValue)]
    myComputedStr = myComputedStr & myChar
    myXPos = myXPos + me.pasteMatrixWidth + 1
    if myXPos > me.modelMember.width - me.pasteMatrixWidth then
      myXPos = 1
      myYPos = myYPos + me.pasteMatrixHeight + 1
      myComputedStr = myComputedStr & return
      if myYPos > me.modelMember.height - me.pasteMatrixHeight then
        exit repeat
      end if
    end if
  end repeat
  return myComputedStr
end JTMRCompute

on JTMRgetSumFromList pList
  if not(listP(pList)) then
    return -13
  end if
  myListLength = pList.count
  myRetValue = 0
  -- 1D List
  if not(listP(pList[1])) then
    repeat with x = 1 to myListLength
      myRetValue = myRetValue + value(pList[x])
    end repeat
    return myRetValue
    -- 2D List
  else
    repeat with y = 1 to myListLength
      myRetValue = myRetValue + JTMRgetSumFromList(pList[y])
    end repeat
    return myRetValue
  end if
end JTMRgetSumFromList


-- ==================================================
on getPropertyDescriptionList
  myPropertylist = [:]
  addProp myPropertyList, #modelMember, [#Comment: "Model Member (8 bits bitmap member)", #format: #bitmap, #default: 0]
  addProp myPropertyList, #pasteMatrixWidth, [#Comment: "Matrix Width", #format: #float, #range: [#min: 1, #max: 20], #default: 4]
  addProp myPropertyList, #pasteMatrixHeight, [#Comment: "Matrix Height", #format: #float, #range: [#min: 1, #max: 20], #default: 8.5]
  return myPropertyList
end getPropertyDescriptionList

on getBehaviorDescription
  return "JTMR Behavior Library" & RETURN &¬
         "© 2000 - JTMR" & RETURN &¬
         "jtmr@worldnet.fr" & RETURN &¬
         "http://services.worldnet.fr/elian-c" & RETURN & RETURN &¬
         "JTMR Img2Txt GrayScale Behavior" & RETURN &¬
         "Download JTMRImg2Txt software (full version includes several effects, HTML export...) at http://services.worldnet.fr/elian-c/?part=Resources." & RETURN & RETURN & "Converts bitmap in raw text." & RETURN &¬
         "Better result when the field (or text) member uses a monospace font." & RETURN & RETURN &¬
         "This behavior is free software; you can redistribute it and/or modify "  &¬
         "it under the terms of the GNU General Public License as published by "  &¬
         "the Free Software Foundation; either version 2 of the License, or (at "  &¬
         "your option) any later version. "  &¬
         "This program is distributed in the hope that it will be useful, but "  &¬
         "WITHOUT ANY WARRANTY; without even the implied warranty of "  &¬
         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU"  &¬
         "General Public License for more details. "  &¬
         "You should have received a copy of the GNU General Public License"  &¬
         "along with this program; if not, write to the Free Software "  &¬
         "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
  
end getBehaviorDescription

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail