SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
Using the given template.py script define the class MyPolygon as prescribed in the diagram
below. The rotate method must change the orientation of the drawn shape by a specified angle
(given by default in radians).
NB: Do not edit the code under main
here is code from template
import turtle as t
class CenteredPolygon:
def __init__(self, n, size, center=(0, 0), pen=None, **kwargs):
self.numsides = n
self.size = size
self.center = center
self.corners = []
self.pen = pen if pen is not None else self.init_pen(**kwargs)
self.draw()
def init_pen(self, **kwargs):
pen = t.Turtle()
for key, value in kwargs.items():
try:
f = getattr(pen, key)
f(value)
except Exception as e:
print(e)
return pen
def set_corners(self) -> list:
p = self.pen
p.pu()
p.goto(self.center)
for i in range(self.numsides):
p.forward(self.size/2)
self.corners.append(p.pos())
p.back(self.size/2)
p.left(360/self.numsides)
p.goto(self.center)
return self.corners
def draw(self):
if not self.corners:
self.set_corners()
p = self.pen
# p.clear()
p.pu()
p.goto(self.corners[0])
p.pd()
p.begin_fill()
for i in self.corners:
p.goto(i)
p.goto(self.corners[0])
p.end_fill()
p.pu()
p.goto(self.center)
p.ht()
t.update()
class MyPolygon(CenteredPolygon):
def rotate_by(self, theta, degrees=False):
...
if __name__ == '__main__':
# DO NOT EDIT
t.tracer(100)
import random, time
from random import randint as r
random.seed(3)
n = 3
col = lambda: "#"+"".join(f"{r(0, 255):02x}" for _ in range(3))
polys = []
size = 500
for i in range(6):
polys.append(MyPolygon(n, size, (0, 0), color=col()))
size -= 50
while True:
for a in range(0, 180, 90):
for p in polys:
p.rotate_by(a, degrees=True)
a *= -1
t.update()
time.sleep(0.1)

Weitere ähnliche Inhalte

Mehr von amirthagiftsmadurai

using the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdfusing the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdf
amirthagiftsmadurai
 
Using this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdfUsing this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdf
amirthagiftsmadurai
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
amirthagiftsmadurai
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
amirthagiftsmadurai
 
Warren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdfWarren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdf
amirthagiftsmadurai
 
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdfVincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
amirthagiftsmadurai
 

Mehr von amirthagiftsmadurai (20)

using the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdfusing the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdf
 
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdfUsted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
 
Using this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdfUsing this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdf
 
using the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdfusing the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdf
 
Using the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdfUsing the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdf
 
Using the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdfUsing the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdf
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
 
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset  how to conduct a comprehensive EDA .pdfUsing the accidentdata dataset  how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
 
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdfVuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
 
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdfVuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
 
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdfWe aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
 
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdfVerdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
 
Verdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdfVerdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdf
 
Warren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdfWarren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdf
 
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdfWatch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
 
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdfVincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
 
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdfWanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
 
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdfW1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
 
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdfVerdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
 

Kürzlich hochgeladen

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

Using the given template.py script define the class MyPolygon as p.pdf

  • 1. Using the given template.py script define the class MyPolygon as prescribed in the diagram below. The rotate method must change the orientation of the drawn shape by a specified angle (given by default in radians). NB: Do not edit the code under main here is code from template import turtle as t class CenteredPolygon: def __init__(self, n, size, center=(0, 0), pen=None, **kwargs): self.numsides = n self.size = size self.center = center self.corners = [] self.pen = pen if pen is not None else self.init_pen(**kwargs) self.draw() def init_pen(self, **kwargs): pen = t.Turtle() for key, value in kwargs.items(): try: f = getattr(pen, key) f(value) except Exception as e: print(e) return pen def set_corners(self) -> list: p = self.pen p.pu() p.goto(self.center) for i in range(self.numsides): p.forward(self.size/2) self.corners.append(p.pos()) p.back(self.size/2) p.left(360/self.numsides)
  • 2. p.goto(self.center) return self.corners def draw(self): if not self.corners: self.set_corners() p = self.pen # p.clear() p.pu() p.goto(self.corners[0]) p.pd() p.begin_fill() for i in self.corners: p.goto(i) p.goto(self.corners[0]) p.end_fill() p.pu() p.goto(self.center) p.ht() t.update() class MyPolygon(CenteredPolygon): def rotate_by(self, theta, degrees=False): ... if __name__ == '__main__': # DO NOT EDIT t.tracer(100) import random, time from random import randint as r random.seed(3) n = 3 col = lambda: "#"+"".join(f"{r(0, 255):02x}" for _ in range(3)) polys = [] size = 500 for i in range(6): polys.append(MyPolygon(n, size, (0, 0), color=col()))
  • 3. size -= 50 while True: for a in range(0, 180, 90): for p in polys: p.rotate_by(a, degrees=True) a *= -1 t.update() time.sleep(0.1)