我写了一个画房子的函数。
def drawHouse():
pic=makeEmptyPicture(400,400)
for x in range (0,400):
for y in range (0,400):
px =getPixel(pic,x,y)
if y <180:
#sky
color=makeColor(137, 194, 255)
if y>=180:
#grass
color =makeColor(137, 194, 19)
if(x>50 and x<200) and (y>160 and y<320):
#house walls
color=makeColor(215, 141, 21)
if (x>70 and x<110) and (y>200 and y<320):
#door
color=makeColor(17, 132, 176)
if ((x>120 and x <155) and (y>180 and y<240)) or ((x>160 and x<195) and (y>180 and y<240)):
#windows
color=makeColor(216, 255, 255)
x0=182
x1=43
x2=204
y0=79
y1=161
y2=162
if (x>((y-y0)*(x1-x0)/(y1-y0)+x0) and x<((y-y0)*(x2-x0)/(y2-y0)+x0) and x>((y-y2)*(x1-x2)/(y1-y2)+x2)):
#roof
color = makeColor(255, 0, 28)
setColor(px,color)
return pic
因为我正在为屋顶创建一个三角形。如何为屋顶创建一个水平底的三角形(不添加单独的直线).. 鉴于 x 值需要被 y 点的差异整除 (x>((y-y0)*(x1 -x0)/ (y1-y0) +x0)?