fb:porticula NoPaste
Versuch: Formel über LaTeX in FB einbinden
Uploader: | nemored |
Datum/Zeit: | 01.08.2014 20:56:26 |
' benötigt: LaTeX, ghostscript und imagemagick (convert)
#include once "fbgfx.bi"
declare function tex2bmp(txt as string, density as integer = 100) as FB.Image ptr
screenres 800, 400, 32
width 100, 25
color 0, rgb(255, 255, 255)
cls
randomize
' Nullstellen zufaellig auswaehlen
dim as integer n1 = int(rnd*11) - 5, n2 = int(rnd*5) - 5, a
do
a = int(rnd*11) - 5
loop until a <> 0
dim as integer b = -a*(n1+n2), c = a*n1*n2
dim as string texstring = "Bestimmen Sie die Nullstellen von $f(x)=" & a & "x^2"
if b > 0 then texstring &= "+"
if b <> 0 then texstring &= b & "x"
if c > 0 then texstring &= "+"
if c <> 0 then texstring &= c
texstring &= "$."
dim as FB.Image ptr teximg = tex2bmp(texstring, 100)
put (100, 100), teximg, pset
imagedestroy teximg
getkey
function tex2bmp(txt as string, density as integer = 100) as FB.Image ptr
dim img as FB.Image ptr, f as integer = freefile, breite as integer, hoehe as integer
open "temp.tex" for output as #f
print #f, "\documentclass{article} \usepackage{lmodern} \usepackage[english]{babel} \usepackage{pst-eps}"
print #f, "\pagestyle{empty} \begin{document} \TeXtoEPS"
print #f, txt
print #f, "\endTeXtoEPS \end{document}"
close #f
shell "latex temp.tex"
shell "dvips -E -o temp.eps temp.dvi"
shell "convert -density " & density & "x" & density & " temp.eps -blur 0x.45 temp.bmp"
open "temp.bmp" for binary as #f
get #f, 19, breite
get #f, 23, hoehe
close #f
img = imagecreate(breite, hoehe)
bload "temp.bmp", img
dim as string tempfile = dir("temp.*")
do while len(tempfile)
kill tempfile
tempfile = dir
loop
return img
end function