Ooops
November 25, 2020, 06:15:40 AM

Author Topic: [bmx] font to defdata by Jesse [ 1+ years ago ]  (Read 451 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] font to defdata by Jesse [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : font to defdata
Author : Jesse
Posted : 1+ years ago

Description : converts a string of characters using current font into a defdata bmx program to be included in a game. I hope it helps someone.

Code :
Code: BlitzMax
  1. Function bittext(capital$,name$)
  2.         CreateFile(name$)
  3.         Local file:TStream = OpenFile(name$)
  4.         If file = Null End
  5.         For Local i% = 0 To capital.length-1
  6.                 Cls
  7.                 Local width% = TextWidth(Chr(capital[i]))
  8.                 Local Height% = TextHeight(Chr(capital[i]))
  9.                 DrawText Chr(capital[i]),0,0
  10.                 Local pixmap:TPixmap = GrabPixmap(0,0,width,height)
  11.                 WriteString file,"defdata "+String(width)+" ,"+String(height)+"'      "+Chr(capital[i])+"~r~n"
  12.                 For Local y% = 0 To height -1
  13.                         Local text$="Defdata "
  14.                         For Local x% = 0 To width-1
  15.                                 Local color% =ReadPixel(pixmap,x,y) & $fff
  16.                                 If x Then text = text+","
  17.                                 If color Then text=text+"1" Else text = text+"0"
  18.                                 SetColor 200,100,0
  19.                                 If color DrawRect x*(5),y*(5),4,4
  20.                         Next
  21.                         text = text +"~r~n"
  22.                         WriteString file,text
  23.                 Next
  24.                 Flip()
  25.                 Delay(50)
  26.         Next
  27.         CloseFile file
  28.         Print "program saved as"+name
  29. End Function
  30.  
  31. Graphics 1024,768,32
  32. Local letters$= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  33. Local numsymb$ = "0123456789!@#$%&()-+*/^_="
  34.  
  35. bittext(letters,"letters.bmx")
  36. bittext(numsymb,"numsymb.bmx")


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal