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)
这是我的代码,输出应如下所示:
答案 0 :(得分:1)
刚试过这个,它对我有用。
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()
我们绘制实心圆圈,然后绘制超过一半的矩形,然后勾勒出圆圈以获得轮廓。 if会检查我们所在的列。
答案 1 :(得分:0)
以下是我对@JaredWindover解决方案进行修改的(臃肿)返工。首先,尽可能多的图形对象设置在嵌套循环之前完成,利用Zelle的CREATE TABLE FILMS (
ID INTEGER NOT NULL PRIMARY KEY
TITLE TEXT NOT NULL,
YEAR INTEGER NOT NULL,
PREDECESSOR_ID INTEGER,
INCREASE NUMERIC
)
方法。其次,它修复了一个很难看到的小错误,圆圈中一半的轮廓是黑色而不是红色。最后,与Jared的解决方案和OP的代码不同,它是可扩展的:
clone()