def main(): turtle.setup(1300, 800, 0, 0) # 启动图形窗口 pythonsize = 10 turtle.pensize(pythonsize) turtle.pencolor("blue") turtle.seth(-40) # 启动时运动的方向(角度) drawSnake(40, 80, 5, pythonsize/2)
def pop_right(): x,y,h = pos_stack.pop() turtle.up() turtle.setpos(x,y) turtle.seth(h) turtle.right(45) turtle.down()
def main(): turtle.setup(1300, 800, 0, 0) pythonsize = 30 turtle.pensize(pythonsize) turtle.pencolor('blue') turtle.seth(-40) drawSnake(rad = 40, angle = 80, len = 5, neckrad = pythonsize/2 )
def circle(r, n, angle): turtle.seth(angle) a = 2*r*sin(pi/n) phi = 180*(1-2/n) for i in range(int(n/2)+1): turtle.forward(a) turtle.right(180-phi)
def main(): file_name = "go" file_name = raw_input( 'Enter a file name or exit to quit program: ') while (file_name != "exit" and file_name != "Exit" and file_name != "quit" and file_name != "Quit"): f = open( file_name, 'r' ) first_line = f.readline() first_line = first_line.split() distance = float( first_line[0] ) angle = float( first_line[1] ) stack = [] wn = tur.Screen() for line in f: wn.clear() tur.penup() tur.seth(90) tur.setx(0) tur.sety(-200) tur.pendown() interprit_line(tur, line, angle, distance, stack) ts = tur.getscreen() ts.getcanvas().postscript(file=file_name +".eps") wn.exitonclick() file_name = raw_input( 'Enter a file name or exit to quit program: ')
def main(): turtle.setup(1300,800,0,0) pythonsize=1 turtle.pensize(pythonsize) turtle.pencolor("black") turtle.seth(-40) drawSnack(40,80,5,pythonsize/2)
def main(): turtle.setup(1300, 800, 0, 0) pythonsize = 30 turtle.pensize(pythonsize) turtle.pencolor("blue") turtle.seth(-40) drawSnake(40, 80, 5, pythonsize / 2)
def draw_background(): t.setup(300, 500) t.title('Hangman') t.pu() t.setpos(-100, -200) t.seth(0) t.pd() t.fd(200)
def main(): turtle.setup(1300, 800, 10, 10) pensize = 30 turtle.pensize(pensize) turtle.pencolor('blue') turtle.seth(-40) draw_snake(40, 80, 5, pensize / 2) turtle.done()
def pop(dummy): global stack turtle.up() turtle.goto(stack[-1][0]) turtle.seth(stack[-1][1]) stack = stack[:-1] turtle.down() return dummy[1:]
def main(): #初始化窗口(宽度,高度,距屏幕左边距离,距屏幕顶边距离) turtle.setup(1300,700,0,20) pythonsize=30 turtle.pensize(pythonsize) turtle.pencolor("blue") #定义初始爬行方向 turtle.seth(-40) drawSnake(40,80,5,pythonsize/2)
def dibujar_cuadrado(x, y, a): up() goto(x + 0.5 * a, y - 0.5 * a) seth(90) down() for i in range(4): forward(a) left(90)
def draw_wall(x, y): goto(x, y) turtle.color("red") if y % 2 == 0: turtle.seth(0) else: turtle.seth(90) turtle.forward(5) turtle.back(10)
def drawSnake(radius,angle,length): turtle.seth(-45) for i in range(length): turtle.circle(redius,angle) turtle.circle(-redius,angle) turtle.circle(redius,angle/2) turtle.fd(40) turtle.circle(16,180) turtle.fd(40*3/2)
def draw(self): ''' Draws the object at its current (x, y) coordinates. ''' turtle.goto(self.x, self.y) turtle.seth(self.heading()) turtle.shape(self.shape) turtle.color(self.color) return turtle.stamp()
def main(): #width,height turtle.setup(1000,200,100,100) pythonsize = 50 #trace width turtle.pensize(pythonsize) turtle.pencolor("red") #trace direction turtle.seth(-40) drawSnake(40,80,3,pythonsize/2)
def owoc(): t.pu() t.lt(30) t.fd(B) t.lt(30) t.fd(B) t.seth(300) t.pd() for i in range(5): #pierwsza warstwa wsk_romb("olive") t.rt(30) t.lt(30) #druga warstwa for i in range(4): t.fd(B) t.lt(30) szer_romb("green") t.rt(30) t.bk(B) t.lt(30) t.rt(120) # trzecia warstwa for i in range(3): for j in range(2): t.fd(B) t.lt(30) kwadrat("yellow") for j in range(2): t.rt(30) t.bk(B) t.lt(30) t.rt(30) #czwarta warstwa for i in range(2): for j in range(3): t.fd(B) t.rt(30) t.fd(B) t.lt(180) szer_romb("orange") t.rt(180) t.bk(B) for j in range(3): t.lt(30) t.bk(B) t.lt(30) for i in range(5): #piąta warstwa t.fd(B) t.rt(30) wsk_romb("red")
def horizontal(row): turtle.goto(xstart, ystart - length * (row + 1)) turtle.seth(0) for x in range(0, maze.size): status = maze.cells[row * maze.size + x].edges[-1].walled if status: turtle.down() else: turtle.up() turtle.forward(length) turtle.up()
def heart(x,y,h=100): go(x,y) turtle.fillcolor("white") turtle.begin_fill() turtle.goto(x-h/2, y+0.75*h) turtle.seth(90) turtle.circle(-h/4, extent=180) turtle.seth(90) turtle.circle(-h/4, extent=180) turtle.goto(x,y) turtle.end_fill() go(x+h/2,y)
def main(): turtle.setup(1300,800,0,0) pythonsize=1 turtle.pensize(pythonsize) turtle.fd(100) turtle.pencolor("black") turtle.seth(120) turtle.fd(100) turtle.pencolor("black") turtle.seth(240) turtle.fd(100) turtle.pencolor("black")
def star(r,n): angle = 180/n l = 2*r*cos(pi/(2*n)) turtle.penup() turtle.seth(90) turtle.forward(r) turtle.right(180-angle/2) turtle.pendown() for i in range(n): turtle.forward(l) turtle.right(180-angle)
def vertical(col): turtle.goto(xstart + length * (col + 1), ystart) turtle.seth(-90) for x in range(0, maze.size): if x == maze.size - 1: status = maze.cells[x * maze.size + col].edges[-1].walled else: status = maze.cells[x * maze.size + col].edges[-2].walled if status: turtle.down() else: turtle.up() turtle.forward(length) turtle.up()
def drawPoints(row): turtle.seth(270) turtle.color("grey") for i in range(len(row)): tempX = row[i][0] temp = 1.414 * ((tempX * 212.1) / 300) turtlex = row[i][1] - temp turtley = row[i][2] - temp turtle.pu() turtle.goto(turtlex,turtley) turtle.pd() turtle.dot(4,"blue") turtle.write("p"+format(i,"2d")) turtle.fd(row[i][2])
def drawBoard(): global b #actually draw the board :D turtle.ht() turtle.width(5) turtle.up() turtle.goto(-3*b/2.0,b/2.0) turtle.down() turtle.seth(0) turtle.forward(3*b) turtle.up() turtle.goto(-3*b/2.0,-b/2.0) turtle.down() turtle.seth(0) turtle.forward(3*b) turtle.up() turtle.goto(-b/2.0,3*b/2.0) turtle.down() turtle.seth(270) turtle.forward(3*b) turtle.up() turtle.goto(b/2.0,3*b/2.0) turtle.down() turtle.seth(270) turtle.forward(3*b)
def execute_L(turtle, state, command_array): saved_state = [] for command in command_array: if command == "F" or command == "f": turtle.forward(10) elif command == "+": turtle.right(5) elif command == "-": turtle.right(355) elif command == "[": saved_state = [turtle.heading(), turtle.pos()] elif command == "]": turtle.goto(saved_state[1]) turtle.seth(int(saved_state[0]))
def eraser(x, y, a, b): # turtle.up() gotoxy(x, y) turtle.seth(0) turtle.begin_fill() turtle.begin_poly() n = 0 while n<=1: turtle.fd(a) turtle.right(90) turtle.fd(b) turtle.right(90) n += 1 turtle.end_poly() turtle.end_fill()
def draw_square(size): turtle.begin_fill() turtle.seth(270) turtle.pd() turtle.fd(size/2) turtle.right(90) turtle.fd(size/2) turtle.right(90) turtle.fd(size) turtle.right(90) turtle.fd(size) turtle.right(90) turtle.fd(size) turtle.right(90) turtle.fd(size) turtle.end_fill()
def eraser(x, y, xs, ys): # turtle.up() gotoxy(x, y) turtle.seth(0) turtle.color("blue", "white") turtle.begin_fill() turtle.begin_poly() n = 0 while n<=1: turtle.fd(a) turtle.right(90) turtle.fd(b) turtle.right(90) n += 1 turtle.end_poly() turtle.end_fill()
def Sierpinsmod(size,mod,alto=1024,ancho=700,dx=4): r=1.0*dx pp=dx # Grueso de los puntos turtle.colormode(1) turtle.ht() turtle.speed("fastest") turtle.tracer(False) turtle.penup() turtle.home() ox = -(turtle.window_width()/2)+2*dx oy = (turtle.window_height()/2)-2*dx P=Pascal(size,mod) turtle.setpos(ox,oy) turtle.dot(pp,clr(P[0][0],mod)) turtle.seth(90) for d in range(1,2*size-1): print("iniciando diagonal ",d), if d< size: initx=0 # Posiciones iniciales inity=d else: initx = d-size+1 inity = size-1 turtle.setpos(ox+initx*dx-dx,oy-inity*dx-dx) for k in range(initx,inity+1): # Recorremos la diagonal de suma d # Los puntos corresponden a (k, d-k) turtle.right(90) turtle.forward(dx) turtle.left(90) turtle.forward(dx) t=P[k][d-k] if t > 0: turtle.dot(pp, clr(t,mod)) if d % 20 ==0: turtle.update()
def rectangulo(px, py, ancho, alto): # Nos posicionamos en la esquina superior derecha # del rectángulo que vamos a dibujar sin dejar rastro # y miramos hacia la izquierda para empezar siempre igual t.penup() t.goto(px + ancho / 2, py + alto / 2) t.seth(180) t.pendown() # Dibujamos la estructura t.forward(ancho) t.left(90) t.forward(alto) t.left(90) t.forward(ancho) t.left(90) t.forward(alto) t.left(90)
def peppa(): import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.color((255, 155, 192), "pink") t.setup(840, 500) t.speed(10) # 鼻子 t.pu() t.goto(-100, 100) t.pd() t.seth(-30) t.begin_fill() a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 t.lt(3) # 向左转3度 t.fd(a) # 向前走a的步长 else: a = a - 0.08 t.lt(3) t.fd(a) t.end_fill() t.pu() t.seth(90) t.fd(25) t.seth(0) t.fd(10) t.pd() t.pencolor(255, 155, 192) t.seth(10) t.begin_fill() t.circle(5) t.color(160, 82, 45) t.end_fill() t.pu() t.seth(0) t.fd(20) t.pd() t.pencolor(255, 155, 192) t.seth(10) t.begin_fill() t.circle(5) t.color(160, 82, 45) t.end_fill() # 头 t.color((255, 155, 192), "pink") t.pu() t.seth(90) t.fd(41) t.seth(0) t.fd(0) t.pd() t.begin_fill() t.seth(180) t.circle(300, -30) t.circle(100, -60) t.circle(80, -100) t.circle(150, -20) t.circle(60, -95) t.seth(161) t.circle(-300, 15) t.pu() t.goto(-100, 100) t.pd() t.seth(-30) a = 0.4 for i in range(60): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 t.lt(3) # 向左转3度 t.fd(a) # 向前走a的步长 else: a = a - 0.08 t.lt(3) t.fd(a) t.end_fill() # 耳朵 t.color((255, 155, 192), "pink") t.pu() t.seth(90) t.fd(-7) t.seth(0) t.fd(70) t.pd() t.begin_fill() t.seth(100) t.circle(-50, 50) t.circle(-10, 120) t.circle(-50, 54) t.end_fill() t.pu() t.seth(90) t.fd(-12) t.seth(0) t.fd(30) t.pd() t.begin_fill() t.seth(100) t.circle(-50, 50) t.circle(-10, 120) t.circle(-50, 56) t.end_fill() # 眼睛 t.color((255, 155, 192), "white") t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-95) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() t.color((255, 155, 192), "white") t.pu() t.seth(90) t.fd(-25) t.seth(0) t.fd(40) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() # 腮 t.color((255, 155, 192)) t.pu() t.seth(90) t.fd(-95) t.seth(0) t.fd(65) t.pd() t.begin_fill() t.circle(30) t.end_fill() # 嘴 t.color(239, 69, 19) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(-100) t.pd() t.seth(-80) t.circle(30, 40) t.circle(40, 80) # 身体 t.color("red", (255, 99, 71)) t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-78) t.pd() t.begin_fill() t.seth(-130) t.circle(100, 10) t.circle(300, 30) t.seth(0) t.fd(230) t.seth(90) t.circle(300, 30) t.circle(100, 3) t.color((255, 155, 192), (255, 100, 100)) t.seth(-135) t.circle(-80, 63) t.circle(-150, 24) t.end_fill() # 手 t.color((255, 155, 192)) t.pu() t.seth(90) t.fd(-40) t.seth(0) t.fd(-27) t.pd() t.seth(-160) t.circle(300, 15) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(0) t.pd() t.seth(-10) t.circle(-20, 90) t.pu() t.seth(90) t.fd(30) t.seth(0) t.fd(237) t.pd() t.seth(-20) t.circle(-300, 15) t.pu() t.seth(90) t.fd(20) t.seth(0) t.fd(0) t.pd() t.seth(-170) t.circle(20, 90) # 脚 t.pensize(10) t.color((240, 128, 128)) t.pu() t.seth(90) t.fd(-75) t.seth(0) t.fd(-180) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color("black") t.pensize(15) t.fd(20) t.pensize(10) t.color((240, 128, 128)) t.pu() t.seth(90) t.fd(40) t.seth(0) t.fd(90) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color("black") t.pensize(15) t.fd(20) # 尾巴 t.pensize(4) t.color((255, 155, 192)) t.pu() t.seth(90) t.fd(70) t.seth(0) t.fd(95) t.pd() t.seth(0) t.circle(70, 20) t.circle(10, 330) t.circle(70, 30)
def turn_up(): t.seth(90) t.fd(10)
import turtle turtle.penup turtle.pendown turtle.pensize(5) turtle.fd(150) turtle.seth(90) turtle.fd(150) turtle.seth(180) turtle.fd(150) turtle.seth(270) turtle.fd(150)
import turtle turtle.pencolor('red') turtle.fillcolor('red') turtle.begin_fill() turtle.circle(200, 180) turtle.circle(100, 180) turtle.circle(-100, 180) turtle.end_fill() turtle.pencolor('blue') turtle.fillcolor('blue') turtle.begin_fill() turtle.circle(-100) turtle.circle(-200, 180) turtle.seth(180) turtle.circle(100, 180) turtle.end_fill() turtle.penup() turtle.pencolor('white') turtle.fillcolor('white') turtle.begin_fill() turtle.sety(60) turtle.circle(40) turtle.end_fill() turtle.pencolor('black') turtle.fillcolor('black') turtle.begin_fill() turtle.sety(260) turtle.circle(40)
t.speed(10) t.setup(width=0.6, height=0.85) t.title('哆啦A梦') #-------------------------------------------- ''' 头 ''' t.penup() # t.goto(0, 200) t.goto(-75, -61.8) t.seth(150) t.pendown() t.color('black', '#4187F1') t.begin_fill() # t.circle(-150) for i in range(300): t.rt(1) t.forward(2 * m.pi * 150 / 360) t.end_fill() t.seth(0) #------------------------------------------------------ ''' 脸
#PythonDraw.pr import turtle as tt tt.setup(650, 350, 200, 200) tt.penup() tt.fd(-250) tt.pendown() tt.pensize(25) tt.pencolor("purple") tt.seth(-40) for i in range(4): tt.circle(40, 80) tt.circle(-40, 80) tt.circle(40, 80 / 2) tt.fd(40) tt.circle(16, 180) tt.fd(40 * 2 / 3) tt.done()
import turtle as t import time t.setup(1500, 1400, 0, 0) #画布大小、位置。参数说明:width,height,startx,starty t.pensize(30) #画笔宽度。别名:turtle.width() t.pencolor("green") #画笔颜色。参数可选颜色字符串、RGB小数值、整数值 t.seth(-40) #画笔行进方向 ''' t.circle(50, 270, steps=10) t.lt(90) t.fd(100) ''' #太阳花 def drawSunFlower(): t.color("red", "yellow") t.speed(10) t.begin_fill() for _ in range(50): t.forward(200) t.left(170) end_fill() time.sleep(1) #小蟒蛇 def drawSnake(rad, angle, len, neckrad): for _ in range(len): t.circle(rad, angle) t.circle(-rad, angle)
def Beat(n,a): turtle.seth(a) # 设置海龟绝对角度 turtle.fd(n) turtle.seth(-a) turtle.fd(2*n) turtle.seth(a) turtle.fd(3*n) turtle.seth(-a) turtle.fd(4*n) turtle.seth(a) turtle.fd(3*n) turtle.seth(-a) turtle.fd(2*n) turtle.seth(a) turtle.fd(n) turtle.seth(0)
def displayMaze(maze, xstart, ystart, length): turtle.up() def vertical(col): turtle.goto(xstart + length * (col + 1), ystart) turtle.seth(-90) for x in range(0, maze.size): if x == maze.size - 1: status = maze.cells[x * maze.size + col].edges[-1].walled else: status = maze.cells[x * maze.size + col].edges[-2].walled if status: turtle.down() else: turtle.up() turtle.forward(length) turtle.up() def horizontal(row): turtle.goto(xstart, ystart - length * (row + 1)) turtle.seth(0) for x in range(0, maze.size): status = maze.cells[row * maze.size + x].edges[-1].walled if status: turtle.down() else: turtle.up() turtle.forward(length) turtle.up() def drawExit(row, col): turtle.goto(xstart + col * length, ystart - row * length) turtle.down() turtle.begin_fill() for x in range(0, 4): turtle.forward(length) turtle.right(90) turtle.end_fill() turtle.up() for row in range(maze.size): for col in range(maze.size): if maze.cells[row * maze.size + col] == maze.end: turtle.color("white", "red") drawExit(row, col) turtle.color("black") if maze.cells[row * maze.size + col] == maze.start: turtle.color("white", "green") drawExit(row, col) turtle.color("black") turtle.goto(xstart, ystart) turtle.seth(0) turtle.down() for x in range(0, 4): turtle.forward(length * maze.size) turtle.right(90) turtle.up() for i in range(0, maze.size - 1): vertical(i) for j in range(0, maze.size - 1): horizontal(j) turtle.up() turtle.goto(xstart, ystart)
# coding:utf-8 import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.color((255, 155, 192), "pink") t.setup(840, 500) t.speed(10) #鼻子 t.pu() t.goto(-100, 100) t.pd() t.seth(-30) t.begin_fill() a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: a = a - 0.08 t.lt(3) t.fd(a) t.end_fill() t.pu() t.seth(90) t.fd(25)
#使用turtle库,绘制一个风轮效果,其中,每个风轮内角为45度,风轮边长150像素。 #exercise2.5.py import turtle as t t.pensize(2) for i in range(4): t.seth(90 * i) t.fd(150) t.right(90) t.circle(-150, 45) t.goto(0, 0)
import turtle as t t.setup(650, 350, 200, 200) t.pu() t.fd(-250) t.pd() t.pensize(25) t.pencolor("green") t.seth(-45) for i in range(4): t.circle(40, 90) t.circle(-40, 90) t.circle(40, 45) t.fd(40) t.circle(-16, 180) t.fd(40 * 2 / 3) t.done()
t.left(174) t.forward(80) t.pu() t.home() t.goto(0, 104) t.pensize(3) t.pencolor('black') t.pd() t.left(180) t.forward(80) t.pu() t.goto(-70, 70) t.pd() t.color('black', 'red') t.pensize(6) t.seth(-60) t.begin_fill() t.circle(80, 40) t.circle(80, 80) t.end_fill() t.pu() t.home() t.goto(-80, 70) t.pd() t.forward(160) t.pu() t.home() t.goto(-50, 50) t.pd() t.pensize(1) t.fillcolor("#eb6e1a")
'''制作人:于家汉 该程序系作者原创,只可用于学习。具体程序解释权归作者所有。 该程序最后关于文字的部分代码参考了python123网站上用户苏悦迪的代码,在此表示感谢。 ''' #初始化(6~12) import turtle as y y.pensize(1) y.penup() y.seth(-90) y.fd(240) y.seth(90) y.pendown() #枝干(17~32) y.pencolor("brown") y.fillcolor(0.64, 0.17, 0.17) y.begin_fill() y.fd(245) y.seth(-180) y.fd(10) y.seth(-90) y.fd(245) y.seth(0) y.fd(10) y.penup() y.seth(90) y.fd(120) y.seth(30) y.pendown() y.end_fill()
turtle.pendown() ''' 花的绘制, (旋转角度)100*18(旋转次数), 刚好为360度的5倍,因而能够闭合。大家 也可以尝试改变这两个值,得到不同效果。 ''' for i in range(18): turtle.fd(300) turtle.left(100) #茎秆部分,移动画笔到合适位置 turtle.fd(150) turtle.right(90) turtle.pensize(8) turtle.pencolor("green") turtle.fd(400) turtle.penup() turtle.pensize(6) turtle.pendown() #叶子的绘制 turtle.fd(-250) turtle.seth(45) turtle.circle(-130, 60) turtle.seth(-135) turtle.circle(-130, 60) turtle.seth(135) turtle.circle(130, 60) turtle.seth(-45) turtle.circle(130, 60) turtle.done()
import turtle as t t.setup(650,350,200,200) t.pensize(5) t.pencolor("red") for i in (270,210,150,90,30,-30): t.seth(i) t.fd(60) t.seth(i-120) t.fd(60) t.seth(i-240) t.fd(120) t.down t.seth(30)
import turtle turtle.pensize(2) turtle.penup() turtle.goto(0, 150) turtle.pendown() turtle.circle(-150, ) for i in range(8): turtle.penup() turtle.goto(0, 0) turtle.pendown() turtle.seth(360 / 8 * i) #想要n等分就360/n*i turtle.fd(150) turtle.goto(0, 0)
# 引入动画库 import turtle as t # 初始化 t.setup(650, 350, 200, 200) # 抬笔,只移动,不绘制 t.penup() # 后退 t.forward(-250) # 放下笔 t.pendown() # 设置笔的宽度 t.pensize(25) # 设置笔的颜色 t.pencolor("purple") # 改变角度 t.seth(-40) # 循环画圆 for i in range(4): # 半径 弧度 t.circle(40, 80) t.circle(-40, 80) t.circle(40, 80 / 2) t.forward(40) t.circle(16, 180) t.forward(40 * 2 / 3) # 画图完毕 t.done()
''' @Author : sean cheng @Email : [email protected] @CreateTime : 2018/9/10 @Program : 使用turtle库的turtle.fd()函数和turtle.seth()函数绘制嵌套六角形, 六角形边长从1像素开始,第一条边从0度方向开始, 边长按照3个像素递增 ''' import turtle edge = 6 d = 0 k = 1 for j in range(10): for i in range(edge): turtle.fd(k) d += 360 / 60 turtle.seth(d) k += 3 turtle.done()
# -*- coding: utf-8 -*- """ Created on Sun May 28 16:47:21 2017 @author: Administrator """ import turtle turtle.fd(240) turtle.seth(120) turtle.fd(240) turtle.seth(-120) turtle.fd(240) turtle.penup() turtle.seth(0) turtle.fd(120) turtle.pendown() turtle.seth(60) turtle.fd(120) turtle.seth(180) turtle.fd(120) turtle.seth(-60) turtle.fd(120)
import turtle turtle.setup(650, 350, 200, 200) #设置启动窗体的宽,高,起始点坐标的x,起始点坐标的y。setup并不是必须的。后两个参数不写,表明窗体在屏幕正中 turtle.penup() #画笔控制,抬起画笔,因此不会再画布上留下轨迹。可简写为turtle.pu turtle.fd(-250) turtle.pendown() #画笔控制,落下画笔,因此后面会在画布上留下轨迹.可简写文turtle.pd turtle.pensize(25) #画笔粗细。也可以直接使用turtle.width() turtle.pencolor("purple") #可以使用字符串或者r,g,b定义画笔颜色 turtle.seth(-40) #全称turtle.setheading, for i in range(4): turtle.circle(40, 80) turtle.circle(-40, 80) turtle.circle(40, 80 / 2) turtle.fd(40) turtle.circle(16, 180) #整数是255模式,小数是小数模式 turtle.fd(40 * 2 / 3) turtle.done() #以下为实例及解释 turtle.goto(10, 10) #绝对坐标,代表以海龟为中心的x,y坐标 turtle.fd() #海龟坐标,海龟前进 turtle.bk() #海龟坐标,海龟后退 turtle.circle(r, angle) #海龟坐标,半径,角度。 turtle.circle(100) #绘制半径为100像素的原型 turtle.circle(-100, 180) #绘制半径为100,逆时针❀半圆 turtle.seth(angle) #改变当前海龟的行进方向,并不行进,angle表示绝对角度 turtle.left(angle) #向左旋转角度 turtle.right(angle) #向右旋转角度 turtle.color()
t.circle(-15) t.end_fill() # ==== head() zui() youshou() yanjing() youzhua() houjiao() houtui() yifu() koudai() qiantui() qianjiao() jiaodi() xie() yiling() zuokou() zuoshou() zuozhua() zuoyl() t.penup() t.goto(80, -40) t.pendown() t.seth(100) t.circle(90, 85) t.done()
turtle.up() turtle.goto(-600, 300) turtle.down() turtle.begin_fill() for i in range(2): turtle.forward(450) turtle.right(90) turtle.forward(300) turtle.right(90) turtle.end_fill() # 党徽 turtle.fillcolor("yellow") turtle.pencolor("yellow") turtle.up() turtle.goto(-370, 240) turtle.seth(225) turtle.down() turtle.begin_fill() turtle.fd(125) turtle.right(90) turtle.fd(50) turtle.right(90) turtle.fd(100) turtle.right(90) turtle.circle(25, 90) turtle.end_fill() turtle.up() turtle.goto(-420, 210) turtle.seth(-45) turtle.down() turtle.begin_fill()
def yanjing(): t.begin_fill() t.penup() t.goto(-125, 140) t.pendown() t.fillcolor("#000000") t.pencolor("black") t.seth(100) t.circle(-25, 80) t.seth(40) t.circle(-200, 23) t.seth(-90) t.fd(45) t.seth(195) t.circle(200, 27) t.seth(150) t.circle(-12, 90) t.goto(-125, 140) t.end_fill() # 黑色 t.begin_fill() t.penup() t.goto(-39, 205) t.pendown() t.fillcolor("#E6E8FA") t.setheading(90) t.circle(-8, 180) t.seth(-90) t.fd(45) t.circle(-8, 180) t.goto(-39, 205) t.end_fill() # 银色 t.begin_fill() t.penup() t.goto(-23, 160) t.pendown() t.fillcolor("#E6E8FA") t.seth(-78) t.circle(85, 130) t.goto(-23, 160) t.end_fill() # 银色 t.begin_fill() t.penup() t.goto(-23, 190) t.pendown() t.fillcolor("#E6E8FA") t.seth(-90) t.circle(90) t.end_fill() # 银色 t.begin_fill() t.penup() t.goto(155, 205) t.pendown() t.fillcolor("#000000") t.seth(-15) t.circle(-100, 20) t.seth(-60) t.circle(-105, 25) t.seth(160) t.circle(200, 13.5) t.seth(75) t.circle(90, 20) t.goto(155, 205) t.end_fill() # 黑色 t.begin_fill() t.penup() t.goto(128, 195) t.pendown() t.fillcolor("#ffffff") t.circle(60) t.end_fill() # 白色 t.begin_fill() t.penup() t.goto(110, 150) t.pendown() t.fillcolor("#000000") t.seth(70) t.circle(70, 110) t.seth(20) t.circle(-60, 150) t.end_fill() # 黑色 t.begin_fill() t.penup() t.goto(25, 210) t.pendown() t.fillcolor("#B85300") t.circle(20) t.end_fill() # 白色 t.begin_fill() t.penup() t.goto(32, 204) t.pendown() t.fillcolor("#000000") t.circle(8) t.end_fill()
def turn_down(): t.seth(270) t.fd(10)
def yifu(): t.begin_fill() t.penup() t.goto(-45, -70) t.pendown() t.fillcolor("#0045D9") t.setheading(-15) t.circle(500, 5) t.circle(400, 26) t.seth(-112) t.circle(-250, 7) t.seth(-69) t.circle(-250, 7) t.right(15) t.circle(-320, 18) t.circle(-330, 10) t.fd(80) t.right(81) t.fd(190) t.seth(141) t.circle(-180, 15) t.circle(-150, 30) t.right(6) t.circle(-90, 15) t.seth(-45) t.circle(50, 10) t.seth(-30) t.circle(200, 20) t.circle(150, 10) t.seth(92) t.circle(500, 10) t.setheading(75) t.goto(-45, -70) t.end_fill()
# From https://zhuanlan.zhihu.com/p/347462010 # Draw Peppa Pig import turtle as t t.screensize(400, 300) t.pensize(4) # 设置画笔的大小 t.colormode(255) # 设置GBK颜色范围为0-255 t.color((255, 155, 192), "pink") # 设置画笔颜色和填充颜色(pink) t.setup(840, 500) # 设置主窗口的大小为840*500 t.speed(10) # 设置画笔速度为10 # 鼻子 t.pu() # 提笔 t.goto(-100, 100) # 画笔前往坐标(-100,100) t.pd() # 下笔 t.seth(-30) # 笔的角度为-30° t.begin_fill() # 外形填充的开始标志 a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 t.lt(3) # 向左转3度 t.fd(a) # 向前走a的步长 else: a = a - 0.08 t.lt(3) t.fd(a) t.end_fill() # 依据轮廓填充 t.pu() # 提笔 t.seth(90) # 笔的角度为90度 t.fd(25) # 向前移动25
#PythonDraw.py import turtle turtle.setup(650,350,200,200) turtle.penup() turtle.fd(-250) turtle.pendown() turtle.pensize(25) turtle.pencolor("purple") turtle.seth(-40) for i in range(4): turtle.circle(40,80) turtle.circle(-40, 80) turtle.circle(40, 80/2) turtle.fd(40) turtle.circle(16,180) turtle.fd(40 * 2/3) turtle.done()
def draw_eyes(): """ 画小猪佩奇的眼睛 :return: """ t.color((255, 155, 192), "white") t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-95) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() t.color((255, 155, 192), "white") t.pu() t.seth(90) t.fd(-25) t.seth(0) t.fd(40) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill()
import turtle as t t.setup(600, 600, None,None) t.pu() t.fd(-120) t.pensize(1) t.width(5) t.pd() t.fd(250) t.seth(120) t.fd(250) t.seth(-120) t.fd(250) t.fd(250) t.seth(0) t.fd(250) t.fd(250) t.seth(120) t.fd(250) t.seth(-120) t.fd(250) t.seth(120) t.fd(250)