I was making a codebase of functions recently. And now I found it time to show off my functions. You may have seen some of the funcions already in my previous posts. But these are ALL of them.
The functions
1- Math
We'll start with the math.
-
round
syntax: round(number#, accuracy)
number#: the max number
accuracy: the number of digits after the comma. (0 = rnd())
`author: SvenB
print round(5.855135,1)
end
function round(nr#,acc)
nr# = nr# * 10^acc
result# = int(nr#)
round_nr# = nr# - result#
if round_nr# > 0.5
inc result#,1
endif
result# = result# / (10^acc)
endfunction result#
-
Modulus
syntax: mod(val1,val2)
the best way is an example:
mod(10,3) = 1 because 10/3 = 3 and 1 that remains.
`author: SvenB
print mod(15,4)
suspend for key
end
`the function
function mod(val1,val2)
val3 = int(val1/val2)
returnval = val1 - (val3 * val2)
endfunction returnval
2- 2D
-
arrows
syntax: arrow(x,y,tx,ty,size,angle#)
x,y: coords of start point
tx,ty: coords of end point
size: size of arrow
angle#: determines the angle of the arrow.
`author: SvenB
sync on
angle# = 0.0
width# = 100.0
height# = 50.0
do
cls
`draw arrow
ink rgb(255,255,255),0
line 320,240,mousex(),mousey()
arrow(320,240,mousex(),mousey(),10,20.0)
sync
loop
`function arrow
function arrow(x,y,x2,y2,size,ang#)
angle# = wrapvalue(270 - atanfull(x2-x,y2-y))
arrow_x1# = cos(angle# + ang#) * size
arrow_y1# = sin(angle# + ang#) * size
arrow_x2# = cos(angle# - ang#) * size
arrow_y2# = sin(angle# - ang#) * size
line x2,y2,x2+arrow_x1#,y2+arrow_y1#
line x2,y2,x2+arrow_x2#,y2+arrow_y2#
endfunction
-
rotated box
syntax: box_rotated(x,y,width,height,angle#)
x,y: coords of the center of the box
width,height: size of the box
angle#: the angle of the box
`author: SvenB
sync on
angle# = 0.0
width# = 100.0
height# = 50.0
do
cls
`draw box
ink rgb(rnd(1)*255,rnd(1)*255,rnd(1)*255),0
box_rotated(320,240,width#,height#,angle#)
angle# = wrapvalue(angle# + 5)
sync
loop
`THE function
function box_rotated(x,y,width#,height#,angle#)
if width# <> 0.0 and height# <> 0.0
ang1# = 2 * atan(width# / height#)
x1# = cos(angle# + ang1#) * (width#/2)
x2# = cos(angle# - ang1#) * (width#/2)
y1# = sin(angle# + ang1#) * (width#/2)
y2# = sin(angle# - ang1#) * (width#/2)
line x+x1#,y+y1#,x-x2#,y-y2#
line x+x1#,y+y1#,x+x2#,y+y2#
line x-x1#,y-y1#,x-x2#,y-y2#
line x-x1#,y-y1#,x+x2#,y+y2#
endif
endfunction
-
dotted line
syntax: dotted_line(x,y,tx,ty,n)
x,y: start coords
tx,ty: end coords
n: number of "smaller" lines.
`author: SvenB
sync on : sync rate 0
do
cls
`draw a dotted line
dotted_line(305,105,mousex(),mousey(),30)
sync
loop
function dotted_line(x1,y1,x2,y2,n)
dx# = x2 - x1
dy# = y2 - y1
for i = 0 to n-1 step 2
px# = dx# / n * i
py# = dy# / n * i
px2# = dx# / n * (i+1)
py2# = dy# / n * (i+1)
line x1 + px#,y1 + py#,x1 + px2#,y1 + py2#
next i
endfunction
3- 3D
-
camera follow
syntax: cam_follow(id,distance#,height#)
id: number of the object
distance#: distance to object
height#: height above object
`author: SvenB
`the function
function follow_camera(id,dist#,height#)
`store id's position and angle
posx#=object position x(id)
posy#=object position y(id)
posz#=object position z(id)
angley#=wrapvalue(object angle y(id)-180)
`calculate camera's position
camx#=newxvalue(posx#,angley#,dist#)
camz#=newzvalue(posz#,angley#,dist#)
camy#=posy# + height#
camx#=curvevalue(camx#,camera position x(),15)
camy#=curvevalue(camy#,camera position y(),15)
camz#=curvevalue(camz#,camera position z(),15)
`update camera
position camera camx#,camy#,camz#
point camera posx#,posy# + (height#/2),posz#
endfunction
-
camera controls
syntax: camcontrols()
standard controls:
mousemovement = rotate
left mouseclick = move forward
right mouseclick = move backward
when controlkey is pressed:
left mouseclick = zoom in
right mouseclick = zoom out
`author: SvenB
`function
function camcontrol()
zoom#=1
do
if controlkey()=0
if mouseclick()=1 then move camera 2
if mouseclick()=2 then move camera -2
anglex# = camera angle x()
angley# = camera angle y()
anglex# = wrapvalue(anglex# + (mousemovey()/2))
angley# = wrapvalue(angley# + (mousemovex()/2))
else
if mouseclick()=1 then dec zoom#,0.05
if mouseclick()=2 then inc zoom#,0.05
endif
if zoom#<0.05 then zoom#=0.05
set camera fov zoom#
rotate camera anglex#,angley#,0
sync
loop
endfunction
-
camera top
syntax: top_camera(id,height#)
id: object to follow
height#: height above object
`author: SvenB
`the function
function top_camera(id, height#)
posx#=object position x(id)
posy#=object position y(id)
posz#=object position z(id)
position camera posx#,posy#+height#,posz#
point camera posx#,posy#,posz#
endfunction
4- Text functions
-
Capitalize
syntax: Cap(string$)
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
input "what's your name? ",name$
print "welcome " + Cap(name$)
suspend for key
end
`the function
function Cap(txt$)
return$ = upper$( mid$(txt$,1) ) + mid3$(txt$, 2, len(txt$)-1)
endfunction return$
function mid3$(txt$,start,length)
return$ = ""
if (start + length - 1) <= len(txt$)
for count = start to start+length - 1
return$ = return$ + mid$(txt$, count)
next count
endif
endfunction return$
-
text in a circle
syntax: circtext(x,y,txt$,radius,start#)
x,y: coords of center
txt$: the text
radius: radius of the circle
start#: start angle
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
do
cls rgb(255,255,255)
ink 0,0
circtext(320,240," this is the function called circtext",100,angle#)
inc angle#,1
sync
loop
`the function
function circtext(x,y,txt$,radius,start#)
for i = 1 to len(txt$)
tx = cos((360 / len(txt$) * (i - 1)) - 90 + start#) * radius
ty = sin((360 / len(txt$) * (i - 1)) - 90 + start#) * radius
text x + tx, y + ty, mid$(txt$,i)
next i
endfunction
-
wave text
syntax: curvetext(x,y,string$,m,q)
x,y: coords of the start point of the text
string$: the text
m: determines the height difference
q: determines the number of waves
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
do
cls rgb(255,255,255)
ink 0,0
curvetext(320,240,"curvetext",20,15,angle#)
inc angle#,10
sync
loop
`the function
function curvetext(x,y,txt$,m,q,start#)
for i = 1 to len(txt$)
ty = sin((m * i) - 90 + start#) * q
text x + text width( mid3$(txt$,1,i-1) ), y + ty, mid$(txt$,i)
next i
endfunction
function mid3$(txt$,start,length)
return$ = ""
if (start + length - 1) <= len(txt$)
for count = start to start+length - 1
return$ = return$ + mid$(txt$, count)
next count
endif
endfunction return$
-
effect1
syntax: effect1(x,y,text$,color1,color2)
x,y: start coords
text$: the text
color1,color2: from color1 -> color2
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
do
cls rgb(255,255,255)
effect1(50,50,"this is effect1",rgb(255,255,0),rgb(255,0,0))
sync
loop
`the function
function effect1(x,y,txt$,color1,color2)
redf = rgbr(color2) - rgbr(color1)
greenf = rgbg(color2) - rgbg(color1)
bluef = rgbb(color2) - rgbb(color1)
for i = 1 to len(txt$)
red = rgbr(color1) + (redf / len(txt$) * i)
green = rgbg(color1) + (greenf / len(txt$) * i)
blue = rgbb(color1) + (bluef / len(txt$) * i)
ink rgb(red, green, blue),0
text x + text width( mid3$(txt$,1,i-1) ), y, mid$(txt$, i)
next i
endfunction
function mid3$(txt$,start,length)
return$ = ""
if (start + length - 1) <= len(txt$)
for count = start to start+length - 1
return$ = return$ + mid$(txt$, count)
next count
endif
endfunction return$
-
effect2
syntax: effect2(x,y,text$,color1,color2)
x,y: start coords
text$: the text
color1,color2: color1 with a color2 border
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
do
cls rgb(255,255,255)
effect2(320,240,"this is effect2", rgb(255,255,0), rgb(0,0,255))
sync
loop
`the function
function effect2(x,y,txt$,color1,color2)
ink color2,0
text x-1,y-1,txt$ : text x-1,y,txt$
text x+1,y+1,txt$ : text x+1,y,txt$
text x,y-1,txt$ : text x,y+1,txt$
ink color1,0
text x,y,txt$
endfunction
-
mid2$
syntax: mid2$(text$,start)
text$: the text
start: from this character to the last one will be returned.
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
print mid2$("abcdehi there",6)
suspend for key
end
`the function
function mid2$(txt$,start)
return$ = ""
for x = start to len(txt$)
return$ = return$ + mid$(txt$, x)
next x
endfunction return$
-
mid3$
syntax: mid3$(txt$,start,length)
txt$: the text
start: start from this character
length: the length of the string that will be returned.
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
print mid2$("abcdehi there",6)
suspend for key
end
`the function
function mid2$(txt$,start)
return$ = ""
for x = start to len(txt$)
return$ = return$ + mid$(txt$, x)
next x
endfunction return$
-
text reversed
syntax: reverse$(text$)
the text will be reversed.
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
print reverse$("?gniod uoy era woh")
suspend for key
end
`the function
function reverse$(txt$)
return$ = ""
for x = len(txt$) to 1 step -1
return$ = return$ + mid$(txt$, x)
next x
endfunction return$
-
shadow text
syntax: shadow(x,y,text$,color)
x,y: coords of the text
text$: the text
color: the color of the text
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
do
cls rgb(255,255,255)
shadow(320,240,"this is text with a shadow",rgb(0,0,255))
sync
loop
`the function
function shadow(x,y,txt$,color)
ink rgb(5,5,5),0
text x-1,y+1,txt$
ink color,0
text x,y,txt$
endfunction
-
colored text
syntax: textcolors(x,y,text$)
x,y: the coords of the text
text$: the text
`Author: SvenB
sync on
hide mouse
set text font "Comic Sans MS"
set text size 20
do
cls rgb(255,255,255)
textcolors(320,240,"this is the function called textcolors")
sync
loop
`the function
function textcolors(x,y,txt$)
tx = text width(txt$)
for i = 1 to len(txt$)
repeat
color = rgb(rnd(1) * 255, rnd(1) * 255, rnd(1) * 255)
until color <> 0
ink color,0
text x + text width( mid3$(txt$,1,i-1) ), y, mid$(txt$, i)
next i
endfunction
function mid3$(txt$,start,length)
return$ = ""
if (start + length - 1) <= len(txt$)
for count = start to start+length - 1
return$ = return$ + mid$(txt$, count)
next count
endif
endfunction return$
5- Misc
-
browserwindow
syntax: browser_window(x,y,sizex,sizey,startdir$,color,move,resize)
x,y: coords of the window
sizex,sizey: size of the window
startdir$: the starting directory
color: the color theme
move,resize: 1: the window is movable/resizable.0 it isn't
`author: SvenB
sync on
for i = 1 to 10
x = rnd(640)
y = rnd(480)
ink rgb(0,0,255),0
box x,y,x + rnd(50),y + rnd(50)
next i
file$ = browser_window(20,10,200,300,"C:\",rgb(255,255,0),1,1)
cls
print file$
suspend for key
end
`************
`the function
`************
function browser_window(posx, posy, sizex, sizey, firstdir$, color1, resize, move)
`preparations
set text font "Arial" : set text size 16
` if sizex < 150 then sizex = 150
` if sizey < 100 then sizey = 100
dir$ = firstdir$
set dir firstdir$
perform checklist for files
`get background
get image 65535,0,0,screen width(),screen height()
y = 0
oldmousez = mousemovez()
mousez = mousemovez()
show mouse
do
`boundries
if posx < 0 then posx = 0
if posy < 0 then posy = 0
if sizex > screen width() - 1 then sizex = screen width() - 1
if sizey > screen height() - 1 then sizey = screen height() - 1
`paste background
paste image 65535,0,0
`handle mousemovez
mousez = mousemovez()
if mousez <> oldmousez
dec y, (oldmousez - mousez) / 30
oldmousez = mousez
endif
`scroll
maxy = (checklist quantity() - 1) * 17 + 16
if y < (maxy - (sizey - 50)) * -1 then y = (maxy - (sizey - 50)) * -1
if y > 0 then y = 0
`make main window
ink rgb(255,255,255),0
endx = posx + sizex
endy = posy + sizey
if endx > screen width()-1 then endx = screen width()-1
if endy > screen height()-1 then endy = screen height()-1
box posx, posy, endx - 1, endy - 1
ink rgb(10, 10, 10), 0
box posx + 1, posy + 1, endx, endy
ink color1,0
box posx + 1, posy + 1, endx-1, endy-1
`make directory
ink rgb(10, 10, 10), 0
endx = posx + sizex - 5
endy = posy + 25
if endx > screen width()-1 then endx = screen width()-1
if endy > screen height()-1 then endy = screen height()-1
box posx + 5, posy + 5, endx - 1, endy - 1
ink rgb(200,200,200),0
box posx + 6, posy + 6, endx, endy
ink rgb(255,255,255),0
box posx + 6, posy + 6, endx - 1, endy - 1
`display directory
ink 0,0 : dispdir$ = ""
for i = 1 to len(dir$)
if text width(dispdir$) < sizex - 20
dispdir$ = dispdir$ + mid$(dir$, i)
endif
next i
text posx + 7, posy + 6, dispdir$
`make file window
endx = posx + sizex - 5
endy = posy + sizey - 5
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
ink rgb(10, 10, 10), 0
box posx + 5, posy + 30, endx - 1, endy - 1
ink rgb(200,200,200),0
box posx + 6, posy + 31, endx, endy
ink rgb(255,255,255),0
box posx + 6, posy + 31, endx - 1, endy - 1
`display files
find first : find next
name$ = get file name$()
if y => 0
if textbutton(posx + 7, posy + 40 + y, "parent", color1) > 0 and hold = 0
hold = 1
if get file type() = 1
dir$ = dir$ + "\" + name$
set dir dir$
dir$ = get dir$()
set dir dir$
perform checklist for files
y = 0
endif
endif
endif
for file = 2 to checklist quantity() - 1
find next : name$ = ""
for char = 1 to len(get file name$())
if text width(name$) < sizex - 18
name$ = name$ + mid$(get file name$(), char)
endif
next char
fileposy = y + ((file - 1) * 17)
if fileposy > 0 and fileposy < sizey - 50
if textbutton(posx + 7, posy + 40 + fileposy, name$, color1) > 0 and hold = 0
hold = 1
if get file type() = 1
if path exist( dir$ + "\" + get file name$() ) > 0
set dir dir$ + "\" + get file name$()
dir$ = get dir$()
perform checklist for files
y = 0
endif
else
filename$ = dir$ + "\" + get file name$()
exitfunction filename$
endif
endif
endif
next file
`move window
if move = 1
if mousex() > posx and mousex() < posx + sizex
if mousey() > posy and mousey() < posy + 10
if mouseclick() = 1 and moving = 0
difx = mousex() - posx
dify = mousey() - posy
moving = 1
endif
endif
endif
if moving = 1
posx = mousex() - difx
posy = mousey() - dify
if mouseclick() = 0 then moving = 0
endif
endif
`resize window
if resize = 1
if mousex() > posx + sizex - 5 and mousex() > posx + sizex
if mousey() > posy + 10 and mousey() < posy + sizey - 5
if mouseclick() = 1 and resising = 0
resising = 1
endif
endif
endif
if mousex() > posx and mousex() < posx + sizex - 5
if mousey() > posy + sizey - 5 and mousey() < posy + sizey
if mouseclick() = 1 and resising = 0
resising = 2
endif
endif
endif
if mousex() > posx + sizex - 5 and mousex() < posx + sizex
if mousey() > posy + sizey - 5 and mousey() < posy + sizey
if mouseclick() = 1 and resising = 0
resising = 3
endif
endif
endif
select resising
case 1
sizex = sizex + mousemovex()
endcase
case 2
sizey = sizey + mousemovey()
endcase
case 3
sizex = sizex + mousemovex()
sizey = sizey + mousemovey()
endcase
endselect
if resising > 0 and mouseclick() = 0 then resising = 0
endif
`unlock mouse
if mouseclick() = 0 then hold = 0
sync
loop
endfunction filename$
function textbutton(x, y, text$, color)
tx = text width(text$)
ty = text height(text$)/2
pressed = 0
if mousex() > x and mousex() < x + tx
if mousey() < y + ty and mousey() > y - ty
pressed = 1
endif
endif
if pressed = 1 then ink color,0 else ink rgb(0,0,0),0
text x, y - (text size()/2), text$
if mouseclick() = 0 then pressed = 0
endfunction pressed
-
calculator
syntax: calc(x,y,color,move)
x,y: coords of window
color: color theme
move: 1 = the window is movable.
`author: SvenB
sync on
a = calc(10,10,rgb(200,200,200),1)
ink rgb(255,255,255),0
print a
suspend for key
end
`the function
function calc(posx, posy, color, move)
`preparations
get image 65535,0,0,screen width(),screen height()
defaultfont$ = text font$()
defaultsize = text size()
defaultstyle = text style()
defaultback = text background type()
dim number$(2)
cnumber = 1
answer$ = ""
display$ = ""
operator = 0
set text font "Fixedsys"
set text size 16
set text to normal
set text transparent
`start loop
do
`background save
paste image 65535,0,0
`main window
endx = posx + 120
endy = posy + 120
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
ink rgb(255,255,255),0
box posx, posy, endx - 1, endy - 1
ink rgb(10,10,10),0
box posx + 1, posy + 1, endx, endy
ink color,0
box posx + 1, posy + 1, endx - 1, endy - 1
`display
endx = posx + 115
endy = posy + 25
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
ink rgb(10,10,10),0
box posx + 5, posy + 5, endx - 1, endy - 1
ink rgb(255,255,255),0
box posx + 6, posy + 6, endx, endy
ink rgb(255,255,255),0
box posx + 6, posy + 6, endx - 1, endy - 1
ink 0,0
display$ = number$(cnumber)
if display$ = "" then display$ = "0"
text posx + 6, posy + 6, display$
`calc_buttons
for x = 1 to 3
for y = 1 to 3
nr = ((x-1)*3) + y
if calc_button((posx + 5) + ((y-1)*21), (posy + 30) + ((x-1)*21), str$(nr), color) > 0 and hold = 0 and len(number$(cnumber)) < 10
if operator = 5 then operator = 0 : number$(1) = ""
hold = 1
number$(cnumber) = number$(cnumber) + str$(nr)
endif
next y
next x
if calc_button(posx + 5, posy + 93, "0", color) > 0 and hold = 0 and len(number$(cnumber)) < 10
if operator = 5 then operator = 0 : number$(1) = ""
hold = 1
number$(cnumber) = number$(cnumber) + "0"
endif
if calc_button(posx + 26, posy + 93,".", color) > 0 and hold = 0 then hold = 1 : number$(cnumber) = number$(cnumber) + "."
`operators
if calc_button(posx + 68, posy + 30, "CA", color) > 0 and hold = 0
hold = 1
number$(1) = ""
number$(2) = ""
operator = 0
endif
if calc_button(posx + 68, posy + 51, "+", color) > 0 and hold = 0
hold = 1
if cnumber = 1
inc cnumber
number$(2) = ""
else
first# = val(number$(1))
sec# = val(number$(2))
select operator
case 1 : number$(1) = str$(first# + sec#) : endcase
case 2 : number$(1) = str$(first# - sec#) : endcase
case 3 : number$(1) = str$(first# * sec#) : endcase
case 4 : number$(1) = str$(first# / sec#) : endcase
endselect
if len(number$(1)) > 10 then number$(1) = "ERROR"
number$(2) = ""
endif
operator = 1
endif
if calc_button(posx + 68, posy + 72, "-", color) > 0 and hold = 0
hold = 1
if cnumber = 1
inc cnumber
number$(2) = ""
else
first# = val(number$(1))
sec# = val(number$(2))
select operator
case 1 : number$(1) = str$(first# + sec#) : endcase
case 2 : number$(1) = str$(first# - sec#) : endcase
case 3 : number$(1) = str$(first# * sec#) : endcase
case 4 : number$(1) = str$(first# / sec#) : endcase
endselect
if len(number$(1)) > 15 then number$(1) = "ERROR"
number$(2) = ""
endif
operator = 2
endif
if calc_button(posx + 89, posy + 51, "*", color) > 0 and hold = 0
hold = 1
if cnumber = 1
inc cnumber
number$(2) = ""
else
first# = val(number$(1))
sec# = val(number$(2))
select operator
case 1 : number$(1) = str$(first# + sec#) : endcase
case 2 : number$(1) = str$(first# - sec#) : endcase
case 3 : number$(1) = str$(first# * sec#) : endcase
case 4 : number$(1) = str$(first# / sec#) : endcase
endselect
if len(number$(1)) > 15 then number$(1) = "ERROR"
number$(2) = ""
endif
operator = 3
endif
if calc_button(posx + 89, posy + 72, "/", color) > 0 and hold = 0
hold = 1
if cnumber = 1
inc cnumber
else
first# = val(number$(1))
sec# = val(number$(2))
select operator
case 1 : number$(1) = str$(first# + sec#) : endcase
case 2 : number$(1) = str$(first# - sec#) : endcase
case 3 : number$(1) = str$(first# * sec#) : endcase
case 4 : number$(1) = str$(first# / sec#) : endcase
endselect
if len(number$(1)) > 15 then number$(1) = "ERROR"
number$(2) = ""
endif
operator = 4
endif
if calc_button(posx + 47, posy + 93, "-#", color) > 0 and hold = 0 and len(number$(cnumber)) = 0
hold = 1
number$(cnumber) = number$(cnumber) + "-"
endif
if calc_button(posx + 89, posy + 93, "=", color) > 0 and hold = 0 and cnumber = 2
cnumber = 1
first# = val(number$(1))
sec# = val(number$(2))
select operator
case 1 : number$(1) = str$(first# + sec#) : endcase
case 2 : number$(1) = str$(first# - sec#) : endcase
case 3 : number$(1) = str$(first# * sec#) : endcase
case 4 : number$(1) = str$(first# / sec#) : endcase
endselect
if len(number$(1)) > 15 then number$(1) = "ERROR"
operator = 5
endif
`exit calc_button
if calc_button(posx + 89, posy + 30, "EX", color) > 0 and hold = 0 then hold = 1 : exit
`unlock mouse
if mouseclick() = 0 then hold = 0
`if moving is allowed
if move = 1
if mousex() > posx and mousex() < posx + 120
if mousey() > posy and mousey() < posy + 5
if mouseclick() = 1 and moving = 0
moving = 1
difx = mousex() - posx
dify = mousey() - posy
endif
endif
endif
if moving = 1
posx = mousex() - difx
posy = mousey() - dify
if mouseclick() = 0 then moving = 0
endif
endif
`boundries
if posx < 0 then posx = 0
if posy < 0 then posy = 0
if posx > screen width() - 1 then posx = screen width() - 1
if posy > screen height() - 1 then posy = screen height() - 1
sync
loop
`reset all
cls
set text font defaultfont$
set text size defaultsize
select defaultstyle
case 1 : set text to italic : endcase
case 2 : set text to bold : endcase
case 3 : set text to bolditalic : endcase
endselect
if defaultback = 1
set text transparent
else
set text opaque
endif
endfunction val(number$(1))
function calc_button(x,y,content$,color)
pressed = 0
`layout
if mousex() < x + 20 and mousex() > x
if mousey() < y + 20 and mousey() > y
if mouseclick() = 1 then pressed = 1
endif
endif
endx = x + 20
endy = y + 20
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
if pressed = 1
ink rgb(20,20,20),0
box x, y, endx - 1, endy - 1
ink rgb(255,255,255),0
box x + 1, y + 1, endx, endy
else
ink rgb(20,20,20),0
box x + 1, y + 1, endx, endy
ink rgb(255,255,255),0
box x, y, endx - 1, endy - 1
endif
ink color,0
box x + 1, y + 1, endx - 1, endy - 1
ink 0,0
center text x + 10, y + 10 - (text size()/2), content$
endfunction pressed
-
inputbox
syntax: inputprompt(x,y,maxc,color)
x,y: coords of the window
maxc: maximum number of chars
color: color theme
`author: SvenB
sync on
a$ = inputprompt(100,100,50,rgb(200,200,200))
cls
ink rgb(255,255,255),0
print a$
suspend for key
end
`**************
`the function
`**************
function inputprompt(posx, posy, maxc, color)
`preparations
set text size 16
for i = 1 to maxc
teststring$ = teststring$ + "X"
next i
sizex = text width(teststring$) + 12
string$ = ""
oldkey$ = ""
do
`main window
endx = posx + sizex
endy = posy + 60
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
ink rgb(255,255,255),0
box posx, posy, endx - 1, endy - 1
ink rgb(rgbr(color)/2,rgbg(color)/2,rgbb(color)/2),0
box posx + 1, posy + 1, endx, endy
ink color,0
box posx + 1, posy + 1, endx - 1, endy - 1
`inputbox
endx = posx + sizex - 5
endy = posy + 25
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
ink rgb(rgbr(color)/2,rgbg(color)/2,rgbb(color)/2),0
box posx + 5, posy + 5, endx - 1, endy - 1
ink rgb(200,200,200),0
box posx + 6, posy + 6, endx, endy
ink rgb(255,255,255),0
box posx + 6, posy + 6, endx - 1, endy - 1
`text in inputbox
ink 0,0
text posx + 6, posy + 6, string$
`make 2 buttons
if 3Dbutton(posx + 6, posy + 35, 60, 20, "OK", color) > 0
ok = 1
endif
if 3Dbutton(posx + 81, posy + 35, 60, 20, "Cancel", color) > 0
cancel = 1
endif
if mouseclick() = 0
if ok = 1
cls
exitfunction string$
endif
if cancel = 1
cls
string$ = ""
exitfunction string$
endif
endif
`input
if oldkey$ <> inkey$()
if asc(inkey$()) <> 8
string$ = string$ + inkey$()
else
if len(string$) > 0
temp$ = ""
for i = 1 to len(string$) - 1
temp$ = temp$ + mid$(string$,i)
next i
string$ = temp$
endif
endif
oldkey$ = inkey$()
endif
sync
loop
endfunction string$
function 3Dbutton(x, y, width, height, content$, color)
pres = 0
endx = x + width
endy = y + height
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
if mousex() > x and mousex() < endx
if mousey() > y and mousey() < endy
if mouseclick() = 1 then pres = 1
endif
endif
if pres = 1
ink rgb(rgbr(color)/2,rgbg(color)/2,rgbb(color)/2),0
box x, y, endx - 1, endy - 1
ink rgb(255,255,255),0
box x + 1, y + 1, endx, endy
else
ink rgb(rgbr(color)/2,rgbg(color)/2,rgbb(color)/2),0
box x + 1, y + 1, endx, endy
ink rgb(255,255,255),0
box x, y, endx - 1, endy - 1
endif
ink color,0
box x + 1, y + 1, endx - 1, endy - 1
ink 0,0
center text x + (width/2), y + (height/2) - (text size()/2), content$
endfunction pres
-
LoadMedia (DBC version)
syntax: LoadMedia()
load all the media in the current folder.
(To change the folder: use the cd or set dir command)
`************************************************
` Media loader
`author: SvenB
`************************************************
sync on
LoadMedia()
suspend for key
end
function LoadMedia()
perform checklist for files
obj = 1 : bmp = 1 : avi = 1 : snd = 1 : mus = 1
find first
for x = 1 to checklist quantity()
find next
name$ = get file name$()
l = len( name$ )
ext$ = mid$( name$, l - 2 ) + mid$( name$, l - 1 ) + mid$( name$, l )
if lower$( ext$ ) = "mid" then load music name$,mus : inc mus
if lower$( ext$ ) = "3ds" then load object name$,obj : inc obj
if lower$( ext$ ) = "avi" then load animation name$,ani : inc ani
if lower$( ext$ ) = "wav" then load sound name$,snd : inc snd
if lower$( ext$ ) = mid$(name$, l-2) + ".x" then load object name$,obj : inc obj
if lower$( ext$ ) = "mp3" then load music name$,mus : inc mus
if lower$( ext$ ) = "bmp" then load image name$,bmp : inc bmp
if lower$( ext$ ) = "jpg" then load image name$,bmp : inc bmp
next x
endfunction
-
Clock
syntax: clock(x,y,size)
x,y: center of clock
size: size of the clock
`author: SvenB
sync on
do
cls
clock(320,240,100,rgb(255,255,255))
sync
loop
`the function
function clock(x,y,size,color)
`border
ink color,0
circle x, y, size / 2
for i = 1 to 60
dx = x + (cos(6 * i - 90) * (size/2 - 2))
dy = y + (sin(6 * i - 90) * (size/2 - 2))
dot dx,dy
next i
`get time
time$ = get time$()
hours = val(mid$(time$,1) + mid$(time$, 2))
minutes = val(mid$(time$,4) + mid$(time$, 5))
seconds = val(mid$(time$,7) + mid$(time$, 8))
`draw:
`- hours
hx = x + (cos((30*hours) + (0.5*minutes) - 90) * (size/4))
hy = y + (sin((30*hours) + (0.5*minutes) - 90) * (size/4))
line x,y,hx,hy
`- minutes
mx = x + (cos((6*minutes) - 90) * (size/8*3))
my = y + (sin((6*minutes) - 90) * (size/8*3))
line x,y,mx,my
`- seconds
sx = x + (cos((6*seconds) - 90) * (size/9*4))
sy = y + (sin((6*seconds) - 90) * (size/9*4))
line x,y,sx,sy
endfunction
-------------------------------------------------------------
That was all.
No credit required.
REQUEST
!!!! Please post your functions on this thread !!!!
Thanks for your attention
cheers!
Immunity and Annihalation makes Immunihalation...