!gr_lib v4.1 !Graphic library. !Графическая библиотека. !(Game developer's library.) !(Библиотека разработчика игр.) !For: RFO Basic v1.92, OliBasic XXIV. !🖼️ image, 🎨 color, 🔤 text (draw), 🟨⭕🔺 objects, 🎞️ fps, 🎵 audio, ⛔ error, 👆 touch, 📄 text (read), 📄 byte, 📦 zip. !and other functions !🖼 image. load !картинка. загрузить !w$ way. путь fn.def i_l(w$) a=fe(w$):i=0 if !a then err("⛔ Image ["+w$+"] not exist."):i=0 if a then gr.bitmap.load i,w$ if i<1 then err("⛔ Image ["+w$+"] not loaded.") fn.rtn i fn.end !image. draw !картинка. рисовать fn.def i_d(i,x,y) gr.bitmap.draw o,i,x,y fn.rtn o fn.end !image. draw (center) !картинка. рисовать (центр) fn.def i_dc(i,x,y) gr.bitmap.size i,w,h gr.bitmap.draw o,i,x-w/2,y-h/2 fn.rtn o fn.end !image. create new !картинка. создать новую !w,h - size. размер fn.def i_c(w,h) gr.bitmap.create i,w,h fn.rtn i fn.end !image. scale !картинка. масштаб !w,h - new size. новый размер fn.def i_s(i,w,h) gr.bitmap.scale i2,i,w,h fn.rtn i2 fn.end !image. scale q !картинка. масштаб q !size*q. размер*q fn.def i_sq(i,q) gr.bitmap.size i,w,h gr.bitmap.scale i2,i,w*q,h*q fn.rtn i2 fn.end !image. cut !картинка. вырезать fn.def i_cu(i,x,y,w,h) gr.bitmap.size i,iw,ih if x+w>iw | y+h>ih then err("⛔ Cut out of image. >width or height."):end gr.bitmap.crop i2,i,x,y,w,h fn.rtn i2 fn.end !image. save !картинка. сохранить fn.def i_sa(i,w$) gr.bitmap.save i,w$ fn.end !image - background !fill source image to big image !заполнить исходную картинку в большую картинку !w2,h2 - size. размер fn.def i_bg(i,w2,h2) gr.bitmap.size i,w,h i2=i_c(w2,h2) gr.bitmap.drawinto.start i2 for y=0 to h2 step h for x=0 to w2 step w i_d(i,x,y) next x next y gr.render gr.bitmap.drawinto.end fn.rtn i2 fn.end !🎨 color. цвет !red,green,blue !красный,зеленый,синий fn.def c_(r,g,b) gr.color 255,r,g,b,1 fn.end !color. empty !цвет. пустой fn.def c_e(r,g,b) gr.color 255,r,g,b,0 fn.end !color. alpha (transparent) !цвет. альфа (прозрачный) fn.def c_a(a,r,g,b) gr.color a,r,g,b,1 fn.end !color. alpha (transparent)+empty !цвет. альфа (прозрачный)+пустой fn.def c_ae(a,r,g,b) gr.color a,r,g,b,0 fn.end !🔤 text. size !текст. размер fn.def t_s(a) gr.text.size a fn.end !text. draw !текст. рисовать fn.def t_d(x,y,t$) gr.text.draw t,x,y,t$ fn.rtn t fn.end !text. draw +number !текст. рисовать +число fn.def t_dn(x,y,t$,n) gr.text.draw t,x,y,t$+int$(n) fn.rtn t fn.end !text. width !текст. ширина fn.def t_w(t$) gr.text.width w,t$ fn.rtn w fn.end !🟨⭕🔺 object. rect !объект. прямоугольник fn.def o_r(x,y,w,h) gr.rect o,x,y,x+w,y+h fn.rtn o fn.end !object. rect (center) !объект. прямоугольник (центр) fn.def o_rc(x,y,w,h) a=w/2:b=h/2 gr.rect o,x-a,y-b,x+a,y+b fn.rtn o fn.end !object. line !объект. линия fn.def o_l(x,y,x2,y2) gr.line o,x,y,x2,y2 fn.rtn o fn.end !object. point !объект. точка fn.def o_p(x,y) gr.point o,x,y fn.rtn o fn.end !object. oval !объект. овал fn.def o_o(x,y,w,h) gr.oval o,x,y,w,h fn.rtn o fn.end !object. arc !объект. дуга !w,h - size. размер !a,a2 (0-360°) - angles (start,end). углы (старт,конец) !f (1/0) - fill. заливка fn.def o_a(x,y,w,h,a,a2,f) gr.arc o,x,y,x+w,y+h,a,a2,f fn.rtn o fn.end !object. circle !объект. круг !r - radius. радиус fn.def o_c(x,y,r) gr.circle o,x,y,r fn.rtn o fn.end !object. polygon !объект. полигон !l - list. список fn.def o_po(l,x,y) gr.poly o,l,x,y fn.rtn o fn.end !📄 string. to number list !строка. в числовой список fn.def s_nl(t$) list.create n,li split a$[],t$,"," array.length le,a$[] for a=1 to le list.add li,val(a$[a]) next a fn.rtn li fn.end !🎞️ fps. initialization !фпс. инициализация fn.def fps_i$() a$=str$(time()) fn.rtn a$+",0,0" fn.end !fps. фпс fn.def fps$(t$) split a$[],t$,"," ts=val(a$[1]) fpsl=val(a$[2]) fps=val(a$[3]) tn=time()-ts:fps+=1 if tn>=1000 then ts=time():fpsl=fps:fps=0 c_(255,255,0) t_d(4,30,"fps: "+int$(fpsl)) t$=str$(ts)+","+str$(fpsl)+","+str$(fps) fn.rtn t$ fn.end !🎵 audio. initialization !аудио. инициализация !s - streams. потоки fn.def au_i(s) soundpool.open s fn.end !audio. load !аудио. загрузить fn.def au_l(w$) a=fe(w$) if !a then err("⛔ Sound ["+w$+"] not exist."):s=0 if a soundpool.load s,w$ sl(100) if s=0 then err("⛔ Sound not loaded, set more pause in au_l().") endif if s=0 then err("⛔ Sound not loaded.") fn.rtn s fn.end !audio. play !аудио. играть fn.def au_p(s) if s=0 then err("⛔ Sound = null (0)."):goto e soundpool.play st,s,0.99,0.99,1,0,1 if st=0 then err("⛔ Can't play audio.") e: fn.end !⛔ error. ошибка fn.def err(t$) dialog.message "Error",t$,p,"Ok" fn.end !👆 touch. bounded (rect) !касание. ограничено (прямоугольник) fn.def to_b(x,y,w,h) gr.bounded.touch t,x,y,x+w,y+h fn.rtn t fn.end !👆 touch. bounded (rect) (center) !касание. ограничено (прямоугольник) (центр) fn.def to_bc(x,y,w,h) a=w/2:b=h/2 gr.bounded.touch t,x-a,y-b,x+a,y+b fn.rtn t fn.end !⏳ sleep. спать !1/1000 sec fn.def sl(a) pause a fn.end !📄 text. read !текст. считать fn.def t_r$(w$) a=fe(w$) if !a then err("⛔ File ["+w$+"] not exist."):t$="" if a text.open r,f,w$ do text.readln f,t2$ if !t2$="EOF" then t$=t$+t2$ until t2$="EOF" text.close f endif fn.rtn t$ fn.end !text. write !текст. записать fn.def t_w$(w$,t$) text.open w,f,w$ text.writeln f,t$ text.close f fn.end !file exist. файл существует (1/0) fn.def fe(w$) file.exists a,w$ if a>0 then a=1 fn.rtn a fn.end !array. length !массив. длинна fn.def a_le(a$[]) array.length l,a$[] fn.rtn l fn.end fn.def a_le2(a[]) array.length l,a[] fn.rtn l fn.end !percent of line !процент линии !pl(1,2,50) = 25 !1/2 of. от 50 !pl(50,100,10) = 5 fn.def pl(min,max,l) d=(min*l)/max fn.rtn d fn.end !yes no. да нет !a=1 yes, a=0 no fn.def yn$(a) t$="yes" if a=0 then t$="no" fn.rtn t$ fn.end !make folder. создать папку fn.def fol(w$) file.mkdir w$ fn.end ! 📄 byte. read. байт. считать. !lb=0. no line break. нет переноса строки. fn.def by_r$(w$,lb) byte.open r,f,w$ t$="":eof=0:n$=chr$(10) do byte.read.byte f,b b$=chr$(b):t$=t$+b$ byte.eof f,eof until eof=1 byte.close f if lb=0 then t$=replace$(t$,chr$(10),"") t$=decode$("cp-1251",t$) t$=replace$(t$,"?","") fn.rtn t$ fn.end ! byte. write. байт. записать. fn.def by_w$(w$,t$) t$=encode$("cp-1251",t$) t$=replace$(t$,n$+"?",n$) byte.open w,f,w$ l=len(t$):a=1 do b=ascii(t$,a):a+=1 byte.write.byte f,b until a=l+1 byte.close f fn.rtn t$ fn.end ! 📦 zip unpack. zip распаковать. !f$="f.zip", w$="dir/" fn.def z_u(f$,w$) if fe(f$)=0 then err("⛔ Zip ["+f$+"] not exist.") fol(w$) zip.open r,z,f$ zip.dir f$,f2$[] fn=a_le(f2$[]) for a=1 to fn f_$=f2$[a]:f2_$=f_$:p=1:p2=0:fo=0:t$="EOF" if right$(f_$,1)="/" then fo=1 if fo=0 then zip.read z,t$,f_$ if !t$="EOF" do p=is_in("/",f_$,p) if p>0 then p2=p:p+=1 until p<1 if p2>0 then l=len(f_$):fo$=left$(f_$,p2):fol(w$+fo$) byte.open w,b,w$+f_$ byte.write.buffer b,t$ byte.close b endif next a zip.close z fn.rtn 1 fn.end ! zip pack. zip упаковать. fn.def z_p(w$,li,z$) ?w$ fn.rtn 1 fn.end