python画建筑物_函数绘制带有门窗的建筑

我正在创建一个绘制办公大楼的函数:窗口为20像素的正方形

窗口之间的间距为10像素

门宽20像素,高50像素,橙色

我的代码无法正确绘制:from graphics import *

from random import *

def add_window(win, nH, nV):

w, h = win.getWidth(), win.getHeight()

rects = []

for x in range(nH):

rects.append([])

for y in range(nV):

r = Rectangle(Point( x *w//nH, y *h//vV),

Point((x+1)*w//nH, (y+1)*h//nV))

window = [ r,

True,

[ 'red', 'green' ]

]

rects[x].append(window)

rects[x][y][0].draw(win)

rects[x][y][0].setOutline('blue')

color = window[2][randint[0,1]]

rects[x][y][0].setFill(color)

return rects

WIN_W, WIN_H = 500, 400

#Top left coner of the building

BLDG_LEFT, BLDG_TOP = 50, 50

#How many floors, how many windows perfloor, window digit and gap

FLOORS, WIN_FLR, WIN_SZ, GAP = 10, 5, 20, 5

win = None

#Syntax : window[x][y]

# [0] : Rectangle() object

# [1] : True/False

windows = []

#--------------------------------------------------------------------

def draw_window(x, y):

global windows

windows = []

left = BLDG_LEFT + GAP + x* (WIN_SZ+GAP)

top = BLDG_TOP + GAP + y* (WIN_SZ+GAP)

r = Rectangle(Point( x *WIN_SZ+GAP, y *(WIN_SZ+GAP)),

Point((x+1)*WIN_SZ+GAP, (y+1)*(WIN_SZ+GAP)))

windows[x][y].append(r)

bit = randint(0,1)

windows[x][y].append(bool(bit))

windows[x][y][0].setFill(COLORS[bit])

windows[x][y][0].draw(win)

def draw_windows():

for i in range(WIN_FLR):

windows.append([])

for j in range(FLOORS):

windows[i].append([])

draw_window(i, j)

def office_tower():

global win

win = GraphWin("OFFICE TOWER", WIN_W, WIN_H)

draw_window(1, 1)

while True:

pt = win.getmouse()

if pt.x < 10 and pt.y < 10:

break

# windows coordinates

x = int((pt.x - BLDG_LEFT - GAP)/(WIN_SZ + GAP))

y = int((pt.y - BLDG_TOP - GAP)/(WIN_SZ + GAP))

print(str((pt.x, pt.y)) + ' --> ' + str((x, y)))

windows[x][y][1] = netwindows[x][y][1]

windows[x][y][0].setFill(COLORS[windows[x][y][1]])

def draw_building():

global windows

win = GraphWin("OFFICE TOWER", WIN_W, WIN_H)

N_H, N_V = 5, 10

while True:

pt = win.getMouse()

m_x, m_y = pt.getX(), pt.getY()

# Grid coordinates:

g_x = m_x // (WIN_W//N_H)

g_y = m_y // (WIN_H//N_V)

# For development purposes:

if m_x < 10 and m_y < 10:

break

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值