473,661 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there another type of function that can replace turtle.goto?

2 New Member
Expand|Select|Wrap|Line Numbers
  1. #question 4
  2. import turtle as t
  3. def drawhat():
  4.     t.speed(15)
  5.     t.fillcolor("black")
  6.     t.begin_fill()
  7.     t.penup()
  8. #i used goto to make the pen goto a certain x,y cordinates so i can continue drawing from that point
  9.     t.goto(0,250)
  10.     t.pendown()
  11.     t.left(180)
  12.     t.forward(60)
  13.     t.left(90)
  14.     t.forward(50)
  15.     t.right(90)
  16.     t.forward(30)
  17.     t.left(90)
  18.     t.forward(20)
  19.     t.left(90)
  20.     t.forward(120)
  21.     t.left(90)
  22.     t.forward(20)
  23.     t.left(90)
  24.     t.forward(30)
  25.     t.right(90)
  26.     t.forward(50)
  27.     t.end_fill()
  28.  
  29. #i used more than one function because this way i can categorize the different parts of the drawing
  30.  
  31. def drawhead():
  32.     t.speed(15)
  33.     #head
  34.     t.penup()
  35.     t.goto(20,150)
  36.     t.pendown()
  37.     t.circle(50)
  38.     #eyes
  39.     t.fillcolor("blue")
  40.     t.begin_fill()
  41.     t.penup()
  42.     t.goto(0,155)
  43.     t.pendown()
  44.     t.circle(5)
  45.     t.end_fill()
  46.  
  47.     t.fillcolor("red")
  48.     t.begin_fill()
  49.     t.penup()
  50.     t.goto(-50, 155)
  51.     t.pendown()
  52.     t.circle(5)
  53.     t.end_fill()
  54.     #mouth
  55.     t.penup()
  56.     t.goto(0,120)
  57.     t.pendown()
  58.     t.left(90)
  59.     t.forward(60)
  60.  
  61. def midsection():
  62.     t.penup()
  63.     t.goto(-20,100)
  64.     t.pendown()
  65.     t.circle(75)
  66.  
  67. def drawarms():
  68.     t.penup()
  69.     t.goto(40,65)
  70.     t.pendown()
  71.     t.right(150)
  72.     t.forward(60)
  73.     t.left(30)
  74.     t.forward(15)
  75.     t.penup()
  76.     t.goto(85,90)
  77.     t.pendown()
  78.     t.forward(25)
  79.     #arm 2
  80.     t.penup()
  81.     t.goto(-90,55)
  82.     t.pendown()
  83.     t.left(60)
  84.     t.forward(50)
  85.     t.left(30)
  86.     t.forward(25)
  87.     t.penup()
  88.     t.goto(-10,20)
  89.     t.pendown()
  90. def arm2():
  91.     t.penup()
  92.     t.goto(-120,100)
  93.     t.pendown()
  94.     t.right(30)
  95.     t.forward(25)
  96.  
  97. def base():
  98.     t.penup()
  99.     t.goto(60,-100)
  100.     t.pendown()
  101.     t.circle(100)
  102.  
  103.  
  104.  
  105.  
  106. #i called them all together at the end      
  107. drawhat()    
  108. drawhead()
  109. midsection()
  110. drawarms()
  111. arm2()
  112. base()
  113.  
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?
May 22 '21 #1
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

Expand|Select|Wrap|Line Numbers
  1. def startLine(x, y):
  2.     t.penup()
  3.     t.goto(x, y)
  4.     t.pendown()
  5.  
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.
May 26 '21 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7141
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
2
2459
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
2
4086
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
3
1130
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!
4
2308
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?
8
2373
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)
20
2076
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
1
2154
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)...
9
4993
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(){};
7
6531
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,
0
8343
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,...
1
8545
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,...
0
8633
tracyyun
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...
0
7364
agi2029
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...
1
6185
isladogs
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...
0
4179
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...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.