main
Alexandre B A Villares 2018-03-17 22:08:22 -03:00
rodzic c7d009dd1e
commit 5552e0bce7
5 zmienionych plików z 40 dodań i 63 usunięć

Wyświetl plik

@ -42,22 +42,18 @@ def draw():
#if not frameCount % 10: gif_export(GifMaker, frames=3000)
def branch(h, theta, size_factor):
# Each branch will be 2/3rds the size of the previous one
h *= size_factor
# All recursive functions must have an exit condition!!!!
if h > 1.5:
# Save the current state of transformation (i.e. where are we now)
pushMatrix()
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(h + random(-d, 0), theta, size_factor)
# Whenever we get back here, we "pop" in order to restore the previous
# matrix state
popMatrix()
# Repeat the same thing, only branch off to the "left" this time!
with pushMatrix():
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(h + random(-d, 0), theta, size_factor)
# Repeat the same thing, only branch off to the "left" this time!
with pushMatrix(): # this 'with' context pops matrix on exit
rotate(-theta + c * random(1))
line(0, 0, 0, -h)
translate(0, -h)

Wyświetl plik

@ -55,22 +55,18 @@ def draw():
#if not frameCount % 10: gif_export(GifMaker, frames=3000)
def branch(h, theta, size_factor):
# Each branch will be 2/3rds the size of the previous one
h *= size_factor
# All recursive functions must have an exit condition!!!!
if h > 1.5:
# Save the current state of transformation (i.e. where are we now)
pushMatrix()
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(h + random(-d, 0), theta, size_factor)
# Whenever we get back here, we "pop" in order to restore the previous
# matrix state
popMatrix()
# Repeat the same thing, only branch off to the "left" this time!
with pushMatrix():
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(h + random(-d, 0), theta, size_factor)
# Repeat the same thing, only branch off to the "left" this time!
with pushMatrix(): # this 'with' context pops matrix on exit
rotate(-theta + c * random(1))
line(0, 0, 0, -h)
translate(0, -h)

Wyświetl plik

@ -39,26 +39,19 @@ def draw():
branch(d, a, width/30)
# uncomment next line to export GIF
if not frameCount % 10: gif_export(GifMaker, frames=2000)
#if not frameCount % 10: gif_export(GifMaker, frames=2000)
def branch(gen, theta, branch_size):
# Each branch will be 2/3rds the size of the previous one
# All recursive functions must have an exit condition!!!!
if gen > 1 and branch_size > 1:
h = branch_size * (1 + random(b) / 4)
branch_size *= 1 - random(b) / 10
# Save the current state of transformation (i.e. where are we now)
pushMatrix()
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(gen - 1, theta, branch_size)
# Whenever we get back here, we "pop" in order to restore the previous
# matrix state
popMatrix()
with pushMatrix():
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(gen - 1, theta, branch_size)
# Repeat the same thing, only branch off to the "left" this time!
with pushMatrix():
rotate(-theta + c * random(1))

Wyświetl plik

@ -55,23 +55,16 @@ def draw():
#if not frameCount % 10: gif_export(GifMaker, frames=3000)
def branch(gen, theta, branch_size):
# Each branch will be 2/3rds the size of the previous one
# All recursive functions must have an exit condition!!!!
if gen > 1 and branch_size > 1:
h = branch_size * (1 + random(b) / 4)
branch_size *= 1 - random(b) / 10
# Save the current state of transformation (i.e. where are we now)
pushMatrix()
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(gen - 1, theta, branch_size)
# Whenever we get back here, we "pop" in order to restore the previous
# matrix state
popMatrix()
with pushMatrix():
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
branch(gen - 1, theta, branch_size)
# Repeat the same thing, only branch off to the "left" this time!
with pushMatrix():
rotate(-theta + c * random(1))

Wyświetl plik

@ -52,20 +52,19 @@ def branch(gen, theta, branch_size):
h = branch_size * (1 + random(b) / 4)
branch_size *= 1 - random(b) / 10
# Save the current state of transformation (i.e. where are we now)
pushMatrix()
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
pushStyle()
branch(gen - 1, theta, branch_size)
popStyle()
# Whenever we get back here, we "pop" in order to restore the previous
# matrix state
popMatrix()
with pushMatrix():
rotate(theta + c * random(1)) # Rotate by theta
line(0, 0, 0, -h) # Draw the branch
translate(0, -h) # Move to the end of the branch
# Ok, now call myself to draw two branches!!
pushStyle()
branch(gen - 1, theta, branch_size)
popStyle()
# Repeat the same thing, only branch off to the "left" this time!
with pushMatrix():
rotate(-theta + c * random(1))
line(0, 0, 0, -h)
translate(0, -h)
pushStyle()
branch(gen - 1, theta, branch_size)
popStyle()