Alexandre B A Villares 2020-07-23 23:39:36 -03:00
rodzic 9d666b0a2c
commit 32a809cd37
5 zmienionych plików z 33 dodań i 15 usunięć

Wyświetl plik

@ -28,23 +28,34 @@ class Quadrado():
self.cor = CORES[self.tipo]
def desenha(self):
posX, posY = self.coluna * self.tamanho, self.fila * self.tamanho
tam = self.tamanho
posX, posY = self.coluna * tam, self.fila * tam
with pushMatrix():
translate(posX, posY)
noStroke()
fill(self.cor)
pushMatrix()
translate(0, 0, self.altura)
rect(0, 0, self.tamanho, self.tamanho)
popMatrix()
fill(255) # branco
pos = ((-1, -1), (1, -1), (1, 1), (-1, 1))
for i, c in enumerate(self.cantos):
pc = self.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)
textSize(20) # para escrever o tipo se o mouse estiver perto
textAlign(CENTER, CENTER)
if (dist(posX, posY, mouseX, mouseY) < self.tamanho * 2):
text(self.tipo, self.tamanho / 2,
self.tamanho / 2, self.altura + 5)
fill(0)
text(self.tipo, self.tamanho / 2, self.tamanho / 2, 35)
fill(255)
text(self.tipo, self.tamanho / 2 - 2, self.tamanho / 2 - 2, 36)
def media_cantos(self):
def calcula_cantos(self):
"""
Devolva uma lista dos cantos nesta ordem:
0 --- 1
@ -57,14 +68,14 @@ class Quadrado():
BL = ((-1, +1), (0, +1), (-1, 0), (0, 0))
BR = ((+1, +1), (0, +1), (+1, 0), (0, 0))
result = []
for corner in (TL, TR, BR, BL):
self.cantos = []
for canto in (TL, TR, BR, BL):
alturas = [self.mapa[(self.coluna + i, self.fila + j)].altura
for i, j in corner
for i, j in canto
if self.mapa.get((self.coluna + i, self.fila + j))]
print(alturas)
media = sum(alturas) / len(alturas)
result.append(media)
self.cantos.append(media)
@staticmethod
def sorteiaAltura(tipo):

Plik binarny nie jest wyświetlany.

Przed

Szerokość:  |  Wysokość:  |  Rozmiar: 1.8 MiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 2.4 MiB

Wyświetl plik

@ -22,11 +22,12 @@ def setup():
mapa[(coluna, fila)] = Quadrado(coluna, fila)
for quadrado in mapa.values():
print(quadrado.media_cantos())
quadrado.calcula_cantos()
def draw():
background(0)
camera(width / 2, height / 2, 500.0, # eyeX, eyeY, eyeZ
# camera(width / 2, height / 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
0.0, 1.0, 0.0) # upX, upY, upZ

Wyświetl plik

@ -21,6 +21,12 @@
---
![sketch_2020_07_23c](2020/sketch_2020_07_23c/sketch_2020_07_23c.gif)
[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_22c](2020/sketch_2020_07_22c/sketch_2020_07_22c.gif)
[sketch_2020_07_22c](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_07_22c) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]