• 0

[python] drawing a semi circle


Question

hi,

I was trying to draw a semi circle in python using the circle function in the turtle module. The documentation is here: http://docs.python.org/lib/module-turtle.html. I don't understand what the extent parameter does. Can you please explain it to me? And if it isn't too much trouble can you post code that will draw a semi circle? Thanks.

Link to comment
https://www.neowin.net/forum/topic/473049-python-drawing-a-semi-circle/
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Have never had to do a semi-circle and can't test it right now, but try this and see what happens:

from turtle import *
import time

color("green")
up()
goto(0,-50)
down()
circle(50, 45)
up()
goto(-150,-120)
color("red")
write("Done!")

time.sleep(5)

FTFM: If extent is not a full circle, one endpoint of the arc is the current pen position. The arc is drawn in a counter clockwise direction if radius is positive, otherwise in a clockwise direction. In the process, the direction of the turtle is changed by the amount of the extent.

This from the turtle.py source might help:

0154	 def circle(self, radius, extent=None):
0155		 if extent is None:
0156			 extent = self._fullcircle
0157		 x0, y0 = self._position
0158		 xc = x0 - radius * sin(self._angle * self._invradian)
0159		 yc = y0 - radius * cos(self._angle * self._invradian)
0160		 if radius >= 0.0:
0161			 start = self._angle - 90.0
0162		 else:
0163			 start = self._angle + 90.0
0164			 extent = -extent
0165		 if self._filling:
0166			 if abs(extent) >= self._fullcircle:
0167				 item = self._canvas.create_oval(xc-radius, yc-radius,
0168												 xc+radius, yc+radius,
0169												 width=self._width,
0170												 outline="")
0171				 self._tofill.append(item)
0172			 item = self._canvas.create_arc(xc-radius, yc-radius,
0173											xc+radius, yc+radius,
0174											style="chord",
0175											start=start,
0176											extent=extent,
0177											width=self._width,
0178											outline="")
0179			 self._tofill.append(item)
0180		 if self._drawing:
0181			 if abs(extent) >= self._fullcircle:
0182				 item = self._canvas.create_oval(xc-radius, yc-radius,
0183												 xc+radius, yc+radius,
0184												 width=self._width,
0185												 outline=self._color)
0186				 self._items.append(item)
0187			 item = self._canvas.create_arc(xc-radius, yc-radius,
0188											xc+radius, yc+radius,
0189											style="arc",
0190											start=start,
0191											extent=extent,
0192											width=self._width,
0193											outline=self._color)
0194			 self._items.append(item)
0195		 angle = start + extent
0196		 x1 = xc + abs(radius) * cos(angle * self._invradian)
0197		 y1 = yc - abs(radius) * sin(angle * self._invradian)
0198		 self._angle = (self._angle + extent) % self._fullcircle
0199		 self._position = x1, y1
0200		 if self._filling:
0201			 self._path.append(self._position)
0202		 self._draw_turtle()

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • CPU-Z 2.16 by Razvan Serea CPU-Z is a freeware utility that gathers information on some of the main devices of your system. CPU-Z does not need to be installed, just unzip the files in a directory and run the .exe. In order to remove the program, just delete the files. The program does not copy any file in any Windows directory, nor write to the registry. CPU Name and number. Core stepping and process. Package. Core voltage. Internal and external clocks, clock multiplier. Supported instructions sets. All cache levels (location, size, speed, technology). Mainboard Vendor, model and revision. BIOS model and date. Chipset (northbridge and southbridge) and sensor. Graphic interface. Memory Frequency and timings. Module(s) specification using SPD (Serial Presence Detect) : vendor, serial number, timings table. System Windows and DirectX version. CPU-Z 2.16 changelog: AMD Ryzen Z2 and Z2 Extreme (Strix Point). AMD Ryzen 9 8945HX, 8940HX, Ryzen 7 8840HX, 8745HX (Dragon Range refresh). Improved support of AMD Ryzen AI 7 350 and Ryzen AI 5 340 (Kraken Point). Zhaoxin KaiXian KX-U6780A and KX-U6580 (LuJiaZui, 8 cores). AMD Radeon RX 9060 XT (Navi 44). NVIDIA RTX 5060 Ti (GB206), RTX 5060 (GB206), RTX 5050 (GB207) Download: CPU-Z 2.16 | Portable ~3.0 MB (Freeware) View: CPU-Z Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • We will go to Mars to say, "We landed on another planet". However, we won't be staying because there is little reason to do so. Tourism for (and hang gliding within) the Valles Marinaris being an exception. HOWEVER, the actual reason to go to Mars is to develop the technologies and infrastructure needed for asteroid mining, the key to ending Earth's resource depletion worries once and for all. https://science.howstuffworks.com/asteroid-mining.htm And there is big, BIG money in asteroid mining (<- this is Musk's endgame). While there are lots of near-Earth asteroids that can be mined for trillions, if we're going to mine the asteroid belt between Mars and Jupiter, Mars (or one of its two moons) make the best choice for a waystation for processing ore before sending the finished product to Earth or Earth's Moon for manufacturing, etc.
    • The Edge UI team is total dogshit Chrome looks way more consistent. Mica has been broken before. Then suddenly some of the other menu's look different and redesigned, except the extension menu that keeps the old look for months. Then we finally got the global media controls that where coming, not coming, coming back again etc. One day I have the cool new chromium design, the day after it reverts to a design from last year. Then settings pages changes 3 times in a month etc. We get a new tab redesign that is announced with fancy commercials and blog posts everywhere, to never be seen again. It is always something. I think I will finally going back to Chrome because I am tired of this unprofessional UI team where everything seems to be in constant beta or stuff changes overnight and back for no reason.
    • Zen Browser 1.14.2b by Razvan Serea Zen Browser is a privacy-focused, open-source web browser built on Mozilla Firefox, offering users a secure and customizable browsing experience. It emphasizes privacy by blocking trackers, ads, and ensuring your data isn't collected. With Zen Mods, users can enhance their browser experience with various customization options, including features like split views and vertical tabs. The browser is designed for efficiency, providing fast browsing speeds and a lightweight interface. Zen Browser prioritizes user control over the browsing experience, offering a minimal yet powerful alternative to traditional web browsers while keeping your online activity private. Zen Browser’s DRM limitation Zen Browser currently lacks support for DRM-protected content, meaning streaming services like Netflix and HBO Max are inaccessible. This is due to the absence of a Widevine license, which requires significant costs and is financially unfeasible for the developer. Additionally, applying for this license would require Zen to be part of a larger company, similar to Mozilla or Brave. Therefore, DRM-protected media won't be supported in Zen Browser for the foreseeable future. Zen Browser offers features that improve user experience, privacy, and customization: Privacy-Focused: Blocks trackers and minimizes data collection. Automatic Updates: Keeps the browser updated with security patches. Zen Mods: Customizable themes and layouts. Workspaces: Organize tabs into different workspaces. Compact Mode: Maximizes screen space by minimizing UI elements. Zen Glance: Quick website previews. Split Views: View multiple tabs in the same window. Sidebar: Access bookmarks and tools quickly. Vertical Tabs: Manage tabs vertically. Container Tabs: Separate browsing sessions. Fast Profile Switcher: Switch between profiles easily. Tab Folders: Organize tabs into folders. Customizable UI: Personalize browser interface. Security Features: Inherits Firefox’s robust security. Fast Performance: Lightweight and optimized for speed. Zen Mods Customization: Deep customization with mods. Quick Access: Easy access to favorite websites. Open Source: Built on Mozilla Firefox with community collaboration. Community-Driven: Active development and feedback from users. GitHub Repository: Contribute and review the source code. Zen Browser 1.14.2b changes: Fixed an issue when disabling mods Download: Zen Browser | 73.6 MB (Open Source) Download: Zen Browser ARM64 | Other Operating Systems View: Zen Browser Home Page | Screenshots 1 | 2 | Reddit Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • What do you mean no one can land an unammaned craft on the moon? It has been done plenty of times before... Kubrick definitely did no such thing and it would be far easier to actually go the moon than try to fake it. If the US did fake it wouldn't you believe their ideological enemies in the Soviets would have immediately threw up red flags and pointed fingers, instead of congratulating them with the rest of the world?
  • Recent Achievements

    • Explorer
      CHUNWEI went up a rank
      Explorer
    • Contributor
      SnyPer456 went up a rank
      Contributor
    • First Post
      LELO2025 earned a badge
      First Post
    • First Post
      Caltor earned a badge
      First Post
    • One Month Later
      LagFighterZ earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      394
    2. 2
      +FloatingFatMan
      153
    3. 3
      ATLien_0
      149
    4. 4
      macoman
      66
    5. 5
      +thexfile
      63
  • Tell a friend

    Love Neowin? Tell a friend!