Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TAMANHO = 50 #TAMANHO grade
- MAPA = []
- def setup():
- global COLUNAS, FILAS, MAPA
- size(600,600)
- COLUNAS = width / TAMANHO
- FILAS = height / TAMANHO
- for fila in range (FILAS):
- for coluna in range(COLUNAS):
- tipo = "mar"
- quadrado = Quadrado(fila, coluna, tipo, 0)
- MAPA.append(quadrado)
- for i in range(10):
- fila, coluna = int(random(COLUNAS)),int(random(FILAS))
- sorteio = no_mapa(fila, coluna)
- MAPA[sorteio].tipo = "montanha"
- for i in range(3):
- MAPA[sorteio].cor = Quadrado.CORES["montanha"]
- fila, coluna = fila+int(random(-2,2)), coluna+int(random(-2,2))
- vizinho = no_mapa(fila, coluna)
- if int(random(5)):
- tipo = "floresta"
- else: tipo = "vila"
- MAPA[vizinho].tipo = tipo
- MAPA[vizinho].cor = Quadrado.CORES[tipo]
- def draw():
- for quadrado in MAPA:
- quadrado.desenha()
- def no_mapa(coluna, fila):
- if coluna < 0:
- coluna = COLUNAS - coluna
- if coluna > COLUNAS:
- coluna = coluna - COLUNAS
- if fila < 0:
- fila = FILAS - fila
- if fila > FILAS:
- fila = fila - FILAS
- if coluna + fila * COLUNAS < len(MAPA):
- return (coluna + fila * COLUNAS)
- else:
- return len(MAPA)-1
- class Quadrado():
- TIPOS = ["mar","montanha","praia","plano","vila","floresta"]
- AMARELO = color(255,230,0)
- AZUL_ESCURO = color(7,0,255)
- MARROM_ESCURO = color(85,25,27)
- VERDE_CLARO = color(10,237,7)
- MARROM_CLARO = color(193,109,111)
- VERDE_ESCURO = color(48,72,36)
- CORES = {"mar":AZUL_ESCURO,
- "montanha":MARROM_ESCURO,
- "praia":AMARELO,
- "plano":VERDE_CLARO,
- "vila":MARROM_CLARO,
- "floresta":VERDE_ESCURO}
- def __init__(self,fila,coluna,tipo,altura):
- self.fila = fila
- self.coluna = coluna
- self.tipo = tipo
- self.altura = altura
- self.cor = Quadrado.CORES[tipo]
- def desenha(self):
- posX, posY = self.coluna * TAMANHO, self.fila * TAMANHO
- with pushMatrix():
- translate(posX, posY)
- noStroke()
- fill(self.cor)
- rect(0, 0, TAMANHO, TAMANHO)
- fill(0) # preto
- textSize(10) # para escrever o tipo se o mouse estiver perto
- if (dist(posX, posY, mouseX, mouseY) < TAMANHO * 2):
- text(self.tipo, 0, 20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement