# Random World Map

``` BBS: Inland Empire Archive
Date: 05-09-92 (11:07)             Number: 168
From: JEFF FREEMAN                 Refer#: NONE
To: ALL                           Recvd: NO
Subj: Random World Map               Conf: (2) Quik_Bas```
```
Someone asked earlier about making a random map.  Here's a little ditty
for generating random land-masses.  This is setup for text-mode, but you
could easily change it to PSET's instead of PRINT's and even save it in
a RAF.  If you're using XLOC and YLOC for grid coordinates, MAXXY for
the limit of XLOC and YLOC (so if you want a map that's 100 x 100 then
MAXXY = 100) then here's how you determine the record # of a given grid
coordinate:

RecNum = ((XLOC-1)*MAXXY)-YLOC

If you want a wrap-around map then use the ABSLOC function:

FUNCTION ABSLOC(XYLOC)
Select case XYLOC
case is > MAXXY
ABSLOC = XYLOC - MAXXY
case is < 1
ABSLOC = XYLOC + MAXXY
case else
ABSLOC = XYLOC
end select
end function

Then call the function like this:

RecNum = ((AbsLoc(XLOC)-1)*MaxXY)-AbsLoc(YLoc)

Okay... sorry this is sloppy, I just wrapped it out.  Here's the actual
land-mass generation thing.  This uses a function called DIST, which
returns the distance from one grid location to another grid location.

DECLARE FUNCTION DIST% (X1%, Y1%, X2%, Y2%)
DEFINT A-Z
RANDOMIZE TIMER
CLS
FOR Landmass = 1 TO 9    'the number of land-masses desired
F1X = FIX(RND * 23) + 1: F2X = FIX(RND * 15) + F1X - 7
F1Y = FIX(RND * 78) + 1: F2Y = FIX(RND * 15) + F1Y - 7
'play with the above to make vastly larger land-masses
Size = DIST(F1X, F1Y, F2X, F2Y) + FIX(RND * 10) + 1
LoX = LoX: LoY = F1Y: HiX = F2X: HiY = F2Y
IF F1X > F2X THEN SWAP LoX, HiX

IF F1Y > F2Y THEN SWAP LoY, HiY
FOR PX = LoX - Size / 3 TO HiX + Size / 3
FOR PY = LoY - Size / 3 TO HiY + Size / 3
D1 = DIST(PX, PY, F1X, F1Y): D2 = DIST(PX, PY, F2X, F2Y)
IF (D1 + D2) <= Size THEN
XX = PX: YY = PY
IF XX > 23 THEN XX = XX - 23     'These won't be necessary if
IF XX < 2 THEN XX = XX + 23      ' you're using the ABSLOC
IF YY > 78 THEN YY = YY - 78     ' function.
IF YY < 2 THEN YY = YY + 78      '
LOCATE XX, YY: PRINT "+";
END IF
NEXT PY, PX
NEXT Landmass
BEEP: A\$ = INPUT\$(1)  'just to letcha know it's done

FUNCTION DIST (X1, Y1, X2, Y2)
Dist1 = X1 - X2: Dist2 = Y1 - Y2
DIST = SQR((Dist1 ^ 2) * (Dist2 ^ 2))
END FUNCTION

There are vast improvements to be made, especially where speed is
concerned...  This sucker is slow as all heck.  Also need something to
give the land masses raggly-edges.  The basic premise is to select to
coordinates as your Foci.  Then select a distance which is greater than
the distance between Focus 1 and Focus 2.  Then following the definition
of an ellipse, the sum of the distances from Focus 1 to Focus 2 is the
border of the land-mass. "Fill in" all of the squares within that
border.

... OFFLINE 1.36 * Ross Perot and what's-his name, 1992.
---
* Origin: Camelot BBS - Dallas, TX - (214) 339-8283 (1:124/1011)
```

Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET