Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../usr/lib64/python3....
File: turtle.py
[2000] Fix | Delete
## three dummy methods to be implemented by child class:
[2001] Fix | Delete
[2002] Fix | Delete
def speed(self, s=0):
[2003] Fix | Delete
"""dummy method - to be overwritten by child class"""
[2004] Fix | Delete
def _tracer(self, a=None, b=None):
[2005] Fix | Delete
"""dummy method - to be overwritten by child class"""
[2006] Fix | Delete
def _delay(self, n=None):
[2007] Fix | Delete
"""dummy method - to be overwritten by child class"""
[2008] Fix | Delete
[2009] Fix | Delete
fd = forward
[2010] Fix | Delete
bk = back
[2011] Fix | Delete
backward = back
[2012] Fix | Delete
rt = right
[2013] Fix | Delete
lt = left
[2014] Fix | Delete
position = pos
[2015] Fix | Delete
setpos = goto
[2016] Fix | Delete
setposition = goto
[2017] Fix | Delete
seth = setheading
[2018] Fix | Delete
[2019] Fix | Delete
[2020] Fix | Delete
class TPen(object):
[2021] Fix | Delete
"""Drawing part of the RawTurtle.
[2022] Fix | Delete
Implements drawing properties.
[2023] Fix | Delete
"""
[2024] Fix | Delete
def __init__(self, resizemode=_CFG["resizemode"]):
[2025] Fix | Delete
self._resizemode = resizemode # or "user" or "noresize"
[2026] Fix | Delete
self.undobuffer = None
[2027] Fix | Delete
TPen._reset(self)
[2028] Fix | Delete
[2029] Fix | Delete
def _reset(self, pencolor=_CFG["pencolor"],
[2030] Fix | Delete
fillcolor=_CFG["fillcolor"]):
[2031] Fix | Delete
self._pensize = 1
[2032] Fix | Delete
self._shown = True
[2033] Fix | Delete
self._pencolor = pencolor
[2034] Fix | Delete
self._fillcolor = fillcolor
[2035] Fix | Delete
self._drawing = True
[2036] Fix | Delete
self._speed = 3
[2037] Fix | Delete
self._stretchfactor = (1., 1.)
[2038] Fix | Delete
self._shearfactor = 0.
[2039] Fix | Delete
self._tilt = 0.
[2040] Fix | Delete
self._shapetrafo = (1., 0., 0., 1.)
[2041] Fix | Delete
self._outlinewidth = 1
[2042] Fix | Delete
[2043] Fix | Delete
def resizemode(self, rmode=None):
[2044] Fix | Delete
"""Set resizemode to one of the values: "auto", "user", "noresize".
[2045] Fix | Delete
[2046] Fix | Delete
(Optional) Argument:
[2047] Fix | Delete
rmode -- one of the strings "auto", "user", "noresize"
[2048] Fix | Delete
[2049] Fix | Delete
Different resizemodes have the following effects:
[2050] Fix | Delete
- "auto" adapts the appearance of the turtle
[2051] Fix | Delete
corresponding to the value of pensize.
[2052] Fix | Delete
- "user" adapts the appearance of the turtle according to the
[2053] Fix | Delete
values of stretchfactor and outlinewidth (outline),
[2054] Fix | Delete
which are set by shapesize()
[2055] Fix | Delete
- "noresize" no adaption of the turtle's appearance takes place.
[2056] Fix | Delete
If no argument is given, return current resizemode.
[2057] Fix | Delete
resizemode("user") is called by a call of shapesize with arguments.
[2058] Fix | Delete
[2059] Fix | Delete
[2060] Fix | Delete
Examples (for a Turtle instance named turtle):
[2061] Fix | Delete
>>> turtle.resizemode("noresize")
[2062] Fix | Delete
>>> turtle.resizemode()
[2063] Fix | Delete
'noresize'
[2064] Fix | Delete
"""
[2065] Fix | Delete
if rmode is None:
[2066] Fix | Delete
return self._resizemode
[2067] Fix | Delete
rmode = rmode.lower()
[2068] Fix | Delete
if rmode in ["auto", "user", "noresize"]:
[2069] Fix | Delete
self.pen(resizemode=rmode)
[2070] Fix | Delete
[2071] Fix | Delete
def pensize(self, width=None):
[2072] Fix | Delete
"""Set or return the line thickness.
[2073] Fix | Delete
[2074] Fix | Delete
Aliases: pensize | width
[2075] Fix | Delete
[2076] Fix | Delete
Argument:
[2077] Fix | Delete
width -- positive number
[2078] Fix | Delete
[2079] Fix | Delete
Set the line thickness to width or return it. If resizemode is set
[2080] Fix | Delete
to "auto" and turtleshape is a polygon, that polygon is drawn with
[2081] Fix | Delete
the same line thickness. If no argument is given, current pensize
[2082] Fix | Delete
is returned.
[2083] Fix | Delete
[2084] Fix | Delete
Example (for a Turtle instance named turtle):
[2085] Fix | Delete
>>> turtle.pensize()
[2086] Fix | Delete
1
[2087] Fix | Delete
>>> turtle.pensize(10) # from here on lines of width 10 are drawn
[2088] Fix | Delete
"""
[2089] Fix | Delete
if width is None:
[2090] Fix | Delete
return self._pensize
[2091] Fix | Delete
self.pen(pensize=width)
[2092] Fix | Delete
[2093] Fix | Delete
[2094] Fix | Delete
def penup(self):
[2095] Fix | Delete
"""Pull the pen up -- no drawing when moving.
[2096] Fix | Delete
[2097] Fix | Delete
Aliases: penup | pu | up
[2098] Fix | Delete
[2099] Fix | Delete
No argument
[2100] Fix | Delete
[2101] Fix | Delete
Example (for a Turtle instance named turtle):
[2102] Fix | Delete
>>> turtle.penup()
[2103] Fix | Delete
"""
[2104] Fix | Delete
if not self._drawing:
[2105] Fix | Delete
return
[2106] Fix | Delete
self.pen(pendown=False)
[2107] Fix | Delete
[2108] Fix | Delete
def pendown(self):
[2109] Fix | Delete
"""Pull the pen down -- drawing when moving.
[2110] Fix | Delete
[2111] Fix | Delete
Aliases: pendown | pd | down
[2112] Fix | Delete
[2113] Fix | Delete
No argument.
[2114] Fix | Delete
[2115] Fix | Delete
Example (for a Turtle instance named turtle):
[2116] Fix | Delete
>>> turtle.pendown()
[2117] Fix | Delete
"""
[2118] Fix | Delete
if self._drawing:
[2119] Fix | Delete
return
[2120] Fix | Delete
self.pen(pendown=True)
[2121] Fix | Delete
[2122] Fix | Delete
def isdown(self):
[2123] Fix | Delete
"""Return True if pen is down, False if it's up.
[2124] Fix | Delete
[2125] Fix | Delete
No argument.
[2126] Fix | Delete
[2127] Fix | Delete
Example (for a Turtle instance named turtle):
[2128] Fix | Delete
>>> turtle.penup()
[2129] Fix | Delete
>>> turtle.isdown()
[2130] Fix | Delete
False
[2131] Fix | Delete
>>> turtle.pendown()
[2132] Fix | Delete
>>> turtle.isdown()
[2133] Fix | Delete
True
[2134] Fix | Delete
"""
[2135] Fix | Delete
return self._drawing
[2136] Fix | Delete
[2137] Fix | Delete
def speed(self, speed=None):
[2138] Fix | Delete
""" Return or set the turtle's speed.
[2139] Fix | Delete
[2140] Fix | Delete
Optional argument:
[2141] Fix | Delete
speed -- an integer in the range 0..10 or a speedstring (see below)
[2142] Fix | Delete
[2143] Fix | Delete
Set the turtle's speed to an integer value in the range 0 .. 10.
[2144] Fix | Delete
If no argument is given: return current speed.
[2145] Fix | Delete
[2146] Fix | Delete
If input is a number greater than 10 or smaller than 0.5,
[2147] Fix | Delete
speed is set to 0.
[2148] Fix | Delete
Speedstrings are mapped to speedvalues in the following way:
[2149] Fix | Delete
'fastest' : 0
[2150] Fix | Delete
'fast' : 10
[2151] Fix | Delete
'normal' : 6
[2152] Fix | Delete
'slow' : 3
[2153] Fix | Delete
'slowest' : 1
[2154] Fix | Delete
speeds from 1 to 10 enforce increasingly faster animation of
[2155] Fix | Delete
line drawing and turtle turning.
[2156] Fix | Delete
[2157] Fix | Delete
Attention:
[2158] Fix | Delete
speed = 0 : *no* animation takes place. forward/back makes turtle jump
[2159] Fix | Delete
and likewise left/right make the turtle turn instantly.
[2160] Fix | Delete
[2161] Fix | Delete
Example (for a Turtle instance named turtle):
[2162] Fix | Delete
>>> turtle.speed(3)
[2163] Fix | Delete
"""
[2164] Fix | Delete
speeds = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
[2165] Fix | Delete
if speed is None:
[2166] Fix | Delete
return self._speed
[2167] Fix | Delete
if speed in speeds:
[2168] Fix | Delete
speed = speeds[speed]
[2169] Fix | Delete
elif 0.5 < speed < 10.5:
[2170] Fix | Delete
speed = int(round(speed))
[2171] Fix | Delete
else:
[2172] Fix | Delete
speed = 0
[2173] Fix | Delete
self.pen(speed=speed)
[2174] Fix | Delete
[2175] Fix | Delete
def color(self, *args):
[2176] Fix | Delete
"""Return or set the pencolor and fillcolor.
[2177] Fix | Delete
[2178] Fix | Delete
Arguments:
[2179] Fix | Delete
Several input formats are allowed.
[2180] Fix | Delete
They use 0, 1, 2, or 3 arguments as follows:
[2181] Fix | Delete
[2182] Fix | Delete
color()
[2183] Fix | Delete
Return the current pencolor and the current fillcolor
[2184] Fix | Delete
as a pair of color specification strings as are returned
[2185] Fix | Delete
by pencolor and fillcolor.
[2186] Fix | Delete
color(colorstring), color((r,g,b)), color(r,g,b)
[2187] Fix | Delete
inputs as in pencolor, set both, fillcolor and pencolor,
[2188] Fix | Delete
to the given value.
[2189] Fix | Delete
color(colorstring1, colorstring2),
[2190] Fix | Delete
color((r1,g1,b1), (r2,g2,b2))
[2191] Fix | Delete
equivalent to pencolor(colorstring1) and fillcolor(colorstring2)
[2192] Fix | Delete
and analogously, if the other input format is used.
[2193] Fix | Delete
[2194] Fix | Delete
If turtleshape is a polygon, outline and interior of that polygon
[2195] Fix | Delete
is drawn with the newly set colors.
[2196] Fix | Delete
For more info see: pencolor, fillcolor
[2197] Fix | Delete
[2198] Fix | Delete
Example (for a Turtle instance named turtle):
[2199] Fix | Delete
>>> turtle.color('red', 'green')
[2200] Fix | Delete
>>> turtle.color()
[2201] Fix | Delete
('red', 'green')
[2202] Fix | Delete
>>> colormode(255)
[2203] Fix | Delete
>>> color((40, 80, 120), (160, 200, 240))
[2204] Fix | Delete
>>> color()
[2205] Fix | Delete
('#285078', '#a0c8f0')
[2206] Fix | Delete
"""
[2207] Fix | Delete
if args:
[2208] Fix | Delete
l = len(args)
[2209] Fix | Delete
if l == 1:
[2210] Fix | Delete
pcolor = fcolor = args[0]
[2211] Fix | Delete
elif l == 2:
[2212] Fix | Delete
pcolor, fcolor = args
[2213] Fix | Delete
elif l == 3:
[2214] Fix | Delete
pcolor = fcolor = args
[2215] Fix | Delete
pcolor = self._colorstr(pcolor)
[2216] Fix | Delete
fcolor = self._colorstr(fcolor)
[2217] Fix | Delete
self.pen(pencolor=pcolor, fillcolor=fcolor)
[2218] Fix | Delete
else:
[2219] Fix | Delete
return self._color(self._pencolor), self._color(self._fillcolor)
[2220] Fix | Delete
[2221] Fix | Delete
def pencolor(self, *args):
[2222] Fix | Delete
""" Return or set the pencolor.
[2223] Fix | Delete
[2224] Fix | Delete
Arguments:
[2225] Fix | Delete
Four input formats are allowed:
[2226] Fix | Delete
- pencolor()
[2227] Fix | Delete
Return the current pencolor as color specification string,
[2228] Fix | Delete
possibly in hex-number format (see example).
[2229] Fix | Delete
May be used as input to another color/pencolor/fillcolor call.
[2230] Fix | Delete
- pencolor(colorstring)
[2231] Fix | Delete
s is a Tk color specification string, such as "red" or "yellow"
[2232] Fix | Delete
- pencolor((r, g, b))
[2233] Fix | Delete
*a tuple* of r, g, and b, which represent, an RGB color,
[2234] Fix | Delete
and each of r, g, and b are in the range 0..colormode,
[2235] Fix | Delete
where colormode is either 1.0 or 255
[2236] Fix | Delete
- pencolor(r, g, b)
[2237] Fix | Delete
r, g, and b represent an RGB color, and each of r, g, and b
[2238] Fix | Delete
are in the range 0..colormode
[2239] Fix | Delete
[2240] Fix | Delete
If turtleshape is a polygon, the outline of that polygon is drawn
[2241] Fix | Delete
with the newly set pencolor.
[2242] Fix | Delete
[2243] Fix | Delete
Example (for a Turtle instance named turtle):
[2244] Fix | Delete
>>> turtle.pencolor('brown')
[2245] Fix | Delete
>>> tup = (0.2, 0.8, 0.55)
[2246] Fix | Delete
>>> turtle.pencolor(tup)
[2247] Fix | Delete
>>> turtle.pencolor()
[2248] Fix | Delete
'#33cc8c'
[2249] Fix | Delete
"""
[2250] Fix | Delete
if args:
[2251] Fix | Delete
color = self._colorstr(args)
[2252] Fix | Delete
if color == self._pencolor:
[2253] Fix | Delete
return
[2254] Fix | Delete
self.pen(pencolor=color)
[2255] Fix | Delete
else:
[2256] Fix | Delete
return self._color(self._pencolor)
[2257] Fix | Delete
[2258] Fix | Delete
def fillcolor(self, *args):
[2259] Fix | Delete
""" Return or set the fillcolor.
[2260] Fix | Delete
[2261] Fix | Delete
Arguments:
[2262] Fix | Delete
Four input formats are allowed:
[2263] Fix | Delete
- fillcolor()
[2264] Fix | Delete
Return the current fillcolor as color specification string,
[2265] Fix | Delete
possibly in hex-number format (see example).
[2266] Fix | Delete
May be used as input to another color/pencolor/fillcolor call.
[2267] Fix | Delete
- fillcolor(colorstring)
[2268] Fix | Delete
s is a Tk color specification string, such as "red" or "yellow"
[2269] Fix | Delete
- fillcolor((r, g, b))
[2270] Fix | Delete
*a tuple* of r, g, and b, which represent, an RGB color,
[2271] Fix | Delete
and each of r, g, and b are in the range 0..colormode,
[2272] Fix | Delete
where colormode is either 1.0 or 255
[2273] Fix | Delete
- fillcolor(r, g, b)
[2274] Fix | Delete
r, g, and b represent an RGB color, and each of r, g, and b
[2275] Fix | Delete
are in the range 0..colormode
[2276] Fix | Delete
[2277] Fix | Delete
If turtleshape is a polygon, the interior of that polygon is drawn
[2278] Fix | Delete
with the newly set fillcolor.
[2279] Fix | Delete
[2280] Fix | Delete
Example (for a Turtle instance named turtle):
[2281] Fix | Delete
>>> turtle.fillcolor('violet')
[2282] Fix | Delete
>>> col = turtle.pencolor()
[2283] Fix | Delete
>>> turtle.fillcolor(col)
[2284] Fix | Delete
>>> turtle.fillcolor(0, .5, 0)
[2285] Fix | Delete
"""
[2286] Fix | Delete
if args:
[2287] Fix | Delete
color = self._colorstr(args)
[2288] Fix | Delete
if color == self._fillcolor:
[2289] Fix | Delete
return
[2290] Fix | Delete
self.pen(fillcolor=color)
[2291] Fix | Delete
else:
[2292] Fix | Delete
return self._color(self._fillcolor)
[2293] Fix | Delete
[2294] Fix | Delete
def showturtle(self):
[2295] Fix | Delete
"""Makes the turtle visible.
[2296] Fix | Delete
[2297] Fix | Delete
Aliases: showturtle | st
[2298] Fix | Delete
[2299] Fix | Delete
No argument.
[2300] Fix | Delete
[2301] Fix | Delete
Example (for a Turtle instance named turtle):
[2302] Fix | Delete
>>> turtle.hideturtle()
[2303] Fix | Delete
>>> turtle.showturtle()
[2304] Fix | Delete
"""
[2305] Fix | Delete
self.pen(shown=True)
[2306] Fix | Delete
[2307] Fix | Delete
def hideturtle(self):
[2308] Fix | Delete
"""Makes the turtle invisible.
[2309] Fix | Delete
[2310] Fix | Delete
Aliases: hideturtle | ht
[2311] Fix | Delete
[2312] Fix | Delete
No argument.
[2313] Fix | Delete
[2314] Fix | Delete
It's a good idea to do this while you're in the
[2315] Fix | Delete
middle of a complicated drawing, because hiding
[2316] Fix | Delete
the turtle speeds up the drawing observably.
[2317] Fix | Delete
[2318] Fix | Delete
Example (for a Turtle instance named turtle):
[2319] Fix | Delete
>>> turtle.hideturtle()
[2320] Fix | Delete
"""
[2321] Fix | Delete
self.pen(shown=False)
[2322] Fix | Delete
[2323] Fix | Delete
def isvisible(self):
[2324] Fix | Delete
"""Return True if the Turtle is shown, False if it's hidden.
[2325] Fix | Delete
[2326] Fix | Delete
No argument.
[2327] Fix | Delete
[2328] Fix | Delete
Example (for a Turtle instance named turtle):
[2329] Fix | Delete
>>> turtle.hideturtle()
[2330] Fix | Delete
>>> print turtle.isvisible():
[2331] Fix | Delete
False
[2332] Fix | Delete
"""
[2333] Fix | Delete
return self._shown
[2334] Fix | Delete
[2335] Fix | Delete
def pen(self, pen=None, **pendict):
[2336] Fix | Delete
"""Return or set the pen's attributes.
[2337] Fix | Delete
[2338] Fix | Delete
Arguments:
[2339] Fix | Delete
pen -- a dictionary with some or all of the below listed keys.
[2340] Fix | Delete
**pendict -- one or more keyword-arguments with the below
[2341] Fix | Delete
listed keys as keywords.
[2342] Fix | Delete
[2343] Fix | Delete
Return or set the pen's attributes in a 'pen-dictionary'
[2344] Fix | Delete
with the following key/value pairs:
[2345] Fix | Delete
"shown" : True/False
[2346] Fix | Delete
"pendown" : True/False
[2347] Fix | Delete
"pencolor" : color-string or color-tuple
[2348] Fix | Delete
"fillcolor" : color-string or color-tuple
[2349] Fix | Delete
"pensize" : positive number
[2350] Fix | Delete
"speed" : number in range 0..10
[2351] Fix | Delete
"resizemode" : "auto" or "user" or "noresize"
[2352] Fix | Delete
"stretchfactor": (positive number, positive number)
[2353] Fix | Delete
"shearfactor": number
[2354] Fix | Delete
"outline" : positive number
[2355] Fix | Delete
"tilt" : number
[2356] Fix | Delete
[2357] Fix | Delete
This dictionary can be used as argument for a subsequent
[2358] Fix | Delete
pen()-call to restore the former pen-state. Moreover one
[2359] Fix | Delete
or more of these attributes can be provided as keyword-arguments.
[2360] Fix | Delete
This can be used to set several pen attributes in one statement.
[2361] Fix | Delete
[2362] Fix | Delete
[2363] Fix | Delete
Examples (for a Turtle instance named turtle):
[2364] Fix | Delete
>>> turtle.pen(fillcolor="black", pencolor="red", pensize=10)
[2365] Fix | Delete
>>> turtle.pen()
[2366] Fix | Delete
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
[2367] Fix | Delete
'pencolor': 'red', 'pendown': True, 'fillcolor': 'black',
[2368] Fix | Delete
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
[2369] Fix | Delete
>>> penstate=turtle.pen()
[2370] Fix | Delete
>>> turtle.color("yellow","")
[2371] Fix | Delete
>>> turtle.penup()
[2372] Fix | Delete
>>> turtle.pen()
[2373] Fix | Delete
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
[2374] Fix | Delete
'pencolor': 'yellow', 'pendown': False, 'fillcolor': '',
[2375] Fix | Delete
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
[2376] Fix | Delete
>>> p.pen(penstate, fillcolor="green")
[2377] Fix | Delete
>>> p.pen()
[2378] Fix | Delete
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
[2379] Fix | Delete
'pencolor': 'red', 'pendown': True, 'fillcolor': 'green',
[2380] Fix | Delete
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
[2381] Fix | Delete
"""
[2382] Fix | Delete
_pd = {"shown" : self._shown,
[2383] Fix | Delete
"pendown" : self._drawing,
[2384] Fix | Delete
"pencolor" : self._pencolor,
[2385] Fix | Delete
"fillcolor" : self._fillcolor,
[2386] Fix | Delete
"pensize" : self._pensize,
[2387] Fix | Delete
"speed" : self._speed,
[2388] Fix | Delete
"resizemode" : self._resizemode,
[2389] Fix | Delete
"stretchfactor" : self._stretchfactor,
[2390] Fix | Delete
"shearfactor" : self._shearfactor,
[2391] Fix | Delete
"outline" : self._outlinewidth,
[2392] Fix | Delete
"tilt" : self._tilt
[2393] Fix | Delete
}
[2394] Fix | Delete
[2395] Fix | Delete
if not (pen or pendict):
[2396] Fix | Delete
return _pd
[2397] Fix | Delete
[2398] Fix | Delete
if isinstance(pen, dict):
[2399] Fix | Delete
p = pen
[2400] Fix | Delete
else:
[2401] Fix | Delete
p = {}
[2402] Fix | Delete
p.update(pendict)
[2403] Fix | Delete
[2404] Fix | Delete
_p_buf = {}
[2405] Fix | Delete
for key in p:
[2406] Fix | Delete
_p_buf[key] = _pd[key]
[2407] Fix | Delete
[2408] Fix | Delete
if self.undobuffer:
[2409] Fix | Delete
self.undobuffer.push(("pen", _p_buf))
[2410] Fix | Delete
[2411] Fix | Delete
newLine = False
[2412] Fix | Delete
if "pendown" in p:
[2413] Fix | Delete
if self._drawing != p["pendown"]:
[2414] Fix | Delete
newLine = True
[2415] Fix | Delete
if "pencolor" in p:
[2416] Fix | Delete
if isinstance(p["pencolor"], tuple):
[2417] Fix | Delete
p["pencolor"] = self._colorstr((p["pencolor"],))
[2418] Fix | Delete
if self._pencolor != p["pencolor"]:
[2419] Fix | Delete
newLine = True
[2420] Fix | Delete
if "pensize" in p:
[2421] Fix | Delete
if self._pensize != p["pensize"]:
[2422] Fix | Delete
newLine = True
[2423] Fix | Delete
if newLine:
[2424] Fix | Delete
self._newLine()
[2425] Fix | Delete
if "pendown" in p:
[2426] Fix | Delete
self._drawing = p["pendown"]
[2427] Fix | Delete
if "pencolor" in p:
[2428] Fix | Delete
self._pencolor = p["pencolor"]
[2429] Fix | Delete
if "pensize" in p:
[2430] Fix | Delete
self._pensize = p["pensize"]
[2431] Fix | Delete
if "fillcolor" in p:
[2432] Fix | Delete
if isinstance(p["fillcolor"], tuple):
[2433] Fix | Delete
p["fillcolor"] = self._colorstr((p["fillcolor"],))
[2434] Fix | Delete
self._fillcolor = p["fillcolor"]
[2435] Fix | Delete
if "speed" in p:
[2436] Fix | Delete
self._speed = p["speed"]
[2437] Fix | Delete
if "resizemode" in p:
[2438] Fix | Delete
self._resizemode = p["resizemode"]
[2439] Fix | Delete
if "stretchfactor" in p:
[2440] Fix | Delete
sf = p["stretchfactor"]
[2441] Fix | Delete
if isinstance(sf, (int, float)):
[2442] Fix | Delete
sf = (sf, sf)
[2443] Fix | Delete
self._stretchfactor = sf
[2444] Fix | Delete
if "shearfactor" in p:
[2445] Fix | Delete
self._shearfactor = p["shearfactor"]
[2446] Fix | Delete
if "outline" in p:
[2447] Fix | Delete
self._outlinewidth = p["outline"]
[2448] Fix | Delete
if "shown" in p:
[2449] Fix | Delete
self._shown = p["shown"]
[2450] Fix | Delete
if "tilt" in p:
[2451] Fix | Delete
self._tilt = p["tilt"]
[2452] Fix | Delete
if "stretchfactor" in p or "tilt" in p or "shearfactor" in p:
[2453] Fix | Delete
scx, scy = self._stretchfactor
[2454] Fix | Delete
shf = self._shearfactor
[2455] Fix | Delete
sa, ca = math.sin(self._tilt), math.cos(self._tilt)
[2456] Fix | Delete
self._shapetrafo = ( scx*ca, scy*(shf*ca + sa),
[2457] Fix | Delete
-scx*sa, scy*(ca - shf*sa))
[2458] Fix | Delete
self._update()
[2459] Fix | Delete
[2460] Fix | Delete
## three dummy methods to be implemented by child class:
[2461] Fix | Delete
[2462] Fix | Delete
def _newLine(self, usePos = True):
[2463] Fix | Delete
"""dummy method - to be overwritten by child class"""
[2464] Fix | Delete
def _update(self, count=True, forced=False):
[2465] Fix | Delete
"""dummy method - to be overwritten by child class"""
[2466] Fix | Delete
def _color(self, args):
[2467] Fix | Delete
"""dummy method - to be overwritten by child class"""
[2468] Fix | Delete
def _colorstr(self, args):
[2469] Fix | Delete
"""dummy method - to be overwritten by child class"""
[2470] Fix | Delete
[2471] Fix | Delete
width = pensize
[2472] Fix | Delete
up = penup
[2473] Fix | Delete
pu = penup
[2474] Fix | Delete
pd = pendown
[2475] Fix | Delete
down = pendown
[2476] Fix | Delete
st = showturtle
[2477] Fix | Delete
ht = hideturtle
[2478] Fix | Delete
[2479] Fix | Delete
[2480] Fix | Delete
class _TurtleImage(object):
[2481] Fix | Delete
"""Helper class: Datatype to store Turtle attributes
[2482] Fix | Delete
"""
[2483] Fix | Delete
[2484] Fix | Delete
def __init__(self, screen, shapeIndex):
[2485] Fix | Delete
self.screen = screen
[2486] Fix | Delete
self._type = None
[2487] Fix | Delete
self._setshape(shapeIndex)
[2488] Fix | Delete
[2489] Fix | Delete
def _setshape(self, shapeIndex):
[2490] Fix | Delete
screen = self.screen
[2491] Fix | Delete
self.shapeIndex = shapeIndex
[2492] Fix | Delete
if self._type == "polygon" == screen._shapes[shapeIndex]._type:
[2493] Fix | Delete
return
[2494] Fix | Delete
if self._type == "image" == screen._shapes[shapeIndex]._type:
[2495] Fix | Delete
return
[2496] Fix | Delete
if self._type in ["image", "polygon"]:
[2497] Fix | Delete
screen._delete(self._item)
[2498] Fix | Delete
elif self._type == "compound":
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function