def redCircles():
win = GraphWin("Patch2" ,100,100)
for x in (10, 30, 50, 70, 90):
for y in (10, 30, 50, 70, 90):
c = Circle(Point(x,y), 10)
c.setFill("red")
c.draw(win)
from graphics import *
def redCircles():
win = GraphWin("Patch2" ,100,100)
for x in (10, 30, 50, 70, 90):
for y in (10, 30, 50, 70, 90):
c = Circle(Point(x,y), 10)
d = Circle(Point(x,y), 10)
if x in (30, 70):
r = Rectangle(Point(x - 10, y), Point(x + 10, y + 10))
else:
r = Rectangle(Point(x - 10, y- 10), Point(x, y + 10))
c.setFill("red")
d.setOutline("red")
r.setFill("white")
r.setOutline('white')
c.draw(win)
r.draw(win)
d.draw(win)
if __name__=='__main__':
redCircles()
下面是我对@JaredWindover的解决方案进行的修改。首先,尽可能多的图形对象设置在嵌套循环之前完成,利用Zelle的
clone()
方法。其次,它修复了一个很难在小范围内看到的缺陷,即圆的一半轮廓是黑色而不是红色。最后,与Jared的解决方案和OP的代码不同,它是可伸缩的:刚刚测试过这个,对我很有效。你知道吗
我们先画满的圆,然后画一半的矩形,然后画出轮廓的圆来恢复轮廓。if检查我们在哪一列。你知道吗
相关问题 更多 >
编程相关推荐