villares 2020-03-26 23:49:02 -03:00
rodzic a8e13fbdbe
commit e43ffcc445
4 zmienionych plików z 88 dodań i 0 usunięć

Plik binarny nie jest wyświetlany.

Po

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

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -0,0 +1,72 @@
# Other L-System
iterations = 7
stroke_len = 600
angle_deg = 90
axiom = 'L'
sentence = axiom
rules = {
'L': '+RF-LFL-FR+',
# 'R': '-LF+RFR+FLL-',
'R': '-LF+RFR+FFL-',
}
def setup():
size(700, 700)
global xo, yo
xo, yo = 50, height - 50
strokeWeight(1)
noFill()
generate(iterations)
def draw():
background(0)
translate(xo, yo)
plot(radians(angle_deg))
def generate(n):
global stroke_len, sentence
for _ in range(n):
stroke_len *= 0.5
next_sentence = ''
for c in sentence:
next_sentence += rules.get(c, c)
sentence = next_sentence
def plot(angle):
for c in sentence:
if c == 'F':
stroke(255)
line(0, 0, 0, -stroke_len)
translate(0, -stroke_len)
elif c == '+':
rotate(angle)
elif c == '-':
rotate(-angle)
elif c == '[':
pushMatrix()
elif c == ']':
popMatrix()
def keyPressed():
global angle_deg, xo, yo, stroke_len
if key == '-':
angle_deg -= 5
print(angle_deg)
if str(key) in "=+":
angle_deg += 5
print(angle_deg)
if key == 's':
saveFrame('####.png')
if key == 'a':
stroke_len *= 2
if key == 'z':
stroke_len /= 2
if keyCode == LEFT:
xo -= 50
if keyCode == RIGHT:
xo += 50
if keyCode == UP:
yo -= 50
if keyCode == DOWN:
yo += 50

Wyświetl plik

@ -17,6 +17,22 @@ You may also support my artistic work, open educational resources and research u
---
![sketch_2020_03_26a](2020/sketch_2020_03_26a/sketch_2020_03_26a.png)
[sketch_2020_03_26a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_03_26a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
```python
axiom = 'L'
sentence = axiom
rules = {
'L': '+RF-LFL-FR+',
'R': '-LF+RFR+FFL-', # broken Hilbert (added L)
}
```
---
![sketch_2020_03_25a](2020/sketch_2020_03_25a/sketch_2020_03_25a.png)
[sketch_2020_03_25a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_03_25a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]