; Functions: name a job once, then use it as often as you like Graphics 640, 480 SetBuffer BackBuffer() Global frames = 0 ; Global: every function can see it While 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 Flip Wend End ; Draws a ship at x,y in the colour r,g,b Function 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, 6 End Function ; Gives back a number that swings smoothly between -size and size Function Wobble(size) Return Sin(frames * 3) * size End Function ; Gives back how far apart two points are Function Distance#(x1#, y1#, x2#, y2#) dx# = x2 - x1 dy# = y2 - y1 Return Sqr(dx * dx + dy * dy) End Function