Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program named stars.py that has two functions for generating star polygons. One function should be implemented using an iteration (a for loop),
Write a program named stars.py that has two functions for generating star polygons. One function should be implemented using an iteration (a for loop), and another function should be a recursion. It is optional to fill in your shapes. The functions for generating stars should be named star (size, n, d=2) and star_recursive (size, n, level, d=2), where size is the size of the polygon side (edge), n is the number of sides (or angles), d is a density or winding number that should be set to default value 2, and level is the level of recursion initially equal to n.. You can read about star polygons here: Star polygon - Wikipedia. You can test your code with the following driver code. NOTE: In your functions, you need to use a variable t that refers to the turtle object instantiated in the main program #main program if __name === '____main__': s = turtle.Screen() s.setup(800, 400) s.bgcolor("white") s.title("Turtle Program") t = turtle. Turtle() t.shape("turtle") t.pen (pencolor='dark violet', fillcolor='dark violet', pensize=3, speed=1) t.penup() t.goto(-150, 0) star(100, 5, 2) # should draw a purple pentagram (5-pointed star) t.penup() t.goto (150, 0) t.color('red') t.pendown() star_recursive (100, 8, 8, 3) # should draw a red octagram (8-pointed star)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a Python program named starspy that defines two functions star and starrecursive for generatin...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started