An L-System example #555
                  
                    
                      villares
                    
                  
                
                  started this conversation in
                Show and tell
              
            Replies: 4 comments 2 replies
-
| Nice work. Impressive demo. | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| Wow, impressive! | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| @villares , this is wonderful, and exactly what I was hoping people would use the Live Coding feature for! | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| Tomorrow I'm going to present an L-System demo, so, to gear up, today I tried to find a nice variation of these rules with the red circles... import py5
step = 10
axiom = 'F'
rules = {
#    'F': 'FF+[+F-F-FO]-[-F+F+FO]',
   'F': 'F[+F-F+FO]F[-F+F-FO]',
    }
angle = 30
iterations = 4
def setup():
    py5.size(600, 600)
    calculate_sequence()
def calculate_sequence():
    global sequence
    starting_sequence = axiom
    for i in range(iterations):
        sequence = ''
        for symbol in starting_sequence:
            sequence = sequence + rules.get(symbol, symbol)
        starting_sequence = sequence
    print(len(sequence))
    
def draw():
    #global angle
    #angle = py5.mouse_x / 5
    py5.background(0)
    py5.stroke(255)
    py5.translate(py5.width / 2, py5.height - 30)
    
    for symbol in sequence:
        if symbol == 'F':
            py5.line(0, 0, 0, -step)
            py5.translate(0, -step)
        elif symbol == '+':
            py5.rotate(py5.radians(-angle))
        elif symbol == '-':
            py5.rotate(py5.radians(angle))
        elif symbol == '[':
            py5.push_matrix()
        elif symbol == ']':
            py5.pop_matrix()
        elif symbol == 'O':
            with py5.push_style():
                py5.fill(255, 0, 0)
                py5.no_stroke()
                py5.circle(0, 0, step / 2)
def key_pressed():
    py5.save_frame('###.png')
            
        
py5.run_sketch() | 
Beta Was this translation helpful? Give feedback.
                  
                    2 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I have been teaching this in so many classes over the years, and about 4 times this month 😄. Also, this is perfect for tweaking with the wonderful new Live Coding feature 😉 !
I really like doing L-Systems with Python + Processing, I always felt like my dict approach to the substitution rules was far better than the rules with arrays in Processing Java examples.
To learn more about L-Systems and related stuff:
Beta Was this translation helpful? Give feedback.
All reactions