Vẽ nhà bằng python

Vẽ nhà bằng python

hạt dẻ

Làm theo

21 tháng 11 năm 2021

·

9 phút đọc

Vẽ Ngôi nhà mơ ước bằng Python Matplotlib Module

Trong blog này, chúng tôi sẽ vẽ ngôi nhà với sự trợ giúp của mô-đun matplotlib

Tạo bởi Nutan

Nhập mô-đun

________ Đặt kích thước hình và giới hạn trục x và trục y _______1

đầu ra

Vẽ một hình chữ nhật giống như bốn bức tường
plt.figure(figsize = (10, 10))#four points
plt.plot(2, 2, marker = "o")
plt.plot(8, 2, marker = "o")
plt.plot(2, 5, marker = "o")
plt.plot(8, 5, marker = "o")
#draw walls
plt.plot([2, 8, 8, 2, 2], [2, 2, 5, 5, 2])
plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()

đầu ra

Vẽ một hình tam giác trên đỉnh của hình chữ nhật______3

đầu ra

Vẽ ống xả trong phần tam giác
plt.figure(figsize = (10, 10))#four points
plt.plot(2, 2, marker = "o")
plt.plot(8, 2, marker = "o")
plt.plot(2, 5, marker = "o")
plt.plot(8, 5, marker = "o")
#draw walls
plt.plot([2, 8, 8, 2, 2], [2, 2, 5, 5, 2])
#triangle points and connect them
plt.plot(5, 7, marker = "o")
plt.plot([2, 5, 8], [5, 7, 5])
#exhauste
plt.plot(5, 6, marker = "o", markersize = 35, color = 'green')
plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()

đầu ra

Vẽ cửa và khóa
plt.figure(figsize = (10, 10))#four points
plt.plot(2, 2, marker = "o")
plt.plot(8, 2, marker = "o")
plt.plot(2, 5, marker = "o")
plt.plot(8, 5, marker = "o")
#draw walls
plt.plot([2, 8, 8, 2, 2], [2, 2, 5, 5, 2])
#triangle points and connect them
plt.plot(5, 7, marker = "o")
plt.plot([2, 5, 8], [5, 7, 5])
#exhauste
plt.plot(5, 6, marker = "o", markersize = 35, color = 'green')
#door
plt.plot(6, 4, marker = "o")
plt.plot(7, 4, marker = "o")
plt.plot([6, 6, 7, 7], [2, 4, 4, 2])
plt.plot([6, 7], [4, 2])
plt.plot([7, 6], [4, 2])
#lock
plt.plot(6.5, 3, marker = "o", markersize = 15, color = 'gold')
plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()

đầu ra

Vẽ cửa sổ và nướng trên đó
plt.figure(figsize = (10, 10))#four points
plt.plot(2, 2, marker = "o")
plt.plot(8, 2, marker = "o")
plt.plot(2, 5, marker = "o")
plt.plot(8, 5, marker = "o")
#draw walls
plt.plot([2, 8, 8, 2, 2], [2, 2, 5, 5, 2])
#triangle points and connect them
plt.plot(5, 7, marker = "o")
plt.plot([2, 5, 8], [5, 7, 5])
#exhauste
plt.plot(5, 6, marker = "o", markersize = 35, color = 'green')
#door
plt.plot(6, 4, marker = "o")
plt.plot(7, 4, marker = "o")
plt.plot([6, 6, 7, 7], [2, 4, 4, 2])
plt.plot([6, 7], [4, 2])
plt.plot([7, 6], [4, 2])
#lock
plt.plot(6.5, 3, marker = "o", markersize = 15, color = 'gold')
#window
plt.plot(2.5, 3.5, marker = 'o')
plt.plot(4, 3.5, marker = 'o')
plt.plot(4, 4.5, marker = 'o')
plt.plot(2.5, 4.5, marker = 'o')
plt.plot([2.5, 4, 4, 2.5, 2.5], [3.5, 3.5, 4.5, 4.5, 3.5])#horizental grill in window
plt.plot([2.8, 2.8], [3.5, 4.5])
plt.plot([3.1, 3.1], [3.5, 4.5])
plt.plot([3.4, 3.4], [3.5, 4.5])
plt.plot([3.7, 3.7], [3.5, 4.5])
#verticle grill in window
plt.plot([2.5, 4], [3.8, 3.8])
plt.plot([2.5, 4], [4.2, 4.2])
plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()

đầu ra

Vẽ ống khói
plt.figure(figsize = (10, 10))#four points
plt.plot(2, 2, marker = "o")
plt.plot(8, 2, marker = "o")
plt.plot(2, 5, marker = "o")
plt.plot(8, 5, marker = "o")
#draw walls
plt.plot([2, 8, 8, 2, 2], [2, 2, 5, 5, 2])
#triangle points and connect them
plt.plot(5, 7, marker = "o")
plt.plot([2, 5, 8], [5, 7, 5])
#exhauste
plt.plot(5, 6, marker = "o", markersize = 35, color = 'green')
#door
plt.plot(6, 4, marker = "o")
plt.plot(7, 4, marker = "o")
plt.plot([6, 6, 7, 7], [2, 4, 4, 2])
plt.plot([6, 7], [4, 2])
plt.plot([7, 6], [4, 2])
#lock
plt.plot(6.5, 3, marker = "o", markersize = 15, color = 'gold')
#window
plt.plot(2.5, 3.5, marker = 'o')
plt.plot(4, 3.5, marker = 'o')
plt.plot(4, 4.5, marker = 'o')
plt.plot(2.5, 4.5, marker = 'o')
plt.plot([2.5, 4, 4, 2.5, 2.5], [3.5, 3.5, 4.5, 4.5, 3.5])#horizental grill in window
plt.plot([2.8, 2.8], [3.5, 4.5])
plt.plot([3.1, 3.1], [3.5, 4.5])
plt.plot([3.4, 3.4], [3.5, 4.5])
plt.plot([3.7, 3.7], [3.5, 4.5])
#verticle grill in window
plt.plot([2.5, 4], [3.8, 3.8])
plt.plot([2.5, 4], [4.2, 4.2])
#draw chimney
plt.plot(3.5, 6.1, marker = 'o')
plt.plot(3.5, 7.5, marker = 'o')
plt.plot(4, 6.4, marker = 'o')
plt.plot(4, 7.5, marker = 'o')
plt.plot([3.5, 3.5], [6.1, 7.5])
plt.plot([4, 4], [6.4, 7.5])
plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()

đầu ra

Vẽ mặt trời
plt.figure(figsize = (10, 10))#four points
plt.plot(2, 2, marker = "o")
plt.plot(8, 2, marker = "o")
plt.plot(2, 5, marker = "o")
plt.plot(8, 5, marker = "o")
#draw walls
plt.plot([2, 8, 8, 2, 2], [2, 2, 5, 5, 2])
#triangle points and connect them
plt.plot(5, 7, marker = "o")
plt.plot([2, 5, 8], [5, 7, 5])
#exhauste
plt.plot(5, 6, marker = "o", markersize = 35, color = 'green')
#door
plt.plot(6, 4, marker = "o")
plt.plot(7, 4, marker = "o")
plt.plot([6, 6, 7, 7], [2, 4, 4, 2])
plt.plot([6, 7], [4, 2])
plt.plot([7, 6], [4, 2])
#lock
plt.plot(6.5, 3, marker = "o", markersize = 15, color = 'gold')
#window
plt.plot(2.5, 3.5, marker = 'o')
plt.plot(4, 3.5, marker = 'o')
plt.plot(4, 4.5, marker = 'o')
plt.plot(2.5, 4.5, marker = 'o')
plt.plot([2.5, 4, 4, 2.5, 2.5], [3.5, 3.5, 4.5, 4.5, 3.5])#horizental grill in window
plt.plot([2.8, 2.8], [3.5, 4.5])
plt.plot([3.1, 3.1], [3.5, 4.5])
plt.plot([3.4, 3.4], [3.5, 4.5])
plt.plot([3.7, 3.7], [3.5, 4.5])
#verticle grill in window
plt.plot([2.5, 4], [3.8, 3.8])
plt.plot([2.5, 4], [4.2, 4.2])
#draw chimney
plt.plot(3.5, 6.1, marker = 'o')
plt.plot(3.5, 7.5, marker = 'o')
plt.plot(4, 6.4, marker = 'o')
plt.plot(4, 7.5, marker = 'o')
plt.plot([3.5, 3.5], [6.1, 7.5])
plt.plot([4, 4], [6.4, 7.5])
#draw sun
plt.plot(9, 9, marker = 'o', markersize = 50, color='yellow')
plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()

đầu ra

Vẽ hàng rào
plt.figure(figsize = (10, 10))#four points
plt.plot(2, 2, marker = "o")
plt.plot(8, 2, marker = "o")
plt.plot(2, 5, marker = "o")
plt.plot(8, 5, marker = "o")
#draw walls
plt.plot([2, 8, 8, 2, 2], [2, 2, 5, 5, 2])
#triangle points and connect them
plt.plot(5, 7, marker = "o")
plt.plot([2, 5, 8], [5, 7, 5])
#exhauste
plt.plot(5, 6, marker = "o", markersize = 35, color = 'green')
#door
plt.plot(6, 4, marker = "o")
plt.plot(7, 4, marker = "o")
plt.plot([6, 6, 7, 7], [2, 4, 4, 2])
plt.plot([6, 7], [4, 2])
plt.plot([7, 6], [4, 2])
#lock
plt.plot(6.5, 3, marker = "o", markersize = 15, color = 'gold')
#window
plt.plot(2.5, 3.5, marker = 'o')
plt.plot(4, 3.5, marker = 'o')
plt.plot(4, 4.5, marker = 'o')
plt.plot(2.5, 4.5, marker = 'o')
plt.plot([2.5, 4, 4, 2.5, 2.5], [3.5, 3.5, 4.5, 4.5, 3.5])#horizental grill in window
plt.plot([2.8, 2.8], [3.5, 4.5])
plt.plot([3.1, 3.1], [3.5, 4.5])
plt.plot([3.4, 3.4], [3.5, 4.5])
plt.plot([3.7, 3.7], [3.5, 4.5])
#verticle grill in window
plt.plot([2.5, 4], [3.8, 3.8])
plt.plot([2.5, 4], [4.2, 4.2])
#draw chimney
plt.plot(3.5, 6.1, marker = 'o')
plt.plot(3.5, 7.5, marker = 'o')
plt.plot(4, 6.4, marker = 'o')
plt.plot(4, 7.5, marker = 'o')
plt.plot([3.5, 3.5], [6.1, 7.5])
plt.plot([4, 4], [6.4, 7.5])
#draw sun
plt.plot(9, 9, marker = 'o', markersize = 50, color='yellow', markeredgecolor = 'r')
#fence
for i in np.linspace(1, 10, 20):
plt.plot(i , 1.5, "go", alpha=0.5, marker=r'$\clubsuit$', markersize=30)
pass
plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()

đầu ra

Vẽ trái tim
plt.figure(figsize = (10, 10))plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()
0

đầu ra

Thay đổi màu mặt trục thành màu đen và vẽ các ngôi sao
plt.figure(figsize = (10, 10))plt.xlim(1, 10)
plt.ylim(1, 10)
plt.show()
1

đầu ra

Cảm ơn vì đã đọc

Tôi có thể sử dụng Python để vẽ không?

Làm quen với Thư viện rùa Python . Cây bút trên màn hình mà bạn sử dụng để vẽ được gọi là con rùa và đây là tên gọi của thư viện. turtle is a pre-installed Python library that enables users to create pictures and shapes by providing them with a virtual canvas. The onscreen pen that you use for drawing is called the turtle and this is what gives the library its name.

Làm cách nào để vẽ hình bằng Python?

Lập trình hướng đối tượng trong Python. Tạo trò chơi phiêu lưu của riêng bạn .
từ nhập hình dạng Giấy, Hình tam giác, Hình chữ nhật, Hình bầu dục
giấy = Giấy()
rect1 = Hình chữ nhật()
trực tràng1. set_width(200) rect1. set_height(100) rect1. .
trực tràng1. vẽ tranh()
giấy. trưng bày()
# đưa code tạo Rectangle thứ 2 vào đây. trưng bày()

Nhà rùa trong Python là gì?

Mô-đun con rùa cung cấp nguyên mẫu đồ họa con rùa, theo cả hướng đối tượng và hướng thủ tục . Bởi vì nó sử dụng Tkinter cho đồ họa cơ bản, nên nó cần cài đặt phiên bản Python có hỗ trợ Tk.

Làm cách nào để tạo trò chơi bằng Python?

Đây là ví dụ sau về việc tạo một cửa sổ pygame đơn giản. .
nhập pygame
pygame. trong đó()
màn hình = pygame. trưng bày. set_mode((400,500))
xong = Sai
trong khi chưa hoàn thành
cho sự kiện trong pygame. biến cố. được()
nếu sự kiện. gõ == pygame. TỪ BỎ
xong = Đúng