【发布时间】:2017-12-09 14:36:25
【问题描述】:
现在我正在编写一个程序来从 52 张扑克牌中随机获取 4 张扑克牌,我必须通过 python turtle 模块绘制这些扑克牌。现在这是我的问题:因为扑克中有一个颠倒的数字,just like this(the bottom right corner number)
起初我想用这段代码来生成数字:
import turtle as do
def generate_digital(number, x, y, start_angle, size):
'''
this function generate '2-10'
parameters:
number: this is number you want to write
x and y: this is the pen's initial location
start_angle: the pen's initial direction
size: the number's size
'''
do.penup()
do.goto(x, y)
do.pensize(30)
do.setheading(start_angle)
do.write(number, font=("Arial", size, "normal"))
我想使用
do.settheading()设置数字的角度,却发现不行!我可以得到一个 5 但我不能使用 do.write() 方法得到一个倒置的 5......
现在,我自己能想到的唯一方法就是使用这个
def generate_photo_2(x, y, start_angle, size):
'''
this function generate a '2'
parameters:
just like last function
'''
do.penup()
do.goto(x, y)
do.pensize(3)
do.setheading(start_angle)
do.pendown()
do.circle(-size, 200)
do.fd(2 * size)
do.left(45)
do.fd(0.6 * size)
do.left(90)
do.fd(2 * size)
代码“绘制”一个数字,通过设置起始角度,我可以“绘制”一个倒数 2,但这会带来很多麻烦,不是吗?
谁能告诉我如何写()一个颠倒的数字? 非常感谢!!!
【问题讨论】: