ArcBasicDocs

tutorials/beginner

08_functions.abs

43 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.

Download 08_functions.absAll files in this folder

08_functions.abs
; Functions: name a job once, then use it as often as you likeGraphics 640, 480SetBuffer BackBuffer()Global frames = 0       ; Global: every function can see itWhile Not KeyHit(1)	frames = frames + 1	Cls	; three ships, drawn by one function	DrawShip(100, 300, 255, 80, 80)	DrawShip(300, 200 + Wobble(40), 80, 255, 80)	DrawShip(500, 300, 80, 160, 255)	Color 255, 255, 255	Text 320, 20, "Three ships, one DrawShip function", True	Text 320, 40, "The distance between the outer ships is " + Distance(100, 300, 500, 300), True	FlipWendEnd; Draws a ship at x,y in the colour r,g,bFunction DrawShip(x, y, r, g, b)	Color r, g, b	Rect x, y + 10, 40, 20	Rect x + 15, y, 10, 10	Color 255, 140, 0	Rect x + 5, y + 30, 6, 6	Rect x + 29, y + 30, 6, 6End Function; Gives back a number that swings smoothly between -size and sizeFunction Wobble(size)	Return Sin(frames * 3) * sizeEnd Function; Gives back how far apart two points areFunction Distance#(x1#, y1#, x2#, y2#)	dx# = x2 - x1	dy# = y2 - y1	Return Sqr(dx * dx + dy * dy)End Function