generated from mwc/project_drawing
I changed the colors in the list, and I added two more branches on the
tree. I noticed that the colors change more slowly as it moves towards the end of the list. I didn't really do much since the last commit a little while ago, I was mainly just tweaking the appearance.
This commit is contained in:
parent
9bc18ac771
commit
24a976f129
Binary file not shown.
Binary file not shown.
|
@ -1,29 +0,0 @@
|
|||
from turtle import *
|
||||
from superturt import *
|
||||
from shapes import *
|
||||
|
||||
# I'm trying to figure out how to get the leaves to change colors.
|
||||
|
||||
fillcolor('green')
|
||||
begin_fill()
|
||||
draw_leaf(20)
|
||||
end_fill()
|
||||
save('green.png')
|
||||
|
||||
#fillcolor('yellow')
|
||||
#begin_fill()
|
||||
#draw_leaf(20)
|
||||
#end_fill()
|
||||
#save('yellow.png')
|
||||
|
||||
#fillcolor('orange')
|
||||
#begin_fill()
|
||||
#draw_leaf(20)
|
||||
#end_fill()
|
||||
#save('orange.png')
|
||||
|
||||
#fillcolor('red')
|
||||
#begin_fill()
|
||||
#draw_leaf(20)
|
||||
#end_fill()
|
||||
#save('red.png')
|
11
drawing.py
11
drawing.py
|
@ -2,17 +2,18 @@
|
|||
# ----------
|
||||
# By Stacy S
|
||||
#
|
||||
# (Drew a tree, and the leaves change colors. Trying to make the leaves fall now?)
|
||||
# (Drew a tree, and the leaves change colors.)
|
||||
|
||||
from turtle import *
|
||||
from shapes import *
|
||||
from superturt import *
|
||||
|
||||
colors = ['green', 'greenyellow', 'yellow', 'goldenrod', 'darkorange', 'orange', 'orangered', 'red', 'firebrick', 'brown']
|
||||
fly(0,-150)
|
||||
|
||||
colors = ['green', 'greenyellow', 'yellow', 'goldenrod', 'darkorange', 'orange', 'orangered', 'red', 'violetred4', 'violetred', 'purple4', 'midnightblue']
|
||||
for color in colors:
|
||||
with no_delay():
|
||||
with restore_state_when_finished():
|
||||
draw_tree_nl(20)
|
||||
draw_tree_nl(25)
|
||||
with restore_state_when_finished():
|
||||
draw_tree_wl(20, color)
|
||||
|
||||
draw_tree_wl(25, color)
|
39
shapes.py
39
shapes.py
|
@ -21,42 +21,37 @@ def draw_leaves(color):
|
|||
right(115)
|
||||
pendown()
|
||||
|
||||
def draw_trunk(size):
|
||||
forward(10*size)
|
||||
circle(size/8,90)
|
||||
|
||||
def draw_branch_nl(size):
|
||||
angles = [150, 150, 150, 150, 150, 150, 90]
|
||||
angles = [165, 150, 150, 150, 150, 150, 150, 165, 105]
|
||||
for angle in angles:
|
||||
branch_end_nl(size)
|
||||
circle(size/8,angle)
|
||||
|
||||
def draw_branch_wl(size, color):
|
||||
angles = [150, 150, 150, 150, 150, 150, 90]
|
||||
angles = [165, 150, 150, 150, 150, 150, 150, 165, 105]
|
||||
for angle in angles:
|
||||
branch_end_wl(size, color)
|
||||
circle(size/8,angle)
|
||||
draw_leaves(color)
|
||||
|
||||
def draw_turn(d1,a1,d2,a2,d3,a3,d4):
|
||||
forward(d1)
|
||||
right(a1)
|
||||
forward(d2)
|
||||
right(a2)
|
||||
forward(d3)
|
||||
right(a3)
|
||||
forward(d4)
|
||||
|
||||
def tip_nl(size):
|
||||
forward(size)
|
||||
right(45)
|
||||
forward(size/10)
|
||||
right(90)
|
||||
forward(size/10)
|
||||
right(45)
|
||||
forward(size)
|
||||
draw_turn(size,45,size/10,90,size/10,45,size)
|
||||
|
||||
def tip_wl(size, color):
|
||||
tip_nl(size)
|
||||
draw_leaves(color)
|
||||
|
||||
def branching_nl(ang1, d1, ang2, d2, ang3):
|
||||
right(ang1)
|
||||
forward(d1)
|
||||
right(ang2)
|
||||
forward(d2)
|
||||
right(ang3)
|
||||
draw_turn(0,ang1,d1,ang2,d2,ang3,0)
|
||||
|
||||
def branching_wl(ang1, d1, ang2, d2, ang3, color):
|
||||
branching_nl(ang1, d1, ang2, d2, ang3)
|
||||
|
@ -92,10 +87,11 @@ def branch_end_nl(size):
|
|||
forward(4*size)
|
||||
|
||||
def draw_tree_nl(size):
|
||||
fillcolor('brown')
|
||||
fillcolor('rosybrown4')
|
||||
begin_fill()
|
||||
circle(size/4,90)
|
||||
draw_trunk(size)
|
||||
forward(10*size)
|
||||
circle(size/8,105)
|
||||
draw_branch_nl(size)
|
||||
forward(10*size)
|
||||
circle(size/4,90)
|
||||
|
@ -104,7 +100,8 @@ def draw_tree_nl(size):
|
|||
def draw_tree_wl(size, color):
|
||||
penup()
|
||||
circle(size/4,90)
|
||||
draw_trunk(size)
|
||||
forward(10*size)
|
||||
circle(size/8,105)
|
||||
draw_branch_wl(size, color)
|
||||
forward(10*size)
|
||||
circle(size/4,90)
|
30
superturt.py
30
superturt.py
|
@ -359,4 +359,32 @@ def save(filename):
|
|||
getcanvas().postscript(file=temp_file)
|
||||
cmd = f"convert {temp_file} -colorspace RGB {filename}"
|
||||
run(cmd, shell=True, check=True)
|
||||
temp_file.unlink()
|
||||
temp_file.unlink()
|
||||
|
||||
from turtle import *
|
||||
from itertools import chain, cycle
|
||||
|
||||
def fly(x,y):
|
||||
"""Moves the turtle to (x,y) without drawing.
|
||||
|
||||
This is really just a simple shortcut for lifting the pen,
|
||||
going to a position, and putting the pen down again. But it's such
|
||||
a commonly-used pattern that it makes sense to put it into a function.
|
||||
Here's an example::
|
||||
|
||||
from turtle import forward, right
|
||||
from superturtle.movement import fly
|
||||
|
||||
def square(size):
|
||||
for side in range(4):
|
||||
forward(size)
|
||||
right(90)
|
||||
|
||||
for col in range(10):
|
||||
for row in range(10):
|
||||
fly(40 * col, 40 * row)
|
||||
square(20)
|
||||
"""
|
||||
penup()
|
||||
goto(x,y)
|
||||
pendown()
|
Loading…
Reference in New Issue