Skip to content
Snippets Groups Projects
Commit 4b424e4e authored by Fabian's avatar Fabian
Browse files

Create test2-2.py

parent 693d07ce
No related merge requests found
def create_rectangle():
# Prompt for the coordinates of two points
x1 = float(input("Enter the x-coordinate of the first point: "))
y1 = float(input("Enter the y-coordinate of the first point: "))
x2 = float(input("Enter the x-coordinate of the second point: "))
y2 = float(input("Enter the y-coordinate of the second point: "))
# Calculate the rectangle's coordinates
x_min = min(x1, x2)
y_min = min(y1, y2)
width = abs(x2 - x1)
height = abs(y2 - y1)
# Create the SVG code for the rectangle
svg_code = f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}">'
svg_code += f'<rect x="{x_min}" y="{y_min}" width="{width}" height="{height}" fill="none" stroke="red" stroke-width="0.05" />'
svg_code += '</svg>'
# Write the SVG code to a file
with open('rectangle.svg', 'w') as file:
file.write(svg_code)
print("Rectangle SVG file 'rectangle.svg' has been generated.")
# Call the function to create the rectangle
create_rectangle()
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment