generated from mwc/project_drawing
I finished making the tree, and I added more shapes into shapes.py as I
felt like they were okay enouh for now. Something I am wondering about is if there is some sort of way to "mirror" lines of code, because of the way that the turtle draws, it would be nice to only draw half of something, and then have it finsish by mirroring, like a loop but in reverse order (at least for things that are symmetrical).
This commit is contained in:
parent
8f1bc7512c
commit
3876534fb3
Binary file not shown.
58
drawing.py
58
drawing.py
|
@ -6,62 +6,8 @@
|
|||
|
||||
from turtle import *
|
||||
from math import sqrt
|
||||
from shapes import draw_leaf
|
||||
from shapes import *
|
||||
|
||||
def draw_trunk(height):
|
||||
right(270)
|
||||
forward(2*height)
|
||||
circle(-height/16,90)
|
||||
|
||||
def draw_branch(length):
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
circle(-length/16,135)
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
circle(-length/16,135)
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
circle(-length/16,135)
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
circle(-length/16,135)
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
circle(-length/16,90)
|
||||
|
||||
forward(2*length)
|
||||
|
||||
# roots
|
||||
# [1,3,3,1]
|
||||
circle(-length/16,45)
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
|
||||
circle(-length/16,135)
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
|
||||
circle(-length/16,135)
|
||||
|
||||
forward(length)
|
||||
circle(length/8,180)
|
||||
forward(length)
|
||||
|
||||
circle(-length/16,45)
|
||||
draw_tree(20)
|
||||
|
||||
input()
|
53
shapes.py
53
shapes.py
|
@ -4,6 +4,53 @@ from math import sqrt
|
|||
def draw_leaf(size):
|
||||
circle(size,90)
|
||||
right(270)
|
||||
circle(size,90)
|
||||
right(225)
|
||||
forward(size*sqrt(2))
|
||||
circle(.75*size,90)
|
||||
circle(-.25*size,90)
|
||||
|
||||
def draw_trunk(size):
|
||||
forward(10*size)
|
||||
circle(size/8,90)
|
||||
|
||||
def draw_branch(size):
|
||||
angles = [135, 135, 135, 135, 90]
|
||||
for angle in angles:
|
||||
branch_end(size)
|
||||
circle(size/8,angle)
|
||||
|
||||
def tip(size):
|
||||
forward(size)
|
||||
right(45)
|
||||
forward(size/10)
|
||||
right(90)
|
||||
forward(size/10)
|
||||
right(45)
|
||||
forward(size)
|
||||
|
||||
def branching(ang1, d1, ang2, d2, ang3):
|
||||
right(ang1)
|
||||
forward(d1)
|
||||
right(ang2)
|
||||
forward(d2)
|
||||
right(ang3)
|
||||
|
||||
def branch_end(size):
|
||||
forward(4*size)
|
||||
right(300)
|
||||
tip(size)
|
||||
branching(240,size,330,size,330)
|
||||
tip(size)
|
||||
branching(30,size,240,size,30)
|
||||
tip(size)
|
||||
branching(330,size,330,size,240)
|
||||
tip(size)
|
||||
right(300)
|
||||
forward(4*size)
|
||||
|
||||
def draw_tree(size):
|
||||
circle(size/4,90)
|
||||
draw_trunk(size)
|
||||
draw_branch(size)
|
||||
forward(10*size)
|
||||
circle(size/4,90)
|
||||
|
||||
|
Loading…
Reference in New Issue