Alexandre B A Villares 2021-01-10 23:27:02 -03:00
rodzic 829e1ea9b5
commit ea9f8519bf
3 zmienionych plików z 73 dodań i 0 usunięć

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 147 KiB

Wyświetl plik

@ -0,0 +1,67 @@
"""
Based PythagorasTree
https://rosettacode.org/wiki/Pythagoras_tree#Processing
Processing 3.5.4
2016-06-08 Trizen
2020-03-02 da8
2020-03-17 Alexandre Villares (Python Mode)
Task: Construct a Pythagoras tree of order 7 using only vectors (no rotation or trigonometric functions).
Related tasks
Fractal tree (https://rosettacode.org/wiki/Fractal_tree)
"""
def setup():
size(800, 400)
background(0)
tree(width / 2.3, height, width / 1.8, height, 10)
save_image()
def tree(x1, y1, x2, y2, depth):
r = lambda: random(-3, 3)
if depth <= 0:
return
dx = (x2 - x1) + r()
dy = (y1 - y2) + r()
x3 = (x2 - dy) + r()
y3 = (y2 - dx) + r()
x4 = (x1 - dy) + r()
y4 = (y1 - dx) + r()
x5 = (x4 + 0.5 * (dx - dy)) + r()
y5 = (y4 - 0.5 * (dx + dy)) + r()
fill(100, 255.0 / depth, 100, 128 + 128.0 / depth)
noStroke()
# square
beginShape()
vertex(x1, y1)
vertex(x2, y2)
vertex(x3, y3)
vertex(x4, y4)
vertex(x1, y1)
endShape()
# triangle
beginShape()
vertex(x3, y3)
vertex(x4, y4)
vertex(x5, y5)
vertex(x3, y3)
endShape()
tree(x4, y4, x5, y5, depth - 1)
tree(x5, y5, x3, y3, depth - 1)
def save_image():
from os import path
sketch = sketchPath()
name = path.basename(sketch)
print(name)
saveFrame('{}.png'.format(name))

Wyświetl plik

@ -26,6 +26,12 @@ Here are listed some of the tools I have been using:
---
![sketch_2021_01_10a](2021/sketch_2021_01_10a/sketch_2021_01_10a.png)
[sketch_2021_01_10a](https://github.com/villares/sketch-a-day/tree/master/2021/sketch_2021_01_10a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---
![sketch_2021_01_09a](2021/sketch_2021_01_09a/sketch_2021_01_09a.gif)
[sketch_2021_01_09a](https://github.com/villares/sketch-a-day/tree/master/2021/sketch_2021_01_09a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]