1. 首页 > 科技

python之turtle题目?(python turtle 问题求大神指导)

python之turtle题目?(python turtle 问题求大神指导)

python turtle 问题求大神指导

import turtle

def draw(x,y):

    turtle.clear() 

    while True:

        turtle.forward(200)

        turtle.left(144)

        if abs(turtle.pos()) < 1:

            break

draw(0,0)

turtle.onscreenclick(draw)

turtle.mainloop()

python turtle作图问题

简介:turtle是一个简单的绘图工具。它提供了一个海龟,你可以把它理解为一个机器人,只听得懂有限的指令。

1.在文件头写上如下行,这能让我们在语句中插入中文

#-*- coding: utf-8 -*-

2.用import turtle导入turtle库

3.绘图窗口的原点(0,0)在正中间。默认情况下,海龟向正右方移动。

4.操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令

(1)运动命令:

forward(d)

向前移动距离d代表距离

backward(d)

向后移动距离d代表距离

right(degree)

向右转动多少度

left(degree)

向左转动多少度

goto(x,y)

将画笔移动到坐标为(x,y)的位置

stamp()

绘制当前图形

speed(speed)

画笔绘制的速度范围[0,10]整数

(2)画笔控制命令:

down()

画笔落下,移动时绘制图形

up()

画笔抬起,移动时不绘制图形

setheading(degree)

海龟朝向,degree代表角度

reset()

恢复所有设置

pensize(width)

画笔的宽度

pencolor(colorstring)

画笔的颜色

fillcolor(colorstring)

绘制图形的填充颜色

fill(Ture)

fill(False)

circle(radius, extent)

绘制一个圆形,其中radius为半径,extent为度数,例如若extent为180,则画一个半圆;如要画一个圆形,可不必写第二个参数

5.几个例子

1)画一个边长为60的三角形

#-*- coding: utf-8 -*-

importturtle

a=60

turtle.forward(a)

turtle.left(120)

turtle.forward(a)

turtle.left(120)

turtle.forward(a)

turtle.left(120)

2)画一个边长为60的正方形,并填充为红色,边框为蓝色

#-*- coding: utf-8 -*-

importturtle

turtle.reset()

a= 60

turtle.fillcolor("red")

turtle.pencolor("blue")

turtle.pensize(10)

turtle.fill(True)

turtle.left(90)

turtle.forward(a)

turtle.left(90)

turtle.forward(a)

turtle.left(90)

turtle.forward(a)

turtle.left(90)

turtle.forward(a)

turtle.fill(False)

6.练习:

1)画一个五边形

2)画一个六边形

3)任意输入一个正整数m(>=3),画一个多边形(m条边)

4)画一个五角星,如下所示,注意填充为红色

5)画一个中国象棋棋盘,如下图所示,其中汉字不必显示出来:

6)绘制奥运五环图,其中五种颜色分别为蓝色、黑色、红色、黄色和绿色。注意根据实际效果调整圆形的大小和位置。

求教python中的turtle

>>> dir(turtle)

['canvas', 'pen', 'rawpen', 'rawturtle', 'screen', 'scrolledcanvas', 'shape', 'tk', 'tnavigator', 'tpen', 'tbuffer', 'terminator', 'turtle', 'turtlegraphicserror', 'turtlescreen', 'turtlescreenbase', 'vec2d', '_cfg', '_language', '_root', '_screen', '_turtleimage', '__all__', '__builtins__', '__doc__', '__file__', '__forwardmethods', '__func_body', '__methoddict', '__methods', '__name__', '__package__', '__stringbody', '_alias_list', '_make_global_funcs', '_math_functions', '_screen_docrevise', '_tg_classes', '_tg_screen_functions', '_tg_turtle_functions', '_tg_utilities', '_turtle_docrevise', '_ver', 'acos', 'acosh', 'addshape', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'back', 'backward', 'begin_fill', 'begin_poly', 'bgcolor', 'bgpic', 'bk', 'bye', 'ceil', 'circle', 'clear', 'clearscreen', 'clearstamp', 'clearstamps', 'clone', 'color', 'colormode', 'config_dict', 'copysign', 'cos', 'cosh', 'deepcopy', 'degrees', 'delay', 'distance', 'done', 'dot', 'down', 'e', 'end_fill', 'end_poly', 'erf', 'erfc', 'exitonclick', 'exp', 'expm1', 'fabs', 'factorial', 'fd', 'fill', 'fillcolor', 'floor', 'fmod', 'forward', 'frexp', 'fsum', 'gamma', 'get_poly', 'getcanvas', 'getmethparlist', 'getpen', 'getscreen', 'getshapes', 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'hypot', 'isdown', 'isfile', 'isinf', 'isnan', 'isvisible', 'join', 'ldexp', 'left', 'lgamma', 'listen', 'log', 'log10', 'log1p', 'lt', 'mainloop', 'math', 'mode', 'modf', 'onclick', 'ondrag', 'onkey', 'onrelease', 'onscreenclick', 'ontimer', 'os', 'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pi', 'pos', 'position', 'pow', 'pu', 'radians', 'read_docstrings', 'readconfig', 'register_shape', 'reset', 'resetscreen', 'resizemode', 'right', 'rt', 'screensize', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setup', 'setworldcoordinates', 'setx', 'sety', 'shape', 'shapesize', 'showturtle', 'sin', 'sinh', 'speed', 'split', 'sqrt', 'st', 'stamp', 'tan', 'tanh', 'tilt', 'tiltangle', 'time', 'title', 'towards', 'tracer', 'trunc', 'turtles', 'turtlesize', 'types', 'undo', 'undobufferentries', 'up', 'update', 'width', 'window_height', 'window_width', 'write', 'write_docstringdict', 'xcor', 'ycor']

>>>

python turtle 问题

你的图像主要是画工字形状,定义一个函数画工字,里面要有有一个参数是控制工字比例大小的,其余两个是画的时候起始坐标

然后定义一个列表,包括坐标,比例

list=[(x1,y1,scale1),

(x2,y2,scale2)

......;

(xn,yn,scalen)

]

for i in list:

draw(*i)

我这个只是一个粗略的比方,大概意思就是定义好画图函数,然后把坐标放在列表,然后遍历,调用函数