在Python中复制此设计
我一直在尝试使用Python复制此设计 我正在使用在Python中复制此设计,python,Python,我一直在尝试使用Python复制此设计 我正在使用图形模块。目前我无法使用任何其他图形模块 这里的代码允许我在一条循环重复的直线上画5个圆 def fdShape(): win = GraphWin(199,199) centre = Point(20,100) for y in range(5): for x in range(5): centre = Point(x * 40 + 20, y * 40 + 60)
图形模块。目前我无法使用任何其他图形模块
这里的代码允许我在一条循环重复的直线上画5个圆
def fdShape():
win = GraphWin(199,199)
centre = Point(20,100)
for y in range(5):
for x in range(5):
centre = Point(x * 40 + 20, y * 40 + 60)
circle = Circle(centre, 20)
circle.setOutline("red")
circle.draw(win)
我发现这段代码的一个问题是,它在窗口顶部留下一条空行,并将最后一条圆线放在窗口边界之外的底部。这是第一个问题
第二种方法是使用代码显示以红色显示的半圆。正如您在本页顶部的图像中所看到的。我不确定如何使用Python复制此图片
谢谢大家! 我看到两个问题
GraphWin应初始化为200x200,而不是199x199
这一行:
centre = Point(x * 40 + 20, y * 40 + 60)
最有可能是:
centre = Point(x * 40 + 20, y * 40 + 20)
这看起来很接近:
from graphic import *
def main():
repeat = 5
diameter = 40
radius = diameter // 2
offset = radius // 2
win = GraphWin("Graphic Design", diameter*repeat + offset, diameter*repeat)
win.setBackground('white')
for i in range(repeat):
for j in range(repeat):
draw_symbol(win, i % 2,
Point(i*diameter + offset, j*diameter), radius, 'red')
win.getMouse()
win.close()
def draw_symbol(win, kind, lower_left, radius, colour):
centre = Point(lower_left.x+radius, lower_left.y+radius)
circle = Circle(centre, radius)
circle.setOutline('')
circle.setFill(colour)
circle.draw(win)
if kind == 0:
rectangle = Rectangle(lower_left,
Point(lower_left.x+radius, lower_left.y+radius*2))
else:
rectangle = Rectangle(lower_left,
Point(lower_left.x+radius*2, lower_left.y+radius))
rectangle.setOutline('white')
rectangle.setFill('white')
rectangle.draw(win)
circle = Circle(centre, radius)
circle.setWidth(1)
circle.setOutline(colour)
circle.setFill('')
circle.draw(win)
main()
你使用什么版本的Python?这也帮助我获得了额外的一行圆圈。非常感谢。