Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Bitmap to Ascii ? Why not !

Hi !
Here is a total useless script... I know I work sometimes for nothing...

This revolutionary script is able to convert all your bitmap pictures in a (grayscale or colored) ascii art into a text file or a html webpage.

Put it above main:
works on rgss 1 & 2

Code:
 

#============================================================================== 

# ** Bitmap vers Ascii Art  

#------------------------------------------------------------------------------ 

#  Par berka...                  http://www.rpgmakervx-fr.com 

# 

# Si vous trouvez une utilité quelconque à ce script, 

#  veuillez avoir l'aimabilité d'en avertir l'auteur 

#============================================================================== 

Tons=['M','@','#','8','0','O','o','c','+','{','|','!',';',':','.',' '] 

Fichier_TXT="./ascii.txt" 

Fichier_HTML="./ascii.html" 

class Bitmap 

  def to_ascii 

    fichier=File.open(Fichier_TXT,"w+") 

    (self.height).times{|y|(self.width).times{|x| 

        c=self.get_pixel(x,y) 

        cg=(c.red+c.green+c.blue)/3 

        cg/=(256/Tons.size) 

        fichier << Tons[cg]} 

      fichier << "\n"} 

    fichier.close 

  end 

  def to_ascii_html 

    fichier=File.open(Fichier_HTML,"w+") 

    fichier << "<pre>" 

    (self.height).times{|y|(self.width).times{|x| 

        c=self.get_pixel(x,y) 

        cg=(c.red+c.green+c.blue)/3 

        cg/=(256/Tons.size) 

        hexa="#" 

        [c.red,c.green,c.blue].each{|col|hexa+=col.to_i.to_s(16).rjust(2,"0")} 

        fichier << '<font color="'+hexa+'">'+Tons[cg]+'</font>'} 

      fichier << "\n"} 

      fichier << "</pre>" 

    fichier.close 

  end 

end

Using:
RMXP
Code:
@bmp=RPG::Cache.picture("test_txt").to_ascii

@bmp=RPG::Cache.picture("test_html").to_ascii_html
RMVX
Code:
@bmp=Cache.system("test_txt").to_ascii

@bmp=Cache.system("test_html").to_ascii_html

results:
html version
arsheshh6.png
 
The only thing i can say is:Cool.... lol, i don´t see much point in it, but i am sure someone will.....
i have no idea of the benefits of this script, though it is nice, really, help to create script commented titles, i.e:

=begin
0 0 ^ ^'
1 Emoticons script by ???? U
--- !---!
=end

(i am sure this will appear buggy, XD)

Thanks ^^
 
That's one elegant looking piece of code. Nice!

Geez, even program code sounds sexy in french!!! :scruff:

Not a clue what it would be used for. (Although, I do have a friend with a 48" plotter!)

I stumbled on a couple websites that have similar online applications (upload a pic, get a ascii art output).
Novelty?

Thanks for sharing.
 

Wichu

Member

Haha, I made a very similar script to this as well. Mine didn't have colour, though.
Here's some suggestions - incorporate transparency, and export it as BBCode as well. Also, instead of making the constants global, you could keep them in the Bitmap class; there could be another script using Tons as a constant name, so putting it inside the Bitmap class would make it less likely to be incompatible. I know it's a nitpick, but you never know...
 
all right, I m gonna make a bbcode version !


edit: well... the main problem is about the translation of pre tag to bbcode...
this may be changed with the "code" tag, but bbcode doesn't parse the content...
 
can u make it so it turns into an ascii png file? that would PWNNNNN, lol.
thats a very new idea though, good job.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top