- #question 4
-
import turtle as t
-
def drawhat():
-
t.speed(15)
-
t.fillcolor("black")
-
t.begin_fill()
-
t.penup()
-
#i used goto to make the pen goto a certain x,y cordinates so i can continue drawing from that point
-
t.goto(0,250)
-
t.pendown()
-
t.left(180)
-
t.forward(60)
-
t.left(90)
-
t.forward(50)
-
t.right(90)
-
t.forward(30)
-
t.left(90)
-
t.forward(20)
-
t.left(90)
-
t.forward(120)
-
t.left(90)
-
t.forward(20)
-
t.left(90)
-
t.forward(30)
-
t.right(90)
-
t.forward(50)
-
t.end_fill()
-
-
#i used more than one function because this way i can categorize the different parts of the drawing
-
-
def drawhead():
-
t.speed(15)
-
#head
-
t.penup()
-
t.goto(20,150)
-
t.pendown()
-
t.circle(50)
-
#eyes
-
t.fillcolor("blue")
-
t.begin_fill()
-
t.penup()
-
t.goto(0,155)
-
t.pendown()
-
t.circle(5)
-
t.end_fill()
-
-
t.fillcolor("red")
-
t.begin_fill()
-
t.penup()
-
t.goto(-50, 155)
-
t.pendown()
-
t.circle(5)
-
t.end_fill()
-
#mouth
-
t.penup()
-
t.goto(0,120)
-
t.pendown()
-
t.left(90)
-
t.forward(60)
-
-
def midsection():
-
t.penup()
-
t.goto(-20,100)
-
t.pendown()
-
t.circle(75)
-
-
def drawarms():
-
t.penup()
-
t.goto(40,65)
-
t.pendown()
-
t.right(150)
-
t.forward(60)
-
t.left(30)
-
t.forward(15)
-
t.penup()
-
t.goto(85,90)
-
t.pendown()
-
t.forward(25)
-
#arm 2
-
t.penup()
-
t.goto(-90,55)
-
t.pendown()
-
t.left(60)
-
t.forward(50)
-
t.left(30)
-
t.forward(25)
-
t.penup()
-
t.goto(-10,20)
-
t.pendown()
-
def arm2():
-
t.penup()
-
t.goto(-120,100)
-
t.pendown()
-
t.right(30)
-
t.forward(25)
-
-
def base():
-
t.penup()
-
t.goto(60,-100)
-
t.pendown()
-
t.circle(100)
-
-
-
-
-
#i called them all together at the end
-
drawhat()
-
drawhead()
-
midsection()
-
drawarms()
-
arm2()
-
base()
-
so basically after every function the same commands are used so is there another type of function that can replace turtle.goto so the code wont seem repetitive?
1 3886 Banfa 9,065
Recognized Expert Moderator Expert
Why would an API contain 2 functrions that do the same thing, that would be crazy and a maintenance issue. What you can do is create your own functions to encapsulate common sets of commands, e.g. nearly every goto is preceded by a penup and followed by a pendown so you could have a function as -
def startLine(x, y):
-
t.penup()
-
t.goto(x, y)
-
t.pendown()
-
Similarly almost every move consists of a turn (left or right) and then moving forward. It should be easy to put that into a function (using a negative value for turn left and a positive value for turn right.
Having functions that encapsulate common sequences will reduce your own code and make it easier to read.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Daniel |
last post by:
Hello,
This is maybe a simple one:
Is there any way to check, if a string can be converted to
another type (like DateTime or Integer) without using
try/catch? In VB, i can use IsDate or IsNumeric to do
this, but how can i do it in C#?
Thanks in advance,
Daniel
|
by: Daniel |
last post by:
Hello,
maybe this is an easy one:
Is there any way to check, if a string value can be
converted into another type (e.g. DateTime, Integer)
without using exceptions (try/catch)?
Thanks in advance,
Daniel
|
by: seash |
last post by:
H
i need a function like GetExitCodeProcess() type function in c#, cause i need to know the status of a process
how do i track the status of a process , whether the process is running or exited
in my application iam invoking an exe of unmanaged code which is written in vc++, and i need to track the status of that process
i know that GetExitCodeProcess() is there in c++ but i want the same functionality of a function in c
--------seash
|
by: Tuvas |
last post by:
I am building a GUI interface with Tkinter. I need to have a way to
open and save files. Is there a nice GUI that can do that for me, ei,
show what files are avaliable, a choose file type function? If it
matters any, I am planning on running this on both windows and linux.
Thanks for the help!
|
by: Joe |
last post by:
Is there another Form1_Load function?
I need to call a function to exit but I want to have it called right after
the User interface have been loaded and appeared on screen. Right now the
Load function doesn't load the User interface to be viewable and the code I
call the exit function in the load function doesn't really help in my cause.
I like to call exit right after the form has been loaded, is there such a
function?
| |
by: bonk |
last post by:
When I have an instance of an object wich is of type System.Type, how
can I find out if it directly or indirecly derives from another type?
myTypeInstance == typeof(AnotherType)
only seems to check if they are ultimately the same type (at the very
bottom of the inheritance hirarchy) but in case myTypeInstance is
"TypeDerivedFromAnotherType" the above evaluates to false..
myTypeInstance.BaseType == typeof(AnotherType)
|
by: elderic |
last post by:
Hi there,
are there other ways than the ones below to check for <type 'function'>
in a python script?
(partly inspired by wrapping Tkinter :P)
def f():
print "This is f(). Godspeed!"
1.: --sort of clumsy and discouraged by the docs as far as I read
|
by: EORTIZ |
last post by:
I would like to know the way that I can write a CASE function in a select statement that uses another variable that is created in the same SELECT statement using another CASE function. This is exacly what I am trying to do but obviusly gives me an error because is incorrect:
SELECT
CSV_SRV_QTY,
NET_PAID,
case when NET_PAID=0 THEN 0 ELSE CSV_SRV_QTY END AS ADJUNITS1,
CASE WHEN NET_PAID<0 AND ADJUNITS1>0 THEN -(ADJUNITS1)...
|
by: grbgooglefan |
last post by:
I am trying to pass a C++ object to Python function. This Python
function then calls another C++ function which then uses this C++
object to call methods of that object's class.
I tried something like this, but it did not work, gave core dump.
class myclass {
public:
myclass(){};
~myclass(){};
|
by: DamienS |
last post by:
Hi,
I need to determine if one type is inheritted from another type. I
don't have instances of the objects (and it's undesirable to create
them).
Can someone please point me in the right direction?
Thanks in advance,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |