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)位置開始,它根據一組函數指令的控制,在這個平面坐標系中移動,從而在它爬行的路徑上繪制了圖形。