Python 海龟turtle 画图常见画图代码⼤全import turtle # 设置初始位置turtle.penup() # 提起画笔turtle.left(90) # 逆时针旋转九⼗度turtle.fd(200) # 向前移动⼀段距离 fd=forward turtle.pendown() # 放下画笔移动画笔开始绘制turtle.right(90) # 顺时针旋转九⼗度# 花蕊turtle.fillcolor("red") # 填充颜⾊turtle.begin_fill() # 开始填充turtle.circle(10, 180) # 画⼀圆,10是半径,180是弧度turtle.circle(25, 110)turtle.left(50)turtle.circle(60, 45)turtle.circle(20, 170)turtle.right(24)turtle.fd(30)turtle.left(10)turtle.circle(30, 110)turtle.fd(20)turtle.left(40)turtle.circle(90, 70)turtle.circle(30, 150)turtle.right(30)turtle.fd(15)turtle.circle(80, 90)turtle.left(15)turtle.fd(45)turtle.right(165)turtle.fd(20)turtle.left(155)turtle.circle(150, 80)turtle.left(50)turtle.circle(150, d_fill() # 结束填充# 花瓣1turtle.left(150)turtle.circle(-90, 70)turtle.left(20)turtle.circle(75, 105)turtle.setheading(60) # urtle.setheading(angle) 或 turtle.seth(angle):改变⾏进⽅向 angle:⾏进⽅向的绝对⾓度,可以为负值turtle.circle(80, 98)turtle.circle(-90, 40)# 花瓣2turtle.left(180)turtle.circle(90, 40)turtle.circle(-80, 98)turtle.setheading(-83)# 叶⼦1turtle.fd(30)turtle.left(90)turtle.fd(25)turtle.left(45)turtle.fillcolor("green")turtle.begin_fill()turtle.circle(-80, 90)turtle.right(90)
1
二进制转换十进制如何算
2
3
4
5
6
7
8
9
asp培训公司>霹雳布袋戏r1810
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
python代码画图案27
28
29
30
31
32
33
34
35interface传感器
36
37
2020国考面试38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
画爱⼼turtle.right(90)turtle.circle(-80, d_fill()turtle.right(135)turtle.fd(60)turtle.left(180)turtle.fd(85)turtle.left(90)turtle.fd(80)# 叶⼦2turtle.right(90)turtle.right(45)turtle.fillcolor("green")turtle.begin_fill()turtle.circle(80, 90)turtle.left(90)turtle.circle(80, d_fill()turtle.left(135)turtle.fd(60)turtle.left(180)turtle.fd(60)turtle.right(90)turtle.circle(200, 60)# 设置成画完不会⾃动退出turtle.done()626364656667686970717273747576777879808182838485868788899091import turtle import time # 画爱⼼的顶部def LittleHeart(): for i in range(200): turtle.right(1) turtle.forward
(2)# 输⼊表⽩的语句,默认I Love you love = input('Please enter a sentence of love, otherwise the default is "I Love you": ') ## 输⼊署名或者赠谁,没有不执⾏me = input('Please enter pen name, otherwise the default do not execute: ')if love == '': love = 'I Love you'# 窗⼝⼤⼩turtle.setup(width=900,height=500)# 颜⾊lor('red', 'pink')# 笔粗细turtle.pensize(3)# 速度turtle.speed(1)# 提笔turtle.up()# 隐藏笔turtle.hideturtle()# 去到的坐标,窗⼝中⼼为0,0
123456789101112131415161718192021222324252627282930
画樱花树(0, -180)turtle.showturtle()# 画上线turtle.down()turtle.speed(1)turtle.begin_fill()turtle.left(140)turtle.forward(224)# 调⽤画爱⼼左边的顶部LittleHeart()# 调⽤画爱右边的顶部turtle.left(120)LittleHeart()# 画下线turtle.forward(d_fill()turtle.pensize(5)turtle.up()turtle.hideturtle()# 在⼼中写字 ⼀次(0, 0)turtle.showturtle()lor('#CD5C5C', 'pink')# 在⼼中写字 font 可以设置字体⾃⼰电脑有的都可以设 align 开始写字的位置turtle.write(love, font=('gungsuh', 30,), align="center")turtle.up()turtle.hideturtle()time.sleep(2)# 在⼼中写字 ⼆次(0, 0)turtle.showturtle()lor('red', 'pink')turtle.write(love, font=('gungsuh', 30,), align="center")turtle.up()turtle.hideturtle()# 写署名if me != '': lor('black', 'pink') time.sleep(2) (180, -180) turtle.showturtle() turtle.write(me, font=(20,), align="center",
move=True)# 点击窗⼝关闭window = turtle.Screen()itonclick()3132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677from turtle import *from random import *from math import *class Tree: def __init__(self): setup(1000, 700) bgcolor(1, 1, 1) # 背景⾊ # ht() # 隐藏turtle speed(10) # 速度 1-10渐进,0 最快 # tracer(1, 100) # 设置绘图屏幕刷新频率,参数1设置在正常刷新频次的第参数1次刷新,参数2设置每次刷新的时延 tracer(0, 0) pu() # 抬笔12345678910111213
backward(100) # 保证笔触箭头⽅向始终不向下,此处使其左转90度,⽽不是右转 left(90) # 左转90度 backward(300) # 后退300 def tree(self, n, l): pd() # 下笔 # 阴影效果 t = cos(radians(heading() + 45)) / 8 + 0.25 pencolor(t, t, t) pensize(n / 1.2) forward(l) # 画树枝 if n > 0: b = random() * 15 + 10 # 右分⽀偏转⾓度 c = random() * 15 + 10 # 左分⽀偏转⾓度 d = l * (random() * 0.25 + 0.7) # 下⼀个分⽀的长度 # 右转⼀定⾓度,画右分⽀ right(b) (n - 1, d) # 左转⼀定⾓度,画左分⽀ left(b + c) (n - 1, d) # 转回来 right(c) else: # 画叶⼦ right(90) n = cos(radians(heading() - 45)) / 4 + 0.5 pencolor(n, n * 0.8, n * 0.8) fillcolor(n, n * 0.8, n * 0.8) begin_fill() circle(3) left(90) end_fill() # 添加0.3倍的飘落叶⼦ if random() > 0.7: pu() # 飘落 t = heading() an = -
40 + random() * 40 setheading(an) dis = int(800 * random() * 0.5 + 400 * random() * 0.3 + 200 * random() * 0.2) forward(dis) setheading(t) # 画叶⼦ pd() right(90) n = cos(radians(heading() - 45)) / 4 + 0.5 pencolor(n * 0.5 + 0.5, 0.4 + n * 0.4, 0.4 + n * 0.4) fillcolor(n, n * 0.8, n * 0.8) begin_fill() circle(2) left(90) end_fill() pu() # 返回 t = heading() setheading(an) backward(dis) setheading(t) # pass pu() backward(l) # 退回def main(): tree = Tree() (12, 100) # 递归7层 done()131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
画⽪卡丘 done()if __name__ == '__main__': main()787980# coding:utf-8import turtle as t import time # ⽪卡丘# 基础设置t.screensize(800, 600)t.pensize(2) # 设置画笔的⼤⼩t.speed(10) # 设置画笔速度为10# 画左偏曲线函数def radian_left(ang, dis, step, n): for i in range(n): dis += step # dis 增⼤step t.lt(ang) # 向左转ang 度 t.fd(dis) # 向前⾛dis 的步长def radian_right(ang, dis, step, n): for i in range(n): dis += step t.rt(ang) # 向左转ang 度 t.fd(dis) # 向前⾛dis 的步长# 画⽿朵def InitEars(): t.color("black", "yellow") # 左⽿朵曲线 t.pu() # 提笔 t.goto(-50, 100) # 笔头初始位置 t.pd() # 下笔 t.setheading(110) # 画笔⾓度 t.begin_fill() radian_left(1.2, 0.4, 0.1, 40) t.setheading(270) # 画笔⾓度 radian_left(1.2, 0.4, 0.1, 40) t.setheading(44) # 画
笔⾓度 t.forward(32) t.end_fill() # 右⽿朵曲线 t.pu() # 提笔 t.goto(50, 100) # 笔头初始位置 t.pd() # 下笔 t.setheading(70) # 画笔⾓度 t.begin_fill() radian_right(1.2, 0.4, 0.1, 40) t.setheading(270) # 画笔⾓度 radian_right(1.2, 0.4, 0.1, 40) t.setheading(136) # 画笔⾓度 t.forward(32) t.end_fill() # ⽿朵⿊ t.begin_fill() t.fillcolor("black") t.pu() # 提笔 t.goto(88, 141) # 笔头初始位置 t.pd() # 下笔 t.setheading(35) # 画笔⾓度 radian_right(1.2, 1.6, 0.1, 16) t.setheading(270) # 画笔⾓度 radian_right(1.2, 0.4, 0.1, 25) t.setheading(132) # 画笔⾓度123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论