|
Post by zzz000abc on Jul 8, 2022 16:11:18 GMT
is there any way to get maths symbols through JB program in image format?
|
|
|
Post by jarychk on Jul 8, 2022 17:22:35 GMT
I am not sure how you mean that. Is printing to a graphic window or printing to a graphicbox control suitable for what you want?
|
|
|
Post by Rod on Jul 8, 2022 18:36:04 GMT
There are many bmp resource for maths symbols. You can use these bmps or you can draw your own symbols with the drawing command.
Give us mor of a clue as to what size, color and range of symbols you need.
|
|
|
Post by zzz000abc on Jul 8, 2022 19:09:50 GMT
There are many bmp resource for maths symbols. You can use these bmps or you can draw your own symbols with the drawing command. Give us mor of a clue as to what size, color and range of symbols you need. input should be in text format ( like latex commands) and out put should be formula with mathematical symbols in image format.
|
|
|
Post by tsh73 on Jul 8, 2022 21:32:03 GMT
There is some math symbols in Symbol font, have a look Obviously some symbols supposed to be combined of several parts (big integrals, big brackets) 'nomainwin
open "test" for graphics_nsb_nf as #gr #gr "home; down; posxy cx cy" #gr "trapclose [quit]" '#gr "font symbol bold italic 14" #gr "font symbol 12"
#gr "place 20, 0" #gr "\" for i = 2 to 15 s$="" for j = 0 to 15 s$=s$+chr$(i*16+j) next if instr(s$, "\") then #gr "|";s$ else #gr "\";s$ end if next
#gr "flush" wait
[quit] timer 0 close #gr end
|
|
|
Post by tsh73 on Jul 8, 2022 21:37:44 GMT
You really can't beat Latex on his field. So how complex formula you need? Give us some examples. I would say, single-line, may be with single level sub and supesrript are pretty easy to do (that is without fractions, radicals and big operator symbols (with it's own indexes) like Integral, Sum and Product)
|
|
|
Post by tsh73 on Jul 12, 2022 22:49:18 GMT
So here's what I got: * Latin letters. * Greeks and any stuff that is in Symbol font. * single level subscript/superscript (btw Wikipedia has an article on subscript/superscipt, I made adjustments after looking) First picture is from computer set to 125% font It had severe problem of cutting stick from italic "d" Second and third are from computer with font set to 100% I do not see much problems variable noItalic (0 or 1) says if it make all letters (except Greeks) italic (slanted) or not Other things If it encounter \ it changes font to Symbol So \a give alpha, \D gives Delta (triangle), \p gives pi Any other symbol you will find with CharMap are yours to keep. But I had problems posting chr$(180), that gives "times" operator (like 'x' but no serifs) - after posting symbol changed. So I had to program it in for last formula (really I just Googled "formula with Greek letters", that was it) If it encounters ^ it goes superscript for single character (font about 60% of current, moved up) If you need several characters type "^1^2^3". Or enhance this program ;) If you type "^\a" you'll get superscipt alpha (smaller and moved up) If it encounters _ it goes subscript for single character - really the same but moved down if noItalic is 0, it keeps digits, operators, brackets and Greeks straight, other letters italic. Modeled after TeX :) Give it a spin, try to code a formula ;) 'rendering some maths 'ths73 Jul 2022 nomainwin
normalFnt=14 'normal smallFnt=12 'index smallFnt=9 'index by Wikipedia as 60+% smallFnt=10 bigFnt=16 'sum etc
normalFnt$="font times_new_roman ";normalFnt indexFnt$="font times_new_roman ";smallFnt normalItalicFnt$="font times_new_roman italic ";normalFnt indexItalicFnt$="font times_new_roman italic ";smallFnt
normalSymbolFnt$="font symbol ";normalFnt indexSymbolFnt$="font symbol ";smallFnt indexBigFnt$="font symbol ";bigFnt
funcList$="min max sin cos atn log ln exp" ops$="+-*/%()[]{}<>=~&|!," '^\ are special digits$=".0123456789" 'functions and operators are stright 'numbers are stright 'variables are italic '\ starts Symbol font, like \a for alpha '^ starts superscript '_ starts subscript '# reverts to normal
WindowHeight=600 open "test" for graphics_nsb_nf as #gr #gr "home; down; posxy cx cy" #gr "trapclose [quit]"
#gr normalFnt$ #gr "\" #gr "posxy dummy dy" lineHeight=dy-cy 'notice lineHeight 'I got 26 but I have 125% scale
data "y=3x+\a" data "Hlop_2 Hlop^2" 'wikipedia example on sub/super scripts data "y=3x^2+\a_7-\p/3" data "\a^\b+e^\p-\g_\D" data "e^2^1-x_1_,_2" 'really ugly data "a^b-c_d+a^a+b_b" 'upper a is cut off! data "A^b-C_d+1" 'lower d is cut off!! data "a^B-c_D+d+1" 'italic d is cut! data "A^B-C_D" data "H=\e_0\dE/\dt+j" data "XYZZY"
noItalic = 1 'noItalic = 0
y0=0 while 1 read math$ if math$="XYZZY" then exit while if instr(math$, "H=\e_0\dE")=1 then math$="\"+chr$(209)+"\"+chr$(180)+math$ x0=lineHeight y0=y0+2*lineHeight
'sub printMath x0, y0, math$ #gr "place ";x0;" ";y0 '#gr "\";math$ i =1 while i<=len(math$) c$=mid$(math$, i, 1) dy=0 select case case instr("+-", c$)<>0 'cause (-) is too small and` #gr normalSymbolFnt$ 'if we took symbol one, (+) gets out of line case c$="\" i=i+1 c$=mid$(math$, i, 1) #gr normalSymbolFnt$ case c$="^" i=i+1 c$=mid$(math$, i, 1) if c$="\" then i=i+1 c$=mid$(math$, i, 1) #gr indexSymbolFnt$ else if noItalic or instr(ops$+digits$, c$)<>0 then #gr indexFnt$ else #gr indexItalicFnt$ end if end if dy=0-lineHeight*(3/8) case c$="_" i=i+1 c$=mid$(math$, i, 1) if c$="\" then i=i+1 c$=mid$(math$, i, 1) #gr indexSymbolFnt$ else if noItalic or instr(ops$+digits$, c$)<>0 then #gr indexFnt$ else #gr indexItalicFnt$ end if end if dy=lineHeight*(1/8) case noItalic or instr(ops$+digits$, c$)<>0 #gr normalFnt$ case else #gr normalItalicFnt$ end select #gr "stringwidth? c$ dx" #gr "place ";x0;" ";y0+dy #gr "\";c$ x0=x0+dx+1 '+3 prevents italic d from being cut i=i+1 wend wend
#gr "flush" wait
[quit] timer 0 close #gr end
|
|
|
Post by zzz000abc on Jul 19, 2022 16:50:48 GMT
thank you tsh for your work here is the sample code what I wanted to do. which needs to use mathematical symbols for further development.
'nomainwin '----------------------- op$="two three five none" '----------------------- WindowWidth=800: WindowHeight=600 graphicbox #w1.gb1,0,0,600,400 radiobutton #w1.rd1,word$(op$,1),doRadio,dummy,620,40,120,40 radiobutton #w1.rd2,word$(op$,2),doRadio,dummy,620,80,120,40 radiobutton #w1.rd3,word$(op$,3),doRadio,dummy,620,120,120,40 radiobutton #w1.rd4,word$(op$,4),doRadio,dummy,620,160,120,40 button #w1.bt1,"prev ",[bt1],UL,20,420 button #w1.bt2,"next ",[bt2],UL,180,420 button #w1.bt3,"close",[bt3],UL,340,420 open "abc" for window as #w1 #w1,"trapclose [quit1]" #w1.rd1,"font 20" for i=1 to 3 h1$="#w1.bt";str$(i) #h1$,"!font tahoma 16" next for i=1 to 4 h1$="#w1.rd";str$(i) #h1$,"font tahoma 16" next #w1.gb1,"down" #w1.gb1,"place 20 180" #w1.gb1,"font tahoma 26 ;color 220 80 80 " #w1.gb1,"\Q1. what is even prime number?" '#w1.bt1,"!font 16" wait sub doRadio res$ ures$="Correct Answer;Go Next;Wrong ;Please Try Again" if res$="#w1.rd1" then msg$=word$(ures$,1,";")+chr$(10)+word$(ures$,2,";") playwave "media/bump.wav" else msg$=word$(ures$,3,";")+chr$(10)+word$(ures$,4,";") playwave "media/beep.wav" end if notice "result"+chr$(13)+msg$ end sub
[quit1] close #w1 print "closed" end
|
|
|
Post by Rod on Jul 20, 2022 12:44:29 GMT
A limited number of maths symbols presented by programmer or endless choice input by user?
|
|
|
Post by tsh73 on Jul 20, 2022 13:31:00 GMT
for math quiz, set of ready images (full fromula) will do If there is small enough number to do it by hand - draw nice formulas with TeX/Word/Open Office/ whatever, printscreen and show then from LibertyBasic
|
|