kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
d763140a2d
commit
ee1aadbebd
|
@ -8,22 +8,44 @@ MARROM_ESCURO = color(85, 25, 27)
|
|||
VERDE_CLARO = color(10, 237, 7)
|
||||
MARROM_CLARO = color(193, 109, 111)
|
||||
VERDE_ESCURO = color(48, 72, 36)
|
||||
TIPOS = {"S": AZUL_ESCURO,
|
||||
"M": MARROM_ESCURO,
|
||||
"B": AMARELO,
|
||||
"P": VERDE_CLARO,
|
||||
"V": MARROM_CLARO,
|
||||
"F": VERDE_ESCURO}
|
||||
TIPOS = {"sea": AZUL_ESCURO,
|
||||
"mount": MARROM_ESCURO,
|
||||
"shore": AMARELO,
|
||||
"field": VERDE_CLARO,
|
||||
"town": MARROM_CLARO,
|
||||
"forest": VERDE_ESCURO}
|
||||
|
||||
PROB_TIPOS = {"sea": ["sea"] * 10 + ["shore"] * 2,
|
||||
"mount":["forest"] * 10 + ["town"] * 2,
|
||||
"shore": ["field"] * 10 + ["town"] * 2,
|
||||
"field": ["forest"] * 10 + ["shore"] * 2,
|
||||
"town": ["field"] * 10 + ["forest"] * 2,
|
||||
"forest": ["field"] * 10 + ["mount"] * 2,
|
||||
}
|
||||
|
||||
class Quadrado():
|
||||
|
||||
""" Região quadrada do mapa"""
|
||||
|
||||
def __init__(self, coluna, fila, tipo=None):
|
||||
self.tipo = tipo or self.selec_tipo()
|
||||
self.altura = Quadrado.sorteiaAltura(self.tipo)
|
||||
def __init__(self, coluna, fila):
|
||||
self.fila = fila
|
||||
self.coluna = coluna
|
||||
self.tipo = None
|
||||
|
||||
def define_tipo(self):
|
||||
pool_tipos = [] #[choice(TIPOS.keys())] # ["mount"] #TIPOS.keys()
|
||||
# print(pool_tipos)
|
||||
for v in self.vizinhos:
|
||||
if v.tipo is not None:
|
||||
# print(v.tipo)
|
||||
pool_tipos.extend(PROB_TIPOS[v.tipo])
|
||||
if not pool_tipos:
|
||||
pool_tipos = [choice(TIPOS.keys())]
|
||||
print(pool_tipos, self.coluna, self.fila)
|
||||
|
||||
self.tipo = choice(pool_tipos)
|
||||
|
||||
self.altura = Quadrado.sorteiaAltura(self.tipo)
|
||||
self.cor = TIPOS[self.tipo]
|
||||
|
||||
def desenha(self):
|
||||
|
@ -46,47 +68,54 @@ class Quadrado():
|
|||
# translate(0, 0, self.altura)
|
||||
# rect(0, 0, self.tamanho, self.tamanho)
|
||||
|
||||
textSize(20) # para escrever o tipo se o mouse estiver perto
|
||||
textSize(18) # para escrever o tipo se o mouse estiver perto
|
||||
textAlign(CENTER, CENTER)
|
||||
if (dist(posX, posY, mouseX, mouseY) < self.tamanho * 2):
|
||||
fill(0)
|
||||
text(self.tipo, self.tamanho / 2, self.tamanho / 2, 35)
|
||||
if (dist(posX, posY, mouseX, mouseY) < self.tamanho):
|
||||
fill(255)
|
||||
text(self.tipo, self.tamanho / 2 - 2, self.tamanho / 2 - 2, 36)
|
||||
text(self.tipo[:3].upper(), self.tamanho / 2 - 1, self.tamanho / 2 - 1, 36)
|
||||
|
||||
def calcula_cantos(self):
|
||||
def calcula_vizinhos(self):
|
||||
"""
|
||||
Devolva uma lista dos cantos nesta ordem:
|
||||
0 --- 1
|
||||
| |
|
||||
| |
|
||||
3 --- 2
|
||||
Calcula uma lista self.vizinhos (incluindo 'S', self)
|
||||
e self.grupos_cantos (0TLS, T1RS, SR2B, LSB3)
|
||||
|
||||
0 | T | 1
|
||||
--|---|--
|
||||
L | S | R
|
||||
--|---|--
|
||||
3 | B | 2
|
||||
"""
|
||||
TL = ((-1, -1), (0, -1), (-1, 0), (0, 0))
|
||||
TR = ((+1, -1), (0, -1), (+1, 0), (0, 0))
|
||||
BL = ((-1, +1), (0, +1), (-1, 0), (0, 0))
|
||||
BR = ((+1, +1), (0, +1), (+1, 0), (0, 0))
|
||||
self.cantos = [[self.mapa[(self.coluna + i, self.fila + j)]
|
||||
for i, j in posicoes
|
||||
if self.mapa.get((self.coluna + i, self.fila + j))]
|
||||
for posicoes in (TL, TR, BR, BL)]
|
||||
self.grupos_cantos = [[self.mapa[(self.coluna + i, self.fila + j)]
|
||||
for i, j in posicoes
|
||||
if self.mapa.get((self.coluna + i, self.fila + j))]
|
||||
for posicoes in (TL, TR, BR, BL)]
|
||||
TODOS = ((-1, -1), (+0, -1), (+1, -1),
|
||||
(-1, +0), (+0, +0), (+1, +0),
|
||||
(-1, +1), (+0, +1), (+1, +1))
|
||||
self.vizinhos = [self.mapa[(self.coluna + i, self.fila + j)]
|
||||
for i, j in TODOS
|
||||
if self.mapa.get((self.coluna + i, self.fila + j))]
|
||||
|
||||
def calcula_alturas(self):
|
||||
self.alturas_cantos = []
|
||||
for canto in self.cantos:
|
||||
alturas = [quadrado.altura for quadrado in canto]
|
||||
media_alturas = sum(alturas) / len(alturas)
|
||||
for grupo in self.grupos_cantos:
|
||||
alturas = [quadrado.altura for quadrado in grupo]
|
||||
if all(alturas):
|
||||
media_alturas = sum(alturas) / len(alturas)
|
||||
else:
|
||||
media_alturas = 0
|
||||
self.alturas_cantos.append(media_alturas)
|
||||
|
||||
def selec_tipo(self):
|
||||
return choice(TIPOS.keys())
|
||||
|
||||
@staticmethod
|
||||
def sorteiaAltura(tipo):
|
||||
# return 0 #(para demo plana)
|
||||
if tipo == "S" or tipo == "B":
|
||||
if tipo == "sea" or tipo == "shore":
|
||||
return 0
|
||||
elif tipo == "M":
|
||||
elif tipo == "mount":
|
||||
return 30
|
||||
else:
|
||||
return random(5, 25)
|
||||
|
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 1.1 MiB |
|
@ -13,16 +13,22 @@ Quadrado.tamanho = 25 # tamanho grade
|
|||
Quadrado.mapa = mapa
|
||||
|
||||
def setup():
|
||||
global mapa, colunas, filas
|
||||
global colunas, filas
|
||||
size(500, 500, P3D)
|
||||
colunas = width / Quadrado.tamanho
|
||||
filas = height / Quadrado.tamanho
|
||||
setup_mapa()
|
||||
|
||||
def setup_mapa():
|
||||
global mapa
|
||||
mapa.clear()
|
||||
for fila in range(filas):
|
||||
for coluna in range(colunas):
|
||||
mapa[(coluna, fila)] = Quadrado(coluna, fila)
|
||||
|
||||
for quadrado in mapa.values():
|
||||
quadrado.calcula_cantos()
|
||||
quadrado.calcula_vizinhos()
|
||||
quadrado.define_tipo()
|
||||
for quadrado in mapa.values():
|
||||
quadrado.calcula_alturas()
|
||||
|
||||
def draw():
|
||||
|
@ -31,7 +37,10 @@ def draw():
|
|||
camera(width / 2, mouseY*2, 500.0, # eyeX, eyeY, eyeZ
|
||||
width / 2, height / 2, 0.0, # centerX, centerY, centerZ
|
||||
0.0, 1.0, 0.0) # upX, upY, upZ
|
||||
|
||||
for fila in range(filas):
|
||||
for coluna in range(colunas):
|
||||
mapa[(fila, coluna)].desenha()
|
||||
|
||||
def keyPressed():
|
||||
if key == ' ':
|
||||
setup_mapa()
|
||||
|
|
|
@ -21,6 +21,12 @@
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_07_24c](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_07_24c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_07_23c](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_07_23c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
Ładowanie…
Reference in New Issue