generated from mwc/project_drawing
I got the leaves on te tree to change colors!
I'm not sure if I did what I was supposed to, because I never got the animate function to work, I just used a list of colors. I had some problems using the superturtle library, as I mentioned last time, and I am still unable to figure out how to use the easing stuff, so I decided to try to use mostly un-super turtle, with some of the superturtle stuff that was working from copying the source code into the superturt.py program file.
This commit is contained in:
parent
9ccad6051e
commit
9bc18ac771
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,148 @@
|
||||||
|
%!PS-Adobe-3.0 EPSF-3.0
|
||||||
|
%%Creator: Tk Canvas Widget
|
||||||
|
%%For: root
|
||||||
|
%%Title: Window .!canvas
|
||||||
|
%%CreationDate: Thu Sep 26 21:58:38 2024
|
||||||
|
%%BoundingBox: -53 92 666 700
|
||||||
|
%%Pages: 1
|
||||||
|
%%DocumentData: Clean7Bit
|
||||||
|
%%Orientation: Portrait
|
||||||
|
%%EndComments
|
||||||
|
|
||||||
|
%%BeginProlog
|
||||||
|
% This is a standard prolog for Postscript generated by Tk's canvas
|
||||||
|
% widget.
|
||||||
|
/CurrentEncoding [
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quotesingle
|
||||||
|
/parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
|
||||||
|
/zero/one/two/three/four/five/six/seven
|
||||||
|
/eight/nine/colon/semicolon/less/equal/greater/question
|
||||||
|
/at/A/B/C/D/E/F/G
|
||||||
|
/H/I/J/K/L/M/N/O
|
||||||
|
/P/Q/R/S/T/U/V/W
|
||||||
|
/X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
|
||||||
|
/grave/a/b/c/d/e/f/g
|
||||||
|
/h/i/j/k/l/m/n/o
|
||||||
|
/p/q/r/s/t/u/v/w
|
||||||
|
/x/y/z/braceleft/bar/braceright/asciitilde/space
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/space/space/space/space/space/space/space
|
||||||
|
/space/exclamdown/cent/sterling/currency/yen/brokenbar/section
|
||||||
|
/dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
|
||||||
|
/degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
|
||||||
|
/cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
|
||||||
|
/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
|
||||||
|
/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
|
||||||
|
/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
|
||||||
|
/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
|
||||||
|
/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
|
||||||
|
/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
|
||||||
|
/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
|
||||||
|
/oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis
|
||||||
|
] def
|
||||||
|
50 dict begin
|
||||||
|
/baseline 0 def
|
||||||
|
/stipimage 0 def
|
||||||
|
/height 0 def
|
||||||
|
/justify 0 def
|
||||||
|
/lineLength 0 def
|
||||||
|
/spacing 0 def
|
||||||
|
/stipple 0 def
|
||||||
|
/strings 0 def
|
||||||
|
/xoffset 0 def
|
||||||
|
/yoffset 0 def
|
||||||
|
/tmpstip null def
|
||||||
|
/baselineSampler ( TXygqPZ) def
|
||||||
|
baselineSampler 0 196 put
|
||||||
|
/cstringshow {{ dup type /stringtype eq { show } { glyphshow } ifelse } forall } bind def
|
||||||
|
/cstringwidth {0 exch 0 exch { dup type /stringtype eq { stringwidth } { currentfont /Encoding get exch 1 exch put (\001) stringwidth } ifelse exch 3 1 roll add 3 1 roll add exch } forall } bind def
|
||||||
|
/ISOEncode {dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall /Encoding CurrentEncoding def currentdict end /Temporary exch definefont } bind def
|
||||||
|
/StrokeClip {{strokepath} stopped { (This Postscript printer gets limitcheck overflows when) = (stippling dashed lines; lines will be printed solid instead.) = [] 0 setdash strokepath} if clip } bind def
|
||||||
|
/EvenPixels {dup 0 matrix currentmatrix dtransform dup mul exch dup mul add sqrt dup round dup 1 lt {pop 1} if exch div mul } bind def
|
||||||
|
/StippleFill {/tmpstip 1 index def 1 EvenPixels dup scale pathbbox 4 2 roll 5 index div dup 0 lt {1 sub} if cvi 5 index mul 4 1 roll 6 index div dup 0 lt {1 sub} if cvi 6 index mul 3 2 roll 6 index exch { 2 index 5 index 3 index { gsave 1 index exch translate 5 index 5 index true matrix tmpstip imagemask grestore } for pop } for pop pop pop pop pop } bind def
|
||||||
|
/AdjustColor {CL 2 lt { currentgray CL 0 eq { .5 lt {0} {1} ifelse } if setgray } if } bind def
|
||||||
|
/DrawText {/stipple exch def /justify exch def /yoffset exch def /xoffset exch def /spacing exch def /strings exch def /lineLength 0 def strings { cstringwidth pop dup lineLength gt {/lineLength exch def} {pop} ifelse newpath } forall 0 0 moveto baselineSampler false charpath pathbbox dup /baseline exch def exch pop exch sub /height exch def pop newpath translate rotate lineLength xoffset mul strings length 1 sub spacing mul height add yoffset mul translate justify lineLength mul baseline neg translate strings { dup cstringwidth pop justify neg mul 0 moveto stipple { gsave /char (X) def { dup type /stringtype eq { { char 0 3 -1 roll put currentpoint gsave char true charpath clip StippleText grestore char stringwidth translate moveto } forall } { currentfont /Encoding get exch 1 exch put currentpoint gsave (\001) true charpath clip StippleText grestore (\001) stringwidth translate moveto } ifelse } forall grestore } {cstringshow} ifelse 0 spacing neg translate } forall } bind def
|
||||||
|
/TkPhotoColor {gsave 32 dict begin /tinteger exch def /transparent 1 string def transparent 0 tinteger put /olddict exch def olddict /DataSource get dup type /filetype ne { olddict /DataSource 3 -1 roll 0 () /SubFileDecode filter put } { pop } ifelse /newdict olddict maxlength dict def olddict newdict copy pop /w newdict /Width get def /crpp newdict /Decode get length 2 idiv def /str w string def /pix w crpp mul string def /substrlen 2 w log 2 log div floor exp cvi def /substrs [ { substrlen string 0 1 substrlen 1 sub { 1 index exch tinteger put } for /substrlen substrlen 2 idiv def substrlen 0 eq {exit} if } loop ] def /h newdict /Height get def 1 w div 1 h div matrix scale olddict /ImageMatrix get exch matrix concatmatrix matrix invertmatrix concat newdict /Height 1 put newdict /DataSource pix put /mat [w 0 0 h 0 0] def newdict /ImageMatrix mat put 0 1 h 1 sub { mat 5 3 -1 roll neg put olddict /DataSource get str readstring pop pop /tail str def /x 0 def olddict /DataSource get pix readstring pop pop { tail transparent search dup /done exch not def {exch pop exch pop} if /w1 exch length def w1 0 ne { newdict /DataSource pix x crpp mul w1 crpp mul getinterval put newdict /Width w1 put mat 4 x neg put /x x w1 add def newdict image /tail tail w1 tail length w1 sub getinterval def } if done {exit} if tail substrs { anchorsearch {pop} if } forall /tail exch def tail length 0 eq {exit} if /x w tail length sub def } loop } for end grestore } bind def
|
||||||
|
/TkPhotoMono {gsave 32 dict begin /dummyInteger exch def /olddict exch def olddict /DataSource get dup type /filetype ne { olddict /DataSource 3 -1 roll 0 () /SubFileDecode filter put } { pop } ifelse /newdict olddict maxlength dict def olddict newdict copy pop /w newdict /Width get def /pix w 7 add 8 idiv string def /h newdict /Height get def 1 w div 1 h div matrix scale olddict /ImageMatrix get exch matrix concatmatrix matrix invertmatrix concat newdict /Height 1 put newdict /DataSource pix put /mat [w 0 0 h 0 0] def newdict /ImageMatrix mat put 0 1 h 1 sub { mat 5 3 -1 roll neg put 0.000 0.000 0.000 setrgbcolor olddict /DataSource get pix readstring pop pop newdict /DataSource pix put newdict imagemask 1.000 1.000 1.000 setrgbcolor olddict /DataSource get pix readstring pop pop newdict /DataSource pix put newdict imagemask } for end grestore } bind def
|
||||||
|
%%EndProlog
|
||||||
|
%%BeginSetup
|
||||||
|
/CL 2 def
|
||||||
|
%%EndSetup
|
||||||
|
|
||||||
|
%%Page: 1 1
|
||||||
|
save
|
||||||
|
306.0 396.0 translate
|
||||||
|
0.75 0.75 scale
|
||||||
|
2 -404 translate
|
||||||
|
-481 808 moveto 477 808 lineto 477 0 lineto -481 0 lineto closepath clip newpath
|
||||||
|
gsave
|
||||||
|
grestore
|
||||||
|
gsave
|
||||||
|
grestore
|
||||||
|
gsave
|
||||||
|
0 402 moveto
|
||||||
|
7.65366864730179 403.522409349774 lineto
|
||||||
|
14.1421356237309 407.857864376269 lineto
|
||||||
|
18.4775906502257 414.346331352698 lineto
|
||||||
|
20 422 lineto
|
||||||
|
14.2597485145237 420.858192987669 lineto
|
||||||
|
9.39339828220179 417.606601717798 lineto
|
||||||
|
6.1418070123307 412.740251485476 lineto
|
||||||
|
5.00000000000001 407 lineto
|
||||||
|
4.3301270189222 404.5 lineto
|
||||||
|
2.50000000000001 402.669872981078 lineto
|
||||||
|
1.19904086659517e-14 402 lineto
|
||||||
|
0 402 lineto
|
||||||
|
0.000 0.502 0.000 setrgbcolor AdjustColor
|
||||||
|
eofill
|
||||||
|
grestore
|
||||||
|
gsave
|
||||||
|
0 402 moveto
|
||||||
|
7.65366864730179 403.522409349774 lineto
|
||||||
|
14.1421356237309 407.857864376269 lineto
|
||||||
|
18.4775906502257 414.346331352698 lineto
|
||||||
|
20 422 lineto
|
||||||
|
14.2597485145237 420.858192987669 lineto
|
||||||
|
9.39339828220179 417.606601717798 lineto
|
||||||
|
6.1418070123307 412.740251485476 lineto
|
||||||
|
5.00000000000001 407 lineto
|
||||||
|
4.3301270189222 404.5 lineto
|
||||||
|
2.50000000000001 402.669872981078 lineto
|
||||||
|
1.19904086659517e-14 402 lineto
|
||||||
|
1 setlinecap
|
||||||
|
1 setlinejoin
|
||||||
|
1 setlinewidth
|
||||||
|
[] 0 setdash
|
||||||
|
0.000 0.000 0.000 setrgbcolor AdjustColor
|
||||||
|
stroke
|
||||||
|
grestore
|
||||||
|
gsave
|
||||||
|
1.19904086659517e-14 402 moveto
|
||||||
|
9.00000000000002 397 lineto
|
||||||
|
7.00000000000001 402 lineto
|
||||||
|
9.00000000000001 407 lineto
|
||||||
|
1.19904086659517e-14 402 lineto
|
||||||
|
0.000 0.502 0.000 setrgbcolor AdjustColor
|
||||||
|
eofill
|
||||||
|
1.19904086659517e-14 402 moveto
|
||||||
|
9.00000000000002 397 lineto
|
||||||
|
7.00000000000001 402 lineto
|
||||||
|
9.00000000000001 407 lineto
|
||||||
|
1.19904086659517e-14 402 lineto
|
||||||
|
1 setlinejoin 1 setlinecap
|
||||||
|
1 setlinewidth
|
||||||
|
[] 0 setdash
|
||||||
|
0.000 0.000 0.000 setrgbcolor AdjustColor
|
||||||
|
stroke
|
||||||
|
grestore
|
||||||
|
restore showpage
|
||||||
|
|
||||||
|
%%Trailer
|
||||||
|
end
|
||||||
|
%%EOF
|
|
@ -4,28 +4,26 @@ from shapes import *
|
||||||
|
|
||||||
# I'm trying to figure out how to get the leaves to change colors.
|
# I'm trying to figure out how to get the leaves to change colors.
|
||||||
|
|
||||||
with no_delay():
|
fillcolor('green')
|
||||||
fillcolor('green')
|
begin_fill()
|
||||||
begin_fill()
|
draw_leaf(20)
|
||||||
draw_leaf(20)
|
end_fill()
|
||||||
end_fill()
|
save('green.png')
|
||||||
|
|
||||||
with no_delay():
|
#fillcolor('yellow')
|
||||||
fillcolor('yellow')
|
#begin_fill()
|
||||||
begin_fill()
|
#draw_leaf(20)
|
||||||
draw_leaf(20)
|
#end_fill()
|
||||||
end_fill()
|
#save('yellow.png')
|
||||||
|
|
||||||
with no_delay():
|
#fillcolor('orange')
|
||||||
fillcolor('orange')
|
#begin_fill()
|
||||||
begin_fill()
|
#draw_leaf(20)
|
||||||
draw_leaf(20)
|
#end_fill()
|
||||||
end_fill()
|
#save('orange.png')
|
||||||
|
|
||||||
with no_delay():
|
#fillcolor('red')
|
||||||
fillcolor('red')
|
#begin_fill()
|
||||||
begin_fill()
|
#draw_leaf(20)
|
||||||
draw_leaf(20)
|
#end_fill()
|
||||||
end_fill()
|
#save('red.png')
|
||||||
|
|
||||||
input()
|
|
10
drawing.py
10
drawing.py
|
@ -2,15 +2,17 @@
|
||||||
# ----------
|
# ----------
|
||||||
# By Stacy S
|
# By Stacy S
|
||||||
#
|
#
|
||||||
# (Drew a tree. Trying to make it change colors.)
|
# (Drew a tree, and the leaves change colors. Trying to make the leaves fall now?)
|
||||||
|
|
||||||
from turtle import *
|
from turtle import *
|
||||||
from shapes import *
|
from shapes import *
|
||||||
from superturt import *
|
from superturt import *
|
||||||
|
|
||||||
with no_delay():
|
colors = ['green', 'greenyellow', 'yellow', 'goldenrod', 'darkorange', 'orange', 'orangered', 'red', 'firebrick', 'brown']
|
||||||
for frame in animate(frames=6, loop=True, debug=False):
|
for color in colors:
|
||||||
|
with no_delay():
|
||||||
with restore_state_when_finished():
|
with restore_state_when_finished():
|
||||||
draw_tree_nl(20)
|
draw_tree_nl(20)
|
||||||
with restore_state_when_finished():
|
with restore_state_when_finished():
|
||||||
draw_tree_wl(20)
|
draw_tree_wl(20, color)
|
||||||
|
|
||||||
|
|
54
shapes.py
54
shapes.py
|
@ -2,20 +2,20 @@ from turtle import *
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
from superturt import *
|
from superturt import *
|
||||||
|
|
||||||
def draw_leaf(size):
|
def draw_leaf(size, color):
|
||||||
pencolor('black')
|
pencolor('black')
|
||||||
# fillcolor('green')
|
fillcolor(color)
|
||||||
# begin_fill()
|
begin_fill()
|
||||||
circle(size,90)
|
circle(size,90)
|
||||||
right(270)
|
right(270)
|
||||||
circle(.75*size,90)
|
circle(.75*size,90)
|
||||||
circle(-.25*size,90)
|
circle(-.25*size,90)
|
||||||
# end_fill()
|
end_fill()
|
||||||
|
|
||||||
def draw_leaves():
|
def draw_leaves(color):
|
||||||
with restore_state_when_finished():
|
with restore_state_when_finished():
|
||||||
for number in range(11):
|
for number in range(11):
|
||||||
draw_leaf(20)
|
draw_leaf(20, color)
|
||||||
penup()
|
penup()
|
||||||
forward(10)
|
forward(10)
|
||||||
right(115)
|
right(115)
|
||||||
|
@ -31,12 +31,12 @@ def draw_branch_nl(size):
|
||||||
branch_end_nl(size)
|
branch_end_nl(size)
|
||||||
circle(size/8,angle)
|
circle(size/8,angle)
|
||||||
|
|
||||||
def draw_branch_wl(size):
|
def draw_branch_wl(size, color):
|
||||||
angles = [150, 150, 150, 150, 150, 150, 90]
|
angles = [150, 150, 150, 150, 150, 150, 90]
|
||||||
for angle in angles:
|
for angle in angles:
|
||||||
branch_end_wl(size)
|
branch_end_wl(size, color)
|
||||||
circle(size/8,angle)
|
circle(size/8,angle)
|
||||||
draw_leaves()
|
draw_leaves(color)
|
||||||
|
|
||||||
def tip_nl(size):
|
def tip_nl(size):
|
||||||
forward(size)
|
forward(size)
|
||||||
|
@ -47,9 +47,9 @@ def tip_nl(size):
|
||||||
right(45)
|
right(45)
|
||||||
forward(size)
|
forward(size)
|
||||||
|
|
||||||
def tip_wl(size):
|
def tip_wl(size, color):
|
||||||
tip_nl(size)
|
tip_nl(size)
|
||||||
draw_leaves()
|
draw_leaves(color)
|
||||||
|
|
||||||
def branching_nl(ang1, d1, ang2, d2, ang3):
|
def branching_nl(ang1, d1, ang2, d2, ang3):
|
||||||
right(ang1)
|
right(ang1)
|
||||||
|
@ -58,23 +58,23 @@ def branching_nl(ang1, d1, ang2, d2, ang3):
|
||||||
forward(d2)
|
forward(d2)
|
||||||
right(ang3)
|
right(ang3)
|
||||||
|
|
||||||
def branching_wl(ang1, d1, ang2, d2, ang3):
|
def branching_wl(ang1, d1, ang2, d2, ang3, color):
|
||||||
branching_nl(ang1, d1, ang2, d2, ang3)
|
branching_nl(ang1, d1, ang2, d2, ang3)
|
||||||
draw_leaves()
|
draw_leaves(color)
|
||||||
|
|
||||||
def branch_end_wl(size):
|
def branch_end_wl(size, color):
|
||||||
for number in range(3):
|
for number in range(3):
|
||||||
forward(size)
|
forward(size)
|
||||||
draw_leaves()
|
draw_leaves(color)
|
||||||
forward(size)
|
forward(size)
|
||||||
right(300)
|
right(300)
|
||||||
tip_wl(size)
|
tip_wl(size, color)
|
||||||
branching_wl(240,size,330,size,330)
|
branching_wl(240,size,330,size,330, color)
|
||||||
tip_wl(size)
|
tip_wl(size, color)
|
||||||
branching_wl(30,size,240,size,30)
|
branching_wl(30,size,240,size,30, color)
|
||||||
tip_wl(size)
|
tip_wl(size, color)
|
||||||
branching_wl(330,size,330,size,240)
|
branching_wl(330,size,330,size,240, color)
|
||||||
tip_wl(size)
|
tip_wl(size, color)
|
||||||
right(300)
|
right(300)
|
||||||
forward(4*size)
|
forward(4*size)
|
||||||
|
|
||||||
|
@ -99,16 +99,12 @@ def draw_tree_nl(size):
|
||||||
draw_branch_nl(size)
|
draw_branch_nl(size)
|
||||||
forward(10*size)
|
forward(10*size)
|
||||||
circle(size/4,90)
|
circle(size/4,90)
|
||||||
right(180)
|
|
||||||
forward(2*size)
|
|
||||||
end_fill()
|
end_fill()
|
||||||
|
|
||||||
def draw_tree_wl(size):
|
def draw_tree_wl(size, color):
|
||||||
penup()
|
penup()
|
||||||
circle(size/4,90)
|
circle(size/4,90)
|
||||||
draw_trunk(size)
|
draw_trunk(size)
|
||||||
draw_branch_wl(size)
|
draw_branch_wl(size, color)
|
||||||
forward(10*size)
|
forward(10*size)
|
||||||
circle(size/4,90)
|
circle(size/4,90)
|
||||||
right(180)
|
|
||||||
forward(2*size)
|
|
18
superturt.py
18
superturt.py
|
@ -343,4 +343,20 @@ def debug_iter(max_val=None):
|
||||||
value -= 1
|
value -= 1
|
||||||
|
|
||||||
class AnimationError(Exception):
|
class AnimationError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
from turtle import getcanvas
|
||||||
|
from pathlib import Path
|
||||||
|
from subprocess import run
|
||||||
|
|
||||||
|
def save(filename):
|
||||||
|
"""Saves the canvas as an image.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
filename (str): Location to save the file, including file extension.
|
||||||
|
"""
|
||||||
|
temp_file = Path("_temp.eps")
|
||||||
|
getcanvas().postscript(file=temp_file)
|
||||||
|
cmd = f"convert {temp_file} -colorspace RGB {filename}"
|
||||||
|
run(cmd, shell=True, check=True)
|
||||||
|
temp_file.unlink()
|
Loading…
Reference in New Issue