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)
|
VERDE_CLARO = color(10, 237, 7)
|
||||||
MARROM_CLARO = color(193, 109, 111)
|
MARROM_CLARO = color(193, 109, 111)
|
||||||
VERDE_ESCURO = color(48, 72, 36)
|
VERDE_ESCURO = color(48, 72, 36)
|
||||||
TIPOS = {"S": AZUL_ESCURO,
|
TIPOS = {"sea": AZUL_ESCURO,
|
||||||
"M": MARROM_ESCURO,
|
"mount": MARROM_ESCURO,
|
||||||
"B": AMARELO,
|
"shore": AMARELO,
|
||||||
"P": VERDE_CLARO,
|
"field": VERDE_CLARO,
|
||||||
"V": MARROM_CLARO,
|
"town": MARROM_CLARO,
|
||||||
"F": VERDE_ESCURO}
|
"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():
|
class Quadrado():
|
||||||
|
|
||||||
""" Região quadrada do mapa"""
|
""" Região quadrada do mapa"""
|
||||||
|
|
||||||
def __init__(self, coluna, fila, tipo=None):
|
def __init__(self, coluna, fila):
|
||||||
self.tipo = tipo or self.selec_tipo()
|
|
||||||
self.altura = Quadrado.sorteiaAltura(self.tipo)
|
|
||||||
self.fila = fila
|
self.fila = fila
|
||||||
self.coluna = coluna
|
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]
|
self.cor = TIPOS[self.tipo]
|
||||||
|
|
||||||
def desenha(self):
|
def desenha(self):
|
||||||
|
@ -46,47 +68,54 @@ class Quadrado():
|
||||||
# translate(0, 0, self.altura)
|
# translate(0, 0, self.altura)
|
||||||
# rect(0, 0, self.tamanho, self.tamanho)
|
# 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)
|
textAlign(CENTER, CENTER)
|
||||||
if (dist(posX, posY, mouseX, mouseY) < self.tamanho * 2):
|
if (dist(posX, posY, mouseX, mouseY) < self.tamanho):
|
||||||
fill(0)
|
|
||||||
text(self.tipo, self.tamanho / 2, self.tamanho / 2, 35)
|
|
||||||
fill(255)
|
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:
|
Calcula uma lista self.vizinhos (incluindo 'S', self)
|
||||||
0 --- 1
|
e self.grupos_cantos (0TLS, T1RS, SR2B, LSB3)
|
||||||
| |
|
|
||||||
| |
|
0 | T | 1
|
||||||
3 --- 2
|
--|---|--
|
||||||
|
L | S | R
|
||||||
|
--|---|--
|
||||||
|
3 | B | 2
|
||||||
"""
|
"""
|
||||||
TL = ((-1, -1), (0, -1), (-1, 0), (0, 0))
|
TL = ((-1, -1), (0, -1), (-1, 0), (0, 0))
|
||||||
TR = ((+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))
|
BL = ((-1, +1), (0, +1), (-1, 0), (0, 0))
|
||||||
BR = ((+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)]
|
self.grupos_cantos = [[self.mapa[(self.coluna + i, self.fila + j)]
|
||||||
for i, j in posicoes
|
for i, j in posicoes
|
||||||
if self.mapa.get((self.coluna + i, self.fila + j))]
|
if self.mapa.get((self.coluna + i, self.fila + j))]
|
||||||
for posicoes in (TL, TR, BR, BL)]
|
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):
|
def calcula_alturas(self):
|
||||||
self.alturas_cantos = []
|
self.alturas_cantos = []
|
||||||
for canto in self.cantos:
|
for grupo in self.grupos_cantos:
|
||||||
alturas = [quadrado.altura for quadrado in canto]
|
alturas = [quadrado.altura for quadrado in grupo]
|
||||||
media_alturas = sum(alturas) / len(alturas)
|
if all(alturas):
|
||||||
|
media_alturas = sum(alturas) / len(alturas)
|
||||||
|
else:
|
||||||
|
media_alturas = 0
|
||||||
self.alturas_cantos.append(media_alturas)
|
self.alturas_cantos.append(media_alturas)
|
||||||
|
|
||||||
def selec_tipo(self):
|
|
||||||
return choice(TIPOS.keys())
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sorteiaAltura(tipo):
|
def sorteiaAltura(tipo):
|
||||||
# return 0 #(para demo plana)
|
# return 0 #(para demo plana)
|
||||||
if tipo == "S" or tipo == "B":
|
if tipo == "sea" or tipo == "shore":
|
||||||
return 0
|
return 0
|
||||||
elif tipo == "M":
|
elif tipo == "mount":
|
||||||
return 30
|
return 30
|
||||||
else:
|
else:
|
||||||
return random(5, 25)
|
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
|
Quadrado.mapa = mapa
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
global mapa, colunas, filas
|
global colunas, filas
|
||||||
size(500, 500, P3D)
|
size(500, 500, P3D)
|
||||||
colunas = width / Quadrado.tamanho
|
colunas = width / Quadrado.tamanho
|
||||||
filas = height / Quadrado.tamanho
|
filas = height / Quadrado.tamanho
|
||||||
|
setup_mapa()
|
||||||
|
|
||||||
|
def setup_mapa():
|
||||||
|
global mapa
|
||||||
|
mapa.clear()
|
||||||
for fila in range(filas):
|
for fila in range(filas):
|
||||||
for coluna in range(colunas):
|
for coluna in range(colunas):
|
||||||
mapa[(coluna, fila)] = Quadrado(coluna, fila)
|
mapa[(coluna, fila)] = Quadrado(coluna, fila)
|
||||||
|
|
||||||
for quadrado in mapa.values():
|
for quadrado in mapa.values():
|
||||||
quadrado.calcula_cantos()
|
quadrado.calcula_vizinhos()
|
||||||
|
quadrado.define_tipo()
|
||||||
|
for quadrado in mapa.values():
|
||||||
quadrado.calcula_alturas()
|
quadrado.calcula_alturas()
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
|
@ -31,7 +37,10 @@ def draw():
|
||||||
camera(width / 2, mouseY*2, 500.0, # eyeX, eyeY, eyeZ
|
camera(width / 2, mouseY*2, 500.0, # eyeX, eyeY, eyeZ
|
||||||
width / 2, height / 2, 0.0, # centerX, centerY, centerZ
|
width / 2, height / 2, 0.0, # centerX, centerY, centerZ
|
||||||
0.0, 1.0, 0.0) # upX, upY, upZ
|
0.0, 1.0, 0.0) # upX, upY, upZ
|
||||||
|
|
||||||
for fila in range(filas):
|
for fila in range(filas):
|
||||||
for coluna in range(colunas):
|
for coluna in range(colunas):
|
||||||
mapa[(fila, coluna)].desenha()
|
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)]
|
[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