Let's start with the #include statement. You may recognise it from other programming languages, and it works in just the same way. It allows you to compile external functions (as source code) into your project.
For example, here are some functions. We want to use them, but they might clutter up the main program.
set display mode 1024,768,32
drawbutton(200,200,400,320,8,RGB(255,0,0),RGB(0,255,0),RGB(0,0,255),RGB(128,128,128))
hollowrect(500,50,550,100)
dust(800,100,80,600)
galaxy(512,600,1024,400,3,5,100000,30,100,RGB(255,127,0))
filledcirc(100,100,50,30)
wait key : end
function filledcirc(X as integer, Y as integer, Xrad as integer, YRad as integer)
ax as integer
ay as integer
For ax = X-XRad to X+XRad
For ay = Y-YRad to Y+YRad
If ((ax-x)*(ax-x)*YRad*YRad)+((ay-y)*(ay-y)*XRad*XRad)<(XRad*XRad*YRad*YRad) then dot ax,ay
Next ay
Next ax
endfunction
function drawbutton(aX as integer, aY as integer, bX as integer, bY as integer,thickness as integer,ColorA as integer,ColorB as integer,ColorC as integer,ColorD as integer)
BOX aX,aY,bx,by,ColorC,ColorA,ColorD,ColorB
t as integer
u as integer
r1 as integer
g1 as integer
b1 as integer
r2 as integer
g2 as integer
b2 as integer
r3 as integer
g3 as integer
b3 as integer
maxi as integer
mini as integer
For t = 1 to thickness
`verticals (left)
r1 = rgbr(ColorA)
r2 = rgbr(ColorC)
g1 = rgbg(ColorA)
g2 = rgbg(ColorC)
b1 = rgbb(ColorA)
b2 = rgbb(ColorC)
maxi = bY-aY+1-t
mini = t-1
For u = mini to maxi
r3 = ((r1*(maxi-u)+r2*(u-mini))/(maxi-mini))+64
g3 = ((g1*(maxi-u)+g2*(u-mini))/(maxi-mini))+64
b3 = ((b1*(maxi-u)+b2*(u-mini))/(maxi-mini))+64
If r3>255 then r3=255
If g3>255 then g3=255
IF b3>255 then b3=255
DOT ax+t-1,u+ay,RGB(r3,g3,b3)
Next u
`verticals (right)
r1 = rgbr(ColorB)
r2 = rgbr(ColorD)
g1 = rgbg(ColorB)
g2 = rgbg(ColorD)
b1 = rgbb(ColorB)
b2 = rgbb(ColorD)
maxi = bY-aY+1-t
mini = t-1
For u = mini to maxi
r3 = ((r1*(maxi-u)+r2*(u-mini))/(maxi-mini))-64
g3 = ((g1*(maxi-u)+g2*(u-mini))/(maxi-mini))-64
b3 = ((b1*(maxi-u)+b2*(u-mini))/(maxi-mini))-64
If r3<0 then r3=0
If g3<0 then g3=0
IF b3<0 then b3=0
DOT bx-t+1,u+ay,RGB(r3,g3,b3)
Next u
`horizontals (top)
r1 = rgbr(ColorA)
r2 = rgbr(ColorB)
g1 = rgbg(ColorA)
g2 = rgbg(ColorB)
b1 = rgbb(ColorA)
b2 = rgbb(ColorB)
maxi = bX-aX+1-t
mini = t-1
For u = mini to maxi
r3 = ((r1*(maxi-u)+r2*(u-mini))/(maxi-mini))+64
g3 = ((g1*(maxi-u)+g2*(u-mini))/(maxi-mini))+64
b3 = ((b1*(maxi-u)+b2*(u-mini))/(maxi-mini))+64
If r3>255 then r3=255
If g3>255 then g3=255
IF b3>255 then b3=255
DOT u+ax,ay+t-1,RGB(r3,g3,b3)
Next u
`horizontals (bottom)
r1 = rgbr(ColorC)
r2 = rgbr(ColorD)
g1 = rgbg(ColorC)
g2 = rgbg(ColorD)
b1 = rgbb(ColorC)
b2 = rgbb(ColorD)
maxi = bX-aX+1-t
mini = t-1
For u = mini to maxi
r3 = ((r1*(maxi-u)+r2*(u-mini))/(maxi-mini))-64
g3 = ((g1*(maxi-u)+g2*(u-mini))/(maxi-mini))-64
b3 = ((b1*(maxi-u)+b2*(u-mini))/(maxi-mini))-64
If r3<0 then r3=0
If g3<0 then g3=0
IF b3<0 then b3=0
DOT u+ax,by-t+1,RGB(r3,g3,b3)
Next u
next t
endfunction
function hollowrect(X1 as integer,Y1 as integer,X2 as integer,Y2 as integer)
Line X1,Y1,X1,Y2
Line X1,Y1,X2,Y1
Line X2,Y2,X1,Y2
Line X2,Y2,X2,Y1
endfunction
function dust(X as integer,Y as integer,Radius as double float,Frequency as integer)
t as integer
angle as double float
distance as double float
For t = 1 to frequency
angle=rnd(36000)/100
distance=rnd(Radius*100)/100
DOT X+(distance*SIN(angle)),Y+(distance*COS(angle))
Next t
endfunction
function galaxy(Xcentre as double float, Ycentre as double float, pixwidth as double float, pixheight as double float, t as integer, s as double float, v as integer, u as double float, arm as double float, colorshift as dword)
INK RGB(255,255,255),0
a as double float
b as double float
c as double float
redshift as integer
greenshift as integer
blueshift as integer
xcoord as integer
ycoord as integer
rdiff as integer
gdiff as integer
bdiff as integer
height as double float
width as double float
redshift=RGBR(colorshift)
greenshift=RGBG(colorshift)
blueshift=RGBB(colorshift)
height = pixheight/200
width = pixwidth/200
LOCK PIXELS
For x = 1 to v
a = rnd(10000.0)/1000.0 : b=a*a : c=rnd(3600.0)
b=(b*SIN(c*t))*INT(rnd(3))*arm/300.0
c=c+(u*SIN(rnd(10000)))
If b<0 then b=0
xcoord=(b*width*SIN(c+s*b))+xcentre
ycoord=(b*height*COS(c+s*b))+ycentre
rdiff=40000/((b)^1.5)
gdiff=40000/((b)^1.5)
bdiff=40000/((b)^1.5)
bdiff=bdiff+blueshift
gdiff=gdiff+greenshift
rdiff=rdiff+redshift
If rdiff>255 then rdiff=255
If gdiff>255 then gdiff=255
If bdiff>255 then bdiff=255
DOT xcoord,ycoord,RGB(rdiff,gdiff,bdiff)
Next x
BOX xcentre-2,ycentre-2,xcentre+2,ycentre+2
unlock pixels
`An impressive galaxy in just 20 lines of code!
`s = spiral intensity (higher means it is more curved)
`t = number of arms
`u = edge width of arms (higher means it blends in better)
`v = number of stars in galaxy (100000 is optimal)
`arm = arm length (in percent), 100 is optimum
`width = galaxy width (5 = width of screen when arm = 100%)
`height = galaxy height (3.75 = height of screen when arm = 100%)
endfunction
To include these, we save them as a file in the current project folder.
Let's call it drawfuncts.dba
We have a main program, here is an example: (not a program that actually does anything)
Set display mode 1024,768,32
We now need to load them in from our main program.
#include "drawfuncts.dba"
We can now use these functions, For example, we can put this into our main program:
galaxy(512,600,1024,400,3,5,100000,30,100,RGB(0,127,255))
This will generate a turqoise galaxy in 3 lines:
Set display mode 1024,768,32
#include "drawfuncts.dba"
galaxy(512,600,1024,400,3,5,100000,30,100,RGB(0,127,255))
Feel free to use any of the attached functions, and you can #include functions from anybody's source. Useful when you have lots of code.
Your signature has been erased by a hyper-intelligent pan-dimensional being (a mod)