def PerformTectonics(self):
self.plateMap = array('i')
doneMap = array('b') #use a little extra memory to speed this operation up
#initialize map with zeros
for i in range(0,self.mapHeight*self.mapWidth):
self.plateMap.append(0)
doneMap.append(False)
#seed plates
randomPlates = PWRand.randint(3,5)
numberOfPlates = self.mapWidth / randomPlates
randomRegions = True
topGap = int(self.mapHeight * (1.0 - self.polarGap * 0.5))
botGap = int(self.mapHeight * self.polarGap)
#The regions work by defining their portion of the map and removing plates
#in those regions.
#Default plate placement
for x in range(1,numberOfPlates + 1):
i = PWRand.randint(0,self.mapWidth*self.mapHeight - 1)
if self.plateMap[i] == 0:
self.plateMap[i] = x
if randomRegions == True:
regionSelect = PWRand.randint(1,3)
if regionSelect < 2:
#Western Region
iSouthY = int(botGap)
iNorthY = int(topGap) - 1
iHeight = iNorthY - iSouthY + 1
iWestX = int(self.mapWidth * 0.1)
iEastX = int(self.mapWidth * 0.4) - 1
iWidth = iEastX - iWestX + 1
elif regionSelect < 3:
#Eastern Region
iSouthY = int(botGap)
iNorthY = int(topGap) - 1
iHeight = iNorthY - iSouthY + 1
iWestX = int(self.mapWidth * 0.6)
iEastX = int(self.mapWidth * 0.9) - 1
iWidth = iEastX - iWestX + 1
else:
#Equatorial Region
iSouthY = int(self.mapHeight * 0.40)
iNorthY = int(self.mapHeight * 0.60) - 1
iHeight = iNorthY - iSouthY + 1
iWestX = 0
iEastX = self.mapWidth - 1
iWidth = iEastX - iWestX + 1
for y in range(iSouthY,iNorthY):
for x in range(iWestX,iEastX):
i = self.GetIndex(x,y)
if self.plateMap[i] != 0 and PWRand.random() < 0.25:
self.plateMap[i] = 0
#grow plates
doneMapFull = False
while not doneMapFull:
doneMapFull = True
for y in range(0,self.mapHeight):
for x in range(0,self.mapWidth):
i = self.GetIndex(x,y)
if self.plateMap[i] != 0 and doneMap[i] == False:
up = self.GetIndex(x,y-1)
down = self.GetIndex(x,y+1)
left = self.GetIndex(x-1,y)
right = self.GetIndex(x+1,y)
done = True
if self.plateMap[up] == 0:
done = False
if PWRand.random() < .5:
self.plateMap[up] = self.plateMap[i]
if self.plateMap[down] == 0:
done = False
if PWRand.random() < .5:
self.plateMap[down] = self.plateMap[i]
if self.plateMap[left] == 0:
done = False
if PWRand.random() < .5:
self.plateMap[left] = self.plateMap[i]
if self.plateMap[right] == 0:
done = False
if PWRand.random() < .5:
self.plateMap[right] = self.plateMap[i]
if done == True:
doneMap[i] = True
else:
doneMapFull = False
#Stagger the plates somewhat to add interest
for iPlate in range(1,numberOfPlates + 1):
polarPlate = False
#Bottom of map
for y in range (0,botGap):
for x in range(0,self.mapWidth):
i = self.GetIndex(x,y)
if self.plateMap[i] == iPlate:
polarPlate = True
#Top of map
for y in range (0,topGap):
for x in range(0,self.mapWidth):
i = self.GetIndex(x,y)
if self.plateMap[i] == iPlate:
polarPlate = True
adjPlate = PWRand.random() * 0.5 + 0.5
for i in range(0,self.mapHeight*self.mapWidth):
if self.plateMap[i] == iPlate:
if polarPlate == False:
self.map[i] += adjPlate
else:
self.map[i] -= adjPlate
#Now that the plates are grown, we must decide how the plate boundaries
#will effect our map. Basically, plots away from plate boundaries will
#cause some sinking, while plots closer to them while rise. After
#multiplying, the main heightmap will be re-normalized.
sinkValue = 1.5
peakValue = 2.0
searchRadius = 4
self.influMap = array('d')
#initialize map with sinkValue
for i in range(0,self.mapHeight*self.mapWidth):
self.influMap.append(sinkValue)
for y in range(self.mapHeight):
for x in range(self.mapWidth):
distance = self.FindDistanceToPlateBoundary(x,y,searchRadius)
i = self.GetIndex(x,y)
if distance == 0.0:
#not found in search radius
self.influMap[i] = sinkValue
else:
self.influMap[i] = self.GetInfluFromDistance(sinkValue,peakValue,searchRadius,distance)
#next step is to multiply the influence map by the original heightmap
for y in range(self.mapHeight):
for x in range (self.mapWidth):
i = self.GetIndex(x,y)
self.map[i] *= self.influMap[i]
return