Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. TAMANHO = 50 #TAMANHO grade
  2. MAPA = []
  3.  
  4. def setup():
  5. global COLUNAS, FILAS, MAPA
  6. size(600,600)
  7. COLUNAS = width / TAMANHO
  8. FILAS = height / TAMANHO
  9. for fila in range (FILAS):
  10. for coluna in range(COLUNAS):
  11. tipo = "mar"
  12. quadrado = Quadrado(fila, coluna, tipo, 0)
  13. MAPA.append(quadrado)
  14. for i in range(10):
  15. fila, coluna = int(random(COLUNAS)),int(random(FILAS))
  16. sorteio = no_mapa(fila, coluna)
  17. MAPA[sorteio].tipo = "montanha"
  18. for i in range(3):
  19. MAPA[sorteio].cor = Quadrado.CORES["montanha"]
  20. fila, coluna = fila+int(random(-2,2)), coluna+int(random(-2,2))
  21. vizinho = no_mapa(fila, coluna)
  22. if int(random(5)):
  23. tipo = "floresta"
  24. else: tipo = "vila"
  25. MAPA[vizinho].tipo = tipo
  26. MAPA[vizinho].cor = Quadrado.CORES[tipo]
  27.  
  28.  
  29. def draw():
  30. for quadrado in MAPA:
  31. quadrado.desenha()
  32.  
  33. def no_mapa(coluna, fila):
  34. if coluna < 0:
  35. coluna = COLUNAS - coluna
  36. if coluna > COLUNAS:
  37. coluna = coluna - COLUNAS
  38. if fila < 0:
  39. fila = FILAS - fila
  40. if fila > FILAS:
  41. fila = fila - FILAS
  42. if coluna + fila * COLUNAS < len(MAPA):
  43. return (coluna + fila * COLUNAS)
  44. else:
  45. return len(MAPA)-1
  46.  
  47. class Quadrado():
  48. TIPOS = ["mar","montanha","praia","plano","vila","floresta"]
  49. AMARELO = color(255,230,0)
  50. AZUL_ESCURO = color(7,0,255)
  51. MARROM_ESCURO = color(85,25,27)
  52. VERDE_CLARO = color(10,237,7)
  53. MARROM_CLARO = color(193,109,111)
  54. VERDE_ESCURO = color(48,72,36)
  55. CORES = {"mar":AZUL_ESCURO,
  56. "montanha":MARROM_ESCURO,
  57. "praia":AMARELO,
  58. "plano":VERDE_CLARO,
  59. "vila":MARROM_CLARO,
  60. "floresta":VERDE_ESCURO}
  61.  
  62. def __init__(self,fila,coluna,tipo,altura):
  63. self.fila = fila
  64. self.coluna = coluna
  65. self.tipo = tipo
  66. self.altura = altura
  67. self.cor = Quadrado.CORES[tipo]
  68.  
  69. def desenha(self):
  70. posX, posY = self.coluna * TAMANHO, self.fila * TAMANHO
  71. with pushMatrix():
  72. translate(posX, posY)
  73. noStroke()
  74. fill(self.cor)
  75. rect(0, 0, TAMANHO, TAMANHO)
  76. fill(0) # preto
  77. textSize(10) # para escrever o tipo se o mouse estiver perto
  78. if (dist(posX, posY, mouseX, mouseY) < TAMANHO * 2):
  79. text(self.tipo, 0, 20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement