Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Turtle: Fixing my turtle code NEED HELP: will not run despite all code being correct. DO NOT REMOVE ANY CODE AS UNNECESSARY. Code provided

Python Turtle: Fixing my turtle code NEED HELP: will not run despite all code being correct. DO NOT REMOVE ANY CODE AS "UNNECESSARY". Code provided below.
Older question: https://www.chegg.com/homework-help/questions-and-answers/help-python-turtle-code-refusing-run-weird-errors-need-code-run-flawlessly-receiving-error-q180917755
In addition: I also need the shape of the circle to be randomized, ive included an image on expected output I need.
My code so far (broken):
import turtle
import random
from tkinter import Tk, Label, Entry, Button, Scale
# Define global variables to store user inputs
num_lakes =0
num_mountains =0
num_rivers =0
size_multiplier =1.0
# Define color constants
OCEAN_COLOR = 'blue'
LAKE_COLOR = 'blue'
def get_user_input():
"""
Creates a GUI using Tkinter to obtain user input for the number of lakes, mountains, and rivers.
"""
def handle_close():
global num_lakes, num_mountains, num_rivers, size_multiplier
num_lakes = int(lake_entry.get()) if lake_entry.get() else 0
num_mountains = int(mountain_entry.get()) if mountain_entry.get() else 0
num_rivers = int(river_entry.get()) if river_entry.get() else 0
size_multiplier = size_scale.get()
window.destroy()
window = Tk()
window.title("Island Generator Settings")
lake_label = Label(window, text="Number of Lakes:")
lake_label.grid(row=0, column=0)
lake_entry = Entry(window)
lake_entry.grid(row=0, column=1)
mountain_label = Label(window, text="Number of Mountains:")
mountain_label.grid(row=1, column=0)
mountain_entry = Entry(window)
mountain_entry.grid(row=1, column=1)
river_label = Label(window, text="Number of Rivers:")
river_label.grid(row=2, column=0)
river_entry = Entry(window)
river_entry.grid(row=2, column=1)
size_scale_label = Label(window, text="Island Size (Scale)")
size_scale_label.grid(row=3, column=0)
size_scale = Scale(window, from_=1, to=3, orient='horizontal', resolution=0.1)
size_scale.set(1) # Default size multiplier of 1
size_scale.grid(row=3, column=1, columnspan=2)
button = Button(window, text="Generate Island", command=handle_close)
button.grid(row=4, column=0, columnspan=3)
window.mainloop()
# Call the function to get user input
get_user_input()
# Set up the turtle screen
screen = turtle.Screen()
screen.setup(width=800, height=600)
screen.bgcolor(OCEAN_COLOR)
# Create a turtle instance
my_turtle = turtle.Turtle()
my_turtle.speed(0)
def draw_circle(radius, line_color, fill_color):
"""
Draws a circle with the specified radius, line color, and fill color.
Args:
radius (int): The radius of the circle.
line_color (str): The color of the circle's outline.
fill_color (str): The color to fill the circle.
"""
my_turtle.color(line_color)
my_turtle.fillcolor(fill_color)
my_turtle.begin_fill()
my_turtle.circle(radius)
my_turtle.end_fill()
def move_turtle(x, y):
"""
Moves the turtle to the specified coordinates without drawing a line.
Args:
x (int): The x-coordinate of the destination.
y (int): The y-coordinate of the destination.
"""
my_turtle.penup()
my_turtle.goto(x, y)
my_turtle.pendown()
def draw_lake():
"""
Draws a random lake circle within the boundaries of the landmass.
Increases the size of the lake based on the size multiplier.
"""
x_limit = int(150* size_multiplier)//2-30* size_multiplier # Adjusted for lake size
y_limit = int(120* size_multiplier)//2-30* size_multiplier # Adjusted for lake size
x = random.randint(-x_limit, x_limit)
y = random.randint(-y_limit, y_limit)
move_turtle(x, y)
radius = random.randint(10,30)* size_multiplier
draw_circle(radius, LAKE_COLOR, LAKE_COLOR)
# Draw lakes
for _ in range(num_lakes):
draw_lake()
# More functions to draw mountains and rivers can be added here using similar patterns
# Hide the turtle and display the result
my_turtle.hideturtle()
turtle.done()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

9. What is the difference between systematic and unsystematic risk?

Answered: 1 week ago

Question

Describe the concept of diversity and diversity management.

Answered: 1 week ago

Question

How does the EEOC define sexual harassment?

Answered: 1 week ago