1. 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)绘制奥运五环图,其中五种颜色分别为蓝色、黑色、红色、黄色和绿色。注意根据实际效果调整圆形的大小和位置。
2. 如何用python画钝角三角形
可以用turtles库,这个库可以实现简单的绘图。大致思路是:将海龟置于适当位置和角度,先前进画一条边,转一定角度,再前进画第二条边,再转一定角度,最后前进画第三条边,回到原来位置。
3. 如何使用python turtle 画一个等边三角形
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x=np.linspace(-10,10,1000)
y=np.linspace(-10,10,1000)
X,Y = np.meshgrid(x,y)
Z=X**2 +(Y-1.5*X**(2/3))**2-1
ax.contour(-1*X,Y,Z,[1,5,10,15,20,25,30])
ax.contour(X,Y,Z,[1,5,10,15,20,25,30])
ax.text(-0.3,-6.5,r'$\dag$',color='r',alpha=0.8,fontsize=25)
ax.text(-7.5,-8.5,r'$\ell$',fontsize=20,color='r')
ax.text(-5.5,-8.5,r'$x^2+y^2=1$',fontsize=20,color='g')
ax.text(0.8,-8.5,r'$|x|$',fontsize=20,color='b')
ax.text(3.5,-8.5,r'$\lim_{n \to \infty}(1+\frac{1}{n})^n$',
fontsize=20,color='c')
ax.set_title(r'$x^2 + (y -\sqrt[3]{x^2})^2 = 1$')
ax.set_xlabel(r'$i$',fontsize=20)
ax.set_ylabel(r'$u$',fontsize=20,rotation=0)
4. python怎么绘制三个叠加的等边三角形
import turtle as t
t.pencolor("blue") #笔触为蓝色
#绘制外部大三角形
t.fd(200)
t.seth(120)
t.fd(200)
t.seth(-120)
t.fd(200)
#绘制内部小三角形
t.seth(0)
t.fd(100)
t.seth(60)
t.fd(100)
t.seth(180)
t.fd(100)
t.seth(-60)
t.fd(100)
t.seth(120)
t.fd(100)
t.seth(0)
t.done()
5. 怎么用python画三角形并填色以及画五角星并且填色(急!!!)
可以. 用fill='#XXXXXX'参数:
from Tkinter import Tk, Canvas, Frame, BOTH
from math import sin, pi,cos
def pentagramPoints(cx, cy, R):
xita = 36*pi/180
r = R*cos(2*xita)/cos(xita)
points = []
for i in range(0, 10):
angle = i*xita + 0.5*xita
if i % 2:
points+=[cx + r*cos(angle), cy - r*sin(angle)]
else:
points+=[cx + R*cos(angle), cy - R*sin(angle)]
return points
if __name__ == '__main__':
root = Tk()
f = Frame(root)
f.pack(fill=BOTH, expand=1)
canvas = Canvas(f)
canvas.create_polygon(30, 10, 160, 470, 290, 10, outline="#000000", fill="#00ff00", width=3)
canvas.create_polygon(pentagramPoints(480, 240, 100), outline = '#000000', fill='#ff0000', width=3)
canvas.pack(fill=BOTH, expand=1)
root.geometry("640x480+300+300")
root.mainloop()
6. 用turtle库绘制一个边长为100的等边三角形该三角形的线条出三像素线条颜色为
import turtle
turtle.screensize(800,600)
turtle.pensize(3)
turtle.goto(0,100)
turtle.pencolor("yellow")
turtle.goto(70,50)
turtle.pencolor("red")
turtle.goto(0,0)
7. 求教python中的turtle
海龟库(turtle)
海龟库 (turtle) 是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。
海龟库积木盒有点类似Kitten创作工具的画笔和动作积木盒的结合体,可以绘制、控制画笔移动,大家使用一下就可以体会了哦。
海龟图的窗口坐标系同Kitten舞台类似,小窗口的情况下,海龟图高和宽是固定400像素。全屏的海龟图和浏览器本身的尺寸有关。
海龟图和math库、random库一样,需要先导入库import turtle,才可以使用库中的函数。使用海龟库中的函数,你可以画出各种有趣的图形。
8. 如何用Python的turth绘制出一个边长为200,三边颜色为红色的等边三角形
你好,答案如下所示。
程序缩进如图所示
import turtle
turtle.pencolor('red')
for i in range(3):
turtle.fd(200)
turtle.left(120)
turtle.hideturtle()
turtle.done()希望你能够详细查看。
如果你有不会的,你可以提问
我有时间就会帮你解答。
希望你好好学习。
每一天都过得充实。
9. 如何利用python turtle绘制一个圆的内接等边三角形
Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。