from pyautocad import Autocad, APoint
def draw_tree(autocad, base_point, trunk_height, trunk_width, canopy_radius):
# Calculate trunk points
trunk_bottom_left = APoint(base_point.x - trunk_width / 2, base_point.y)
trunk_bottom_right = APoint(base_point.x + trunk_width / 2, base_point.y)
trunk_top_left = APoint(trunk_bottom_left.x, base_point.y + trunk_height)
trunk_top_right = APoint(trunk_bottom_right.x, base_point.y + trunk_height)
# Draw trunk as a rectangle
autocad.model.AddLine(trunk_bottom_left, trunk_bottom_right)
autocad.model.AddLine(trunk_bottom_left, trunk_top_left)
autocad.model.AddLine(trunk_bottom_right, trunk_top_right)
autocad.model.AddLine(trunk_top_left, trunk_top_right)
# Draw canopy as a circle
canopy_center = APoint(base_point.x, base_point.y + trunk_height + canopy_radius)
autocad.model.AddCircle(canopy_center, canopy_radius)
if __name__ == "__main__":
acad = Autocad()
acad.prompt("Hello! This script draws a basic tree.\n")
# Base point for the tree
base_point = APoint(0, 0)
# Dimensions for the tree
trunk_height = 30
trunk_width = 10
canopy_radius = 20
# Draw the tree
draw_tree(acad, base_point, trunk_height, trunk_width, canopy_radius)
print("Tree has been drawn in AutoCAD.")