RE: syntaxwise, what is the best programming language?
08-17-2016, 06:44 PM
(08-17-2016, 01:23 PM)Loather Wrote: »heres a map generator i made in python, please judge softlyWait, in Python function decs have colons instead of curly brackets? Weeeeeiiiirrrrd....
Code:from Tkinter import *
from random import randint
def buildIsland(xStart, yStart, landCounter, blobbiness):
global mapArray
mapArray[xStart][yStart] = "green"
while landCounter >= 0:
xCoord = xStart
yCoord = yStart
while(mapArray[xCoord][yCoord] == "green"):
if xCoord >= 1 and xCoord <= 299:
xCoord += randint(0,2) - 1
elif xCoord >= 1:
xCoord -= 1
elif xCoord <= 299:
xCoord += 1
if yCoord >= 1 and yCoord <= 299:
yCoord += randint(0,2) - 1
elif yCoord >= 1:
yCoord -= 1
elif yCoord <= 299:
yCoord += 1
mapArray[xCoord][yCoord] = "green"
landCounter -= 1
if randint(0,blobbiness) == 1:
xStart = xCoord
yStart = yCoord
master = Tk()
xCoord = 150
yCoord = 150
canvasWidth = 300
canvasHeight = 300
xCounter = 0
yCounter = 0
zoomLevel = 1
mapArray = [["blue" for x in range(canvasWidth + 1)] for y in range(canvasHeight + 1)]
#Build islands
for x in range(0,50):
buildIsland(randint(0,300),randint(0,300),randint(150,2000),1)
#Set up canvas
drawMap = Canvas(master, width = canvasWidth * zoomLevel, height = canvasHeight * zoomLevel)
drawMap.pack()
#Draw map
while(yCounter <= canvasHeight):
while(xCounter <= canvasWidth):
drawMap.create_rectangle(xCounter * zoomLevel, yCounter * zoomLevel, (xCounter * zoomLevel)+ zoomLevel,
(yCounter * zoomLevel) + zoomLevel, fill=mapArray[xCounter][yCounter],
outline=mapArray[xCounter][yCounter])
xCounter += 1
xCounter = 0
yCounter += 1
mainloop()