kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
3feeaad8a1
commit
2d1c557641
|
|
@ -0,0 +1,125 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from random import choice
|
||||||
|
|
||||||
|
AMARELO = color(255, 230, 0)
|
||||||
|
AZUL_ESCURO = color(7, 0, 255)
|
||||||
|
CINZA = color(128, 128, 128)
|
||||||
|
VERDE_CLARO = color(10, 237, 7)
|
||||||
|
VERMELHO = color(193, 10, 0)
|
||||||
|
VERDE_ESCURO = color(48, 128, 36)
|
||||||
|
TIPOS = {'sea': AZUL_ESCURO,
|
||||||
|
'mount': CINZA,
|
||||||
|
'shore': AMARELO,
|
||||||
|
'field': VERDE_CLARO,
|
||||||
|
'town': VERMELHO,
|
||||||
|
'forest': VERDE_ESCURO}
|
||||||
|
|
||||||
|
PROB_TIPOS = {'sea': ['sea'] * 10 + ['shore'] * 2,
|
||||||
|
'mount': ['forest'] * 10 + ['mount'],
|
||||||
|
# "shore": ['field'] * 10 + ['town'] * 2,
|
||||||
|
'shore': ['sea'] * 50 + ['town'],
|
||||||
|
"field": ['field'] * 5 + ['forest'] * 5,
|
||||||
|
'town': ['field'] * 10 + ['forest'] * 2,
|
||||||
|
"forest": ['forest'] * 8 + ['mount'] * 2 + ['field'] * 2,
|
||||||
|
None: ['sea', 'field', 'forest']
|
||||||
|
}
|
||||||
|
|
||||||
|
class Quadrado():
|
||||||
|
|
||||||
|
""" Região quadrada do mapa"""
|
||||||
|
|
||||||
|
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:
|
||||||
|
print(v.tipo)
|
||||||
|
pool_tipos.extend(PROB_TIPOS[v.tipo])
|
||||||
|
self.tipo = choice(pool_tipos)
|
||||||
|
|
||||||
|
self.altura = Quadrado.sorteiaAltura(self.tipo)
|
||||||
|
self.cor = TIPOS[self.tipo]
|
||||||
|
|
||||||
|
def desenha(self):
|
||||||
|
tam = self.tamanho
|
||||||
|
posX, posY = self.coluna * tam, self.fila * tam
|
||||||
|
with pushMatrix():
|
||||||
|
translate(posX, posY, self.altura)
|
||||||
|
noStroke()
|
||||||
|
fill(self.cor)
|
||||||
|
# if self.tipo != 'town':
|
||||||
|
# self.triangles(tam)
|
||||||
|
# else:
|
||||||
|
translate(0, 0, tam)
|
||||||
|
box(tam, tam, tam * 2)
|
||||||
|
|
||||||
|
textSize(18) # para escrever o tipo se o mouse estiver perto
|
||||||
|
textAlign(CENTER, CENTER)
|
||||||
|
if (dist(posX, posY, mouseX, mouseY) < self.tamanho * 2):
|
||||||
|
fill(255)
|
||||||
|
text(int(self.altura), self.tamanho /
|
||||||
|
2 - 1, self.tamanho / 2 - 1, 36)
|
||||||
|
|
||||||
|
def triangles(self, tam):
|
||||||
|
pos = ((-1, -1), (1, -1), (1, 1), (-1, 1))
|
||||||
|
for i, c in enumerate(self.alturas_cantos):
|
||||||
|
pc = self.alturas_cantos[i - 1]
|
||||||
|
ipos, ppos = pos[i], pos[i - 1]
|
||||||
|
beginShape()
|
||||||
|
vertex(ipos[0] * tam / 2, ipos[1] * tam / 2, c)
|
||||||
|
vertex(ppos[0] * tam / 2, ppos[1] * tam / 2, pc)
|
||||||
|
vertex(0, 0, self.altura)
|
||||||
|
endShape(CLOSE)
|
||||||
|
# translate(0, 0, self.altura)
|
||||||
|
# rect(0, 0, self.tamanho, self.tamanho)
|
||||||
|
|
||||||
|
def calcula_vizinhos(self):
|
||||||
|
"""
|
||||||
|
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.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 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)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def sorteiaAltura(tipo):
|
||||||
|
# return 0 #(para demo plana)
|
||||||
|
if tipo == 'sea' or tipo == 'shore':
|
||||||
|
return 0
|
||||||
|
elif tipo == 'mount':
|
||||||
|
return random(30, 40)
|
||||||
|
else:
|
||||||
|
return random(5, 25)
|
||||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 528 KiB |
|
|
@ -0,0 +1,66 @@
|
||||||
|
"""
|
||||||
|
Prova de conceito para mapa em 3D
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Para pau com placa Intel HD
|
||||||
|
from java.lang import System
|
||||||
|
System.setProperty("jogl.disable.openglcore", "false")
|
||||||
|
|
||||||
|
from mapa import Quadrado
|
||||||
|
|
||||||
|
mapa = {}
|
||||||
|
Quadrado.tamanho = 15 # tamanho grade
|
||||||
|
Quadrado.mapa = mapa
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
global colunas, filas
|
||||||
|
size(500, 600, P3D)
|
||||||
|
colunas = width / Quadrado.tamanho
|
||||||
|
filas = width / Quadrado.tamanho
|
||||||
|
setup_mapa()
|
||||||
|
textMode(SHAPE)
|
||||||
|
|
||||||
|
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_vizinhos()
|
||||||
|
for fila in range(filas):
|
||||||
|
for coluna in range(colunas):
|
||||||
|
mapa[(coluna, fila)].define_tipo()
|
||||||
|
# for quadrado in mapa.values():
|
||||||
|
# quadrado.define_tipo()
|
||||||
|
for quadrado in mapa.values():
|
||||||
|
quadrado.calcula_alturas()
|
||||||
|
|
||||||
|
def draw():
|
||||||
|
background(0)
|
||||||
|
lights()
|
||||||
|
perspective()
|
||||||
|
camera(width / 2, height / 2, 600.0, # eyeX, eyeY, eyeZ
|
||||||
|
# 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
|
||||||
|
translate(0, 100, 0)
|
||||||
|
|
||||||
|
for fila in range(filas):
|
||||||
|
for coluna in range(colunas):
|
||||||
|
mapa[(fila, coluna)].desenha()
|
||||||
|
|
||||||
|
rotateX(HALF_PI)
|
||||||
|
translate(0, -height/2, 50)
|
||||||
|
scale(1, 1, 0.4)
|
||||||
|
ortho()
|
||||||
|
q = Quadrado.tamanho
|
||||||
|
for fila in range(filas):
|
||||||
|
for coluna in range(colunas):
|
||||||
|
if mouseY + q > coluna * q > mouseY - q:
|
||||||
|
mapa[(fila, coluna)].desenha()
|
||||||
|
|
||||||
|
|
||||||
|
def keyPressed():
|
||||||
|
if key == ' ':
|
||||||
|
setup_mapa()
|
||||||
|
|
@ -21,6 +21,12 @@
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|

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

|

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