├── .gitignore ├── Android_logo.py ├── BaseLsystem.py ├── Dragon curve.png ├── Dragon curve.py ├── Draw.sln ├── Koch曲线.png ├── Koch曲线.py ├── Lsystem21.png ├── Lsystem21.py ├── Lsystem22.png ├── Lsystem22.py ├── Lsystem23.png ├── Lsystem23.py ├── README.md ├── Sierpinski三角形.png ├── Sierpinski三角形.py ├── Sierpiński箭头曲线.png ├── Sierpiński箭头曲线.py ├── font.gif ├── lsystem24.png ├── lsystem24.py ├── lsystem25.png ├── lsystem25.py ├── requirements.txt ├── wordcloud ├── 1.txt ├── 2.jpg ├── 3.jpg ├── 3.png ├── 4.jpg ├── 4.png ├── 5.jpg ├── Draw.pyproj ├── __pycache__ │ └── wordcloud.cpython-36.pyc └── wordcloud.py ├── xm.py ├── yueliang.jpg ├── 个人名片.png ├── 个人名片.py ├── 二叉树.py ├── 优雅画一颗大树.gif ├── 优雅画树.gif ├── 优雅画树.png ├── 优雅画树.py ├── 分形4阶.png ├── 分形4阶.py ├── 如何优雅的画一颗大树(有详细注释).py ├── 如何优雅的画一颗大树.png ├── 小树.png ├── 小树.py ├── 希尔伯特曲线.png ├── 希尔伯特曲线.py ├── 康托尔集-深度大,相距间隔短..py ├── 康托尔集-深度大,相距间隔短.png ├── 文字.png ├── 文字.py ├── 月亮代表我的心.gif ├── 月亮代表我的心.py ├── 树干也要骚.png ├── 树干也要骚.py ├── 樱桃树.png ├── 樱桃树.py ├── 汉诺塔高级玩法.png ├── 汉诺塔高级玩法.py ├── 爱心挂满树.png ├── 爱心挂满树.py ├── 科赫雪花.png ├── 科赫雪花.py ├── 藤曼还是花蕾.png ├── 藤曼还是花蕾.py ├── 视觉3.py ├── 视觉冲击.png ├── 视觉冲击.py ├── 视觉冲击2.png ├── 视觉冲击2.py ├── 闪瞎你眼睛.png └── 闪瞎你眼睛.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | downloads/ 14 | eggs/ 15 | .eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | wheels/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | MANIFEST 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *.cover 46 | .hypothesis/ 47 | .pytest_cache/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | db.sqlite3 57 | 58 | # Flask stuff: 59 | instance/ 60 | .webassets-cache 61 | 62 | # Scrapy stuff: 63 | .scrapy 64 | 65 | # Sphinx documentation 66 | docs/_build/ 67 | 68 | # PyBuilder 69 | target/ 70 | 71 | # Jupyter Notebook 72 | .ipynb_checkpoints 73 | 74 | # pyenv 75 | .python-version 76 | 77 | # celery beat schedule file 78 | celerybeat-schedule 79 | 80 | # SageMath parsed files 81 | *.sage.py 82 | 83 | # Environments 84 | .env 85 | .venv 86 | env/ 87 | venv/ 88 | ENV/ 89 | env.bak/ 90 | venv.bak/ 91 | 92 | # Spyder project settings 93 | .spyderproject 94 | .spyproject 95 | 96 | # Rope project settings 97 | .ropeproject 98 | 99 | # mkdocs documentation 100 | /site 101 | 102 | # mypy 103 | .mypy_cache/ 104 | 105 | # mydir 106 | .idea/ -------------------------------------------------------------------------------- /Android_logo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import turtle 3 | 4 | aj = turtle.Pen() 5 | y = 0 6 | aj.speed(5) 7 | # turtle.screensize(200,800) 8 | turtle.bgcolor("black") 9 | 10 | 11 | # aj.shape("turtle") 12 | def head(): 13 | aj.color("green") 14 | aj.fd(160) 15 | x = aj.xcor() 16 | aj.seth(90) 17 | aj.begin_fill() 18 | # aj.color("green") 19 | aj.circle(x / 2, 180) 20 | aj.end_fill() 21 | aj.penup() 22 | aj.goto(33, 37) 23 | aj.pendown() 24 | aj.dot(13, "black") 25 | aj.penup() 26 | aj.goto(126, 37) 27 | aj.pendown() 28 | aj.dot(13, "black") 29 | aj.penup() 30 | aj.home() 31 | aj.pendown() 32 | aj.hideturtle() 33 | aj.fd(160) 34 | aj.seth(90) 35 | aj.circle(x / 2, 60) 36 | aj.right(90) 37 | aj.pensize(5) 38 | aj.fd(30) 39 | 40 | aj.penup() 41 | aj.home() 42 | # aj.pendown() 43 | aj.hideturtle() 44 | aj.fd(160) 45 | aj.seth(90) 46 | aj.circle(x / 2, 120) 47 | aj.right(90) 48 | aj.pensize(5) 49 | aj.pendown() 50 | aj.fd(30) 51 | aj.penup() 52 | aj.home() 53 | aj.penup() 54 | 55 | 56 | def body(): 57 | aj.pensize(0) 58 | 59 | aj.home() 60 | aj.showturtle() 61 | aj.goto(0, -7) 62 | aj.pendown() 63 | aj.begin_fill() 64 | aj.fd(160) 65 | aj.right(90) 66 | aj.fd(120) 67 | aj.right(90) 68 | aj.fd(160) 69 | y = aj.ycor() 70 | aj.right(90) 71 | aj.fd(120) 72 | aj.end_fill() 73 | 74 | 75 | def legs(): 76 | aj.penup() 77 | # turtle.color("red") 78 | aj.goto(33, -169) 79 | aj.pendown() 80 | aj.pensize(32) 81 | aj.fd(43) 82 | aj.penup() 83 | aj.goto(130, -169) 84 | aj.pendown() 85 | aj.fd(43) 86 | aj.penup() 87 | 88 | 89 | def hands(): 90 | aj.home() 91 | aj.pensize(30) 92 | aj.goto(-18, -77) 93 | aj.pendown() 94 | aj.left(90) 95 | aj.fd(65) 96 | aj.penup() 97 | aj.goto(179, -77) 98 | aj.pendown() 99 | aj.fd(65) 100 | aj.penup() 101 | aj.hideturtle 102 | aj.fd(100) 103 | aj.hideturtle() 104 | aj.circle(100) 105 | aj.circle(100, 360, 59) 106 | aj.reset() 107 | turtle.bgcolor("black") 108 | turtle.pencolor("green") 109 | turtle.hideturtle() 110 | turtle.goto(-300, 0) 111 | aj.hideturtle 112 | turtle.write("Thank you for watching....", font=("Bodoni MT Black", 28, "bold")) 113 | turtle.penup() 114 | turtle.goto(-40, -170) 115 | turtle.pendown() 116 | turtle.pencolor("yellow") 117 | turtle.write("Developed by Ajil Raju", font=("Palatino Linotype", 22, "bold")) 118 | 119 | 120 | head() 121 | body() 122 | legs() 123 | hands() 124 | turtle.done() 125 | -------------------------------------------------------------------------------- /BaseLsystem.py: -------------------------------------------------------------------------------- 1 | # !/usr/bin/python3 2 | # -*- coding: utf-8 -*- 3 | # Time : 2020/12/12 15:25 4 | # Author : Amd794 5 | # Email : 2952277346@qq.com 6 | # Github : https://github.com/Amd794 7 | # -*- coding: utf-8 -*- 8 | # Time : 2019/4/5 22:20 9 | # Author : Mifen 10 | # Email : 2952277346@qq.com 11 | # Github : https://github.com/Amd794 12 | 13 | 14 | import turtle as t 15 | 16 | 17 | class Pic(object): 18 | def __init__(self, 19 | init_path: str, 20 | rules: dict, 21 | angle: int, 22 | length: int = 5, 23 | deep: int = 5) -> None: 24 | t.setup(1280, 720) 25 | t.speed(0) 26 | t.pensize(1) 27 | self.deep = deep 28 | self.about_me() 29 | self.length = length 30 | self.init_path = init_path 31 | self.angle = angle 32 | self.rules = rules 33 | 34 | def about_me(self): 35 | t.up() 36 | t.color("#262626") 37 | t.goto(-600, 300) 38 | t.write('Author:Amd794', font=("微软雅黑", 18)) 39 | t.goto(-600, 250) 40 | t.write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 41 | t.goto(-600, 200) 42 | t.write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 43 | t.goto(-600, -350) 44 | t.down() 45 | 46 | def draw_path(self, apply_path): 47 | posList, angleList = [], [] 48 | t.up() 49 | t.goto(0, -350) 50 | t.down() 51 | t.lt(90) 52 | for symbol in apply_path: 53 | if symbol == 'F': 54 | t.forward(self.length) 55 | elif symbol == '+': 56 | t.left(self.angle) 57 | elif symbol == '-': 58 | t.rt(self.angle) 59 | elif symbol == '[': 60 | posList.append(t.pos()) 61 | angleList.append(t.heading()) 62 | elif symbol == 'a': 63 | t.pensize(3) 64 | t.color("#8c503c") 65 | elif symbol == 'b': 66 | t.pensize(2) 67 | t.color("#4ab441") 68 | elif symbol == 'c': 69 | t.pensize(2) 70 | t.color("#18b418") 71 | elif symbol == ']': 72 | t.up() 73 | t.home() 74 | t.goto(posList.pop()) 75 | t.left(angleList.pop()) 76 | t.down() 77 | 78 | def apply_rules(self): 79 | apply_path = self.init_path 80 | for k in range(self.deep): 81 | L = [_ for _ in apply_path] 82 | for i in range(len(L)): 83 | symbol = L[i] 84 | if symbol == 'F': 85 | L[i] = self.rules[symbol] 86 | if symbol == 'X': 87 | L[i] = self.rules[symbol] 88 | apply_path = ''.join(L) 89 | return apply_path 90 | 91 | 92 | if __name__ == '__main__': 93 | rules = { 94 | 'F': 'aFF-[b-F+F]+[c+F-F]', 95 | 'X': 'aFF+[b+F]+[c-F]' 96 | } 97 | angle = 25 98 | init_path = 'FX' 99 | p = Pic(init_path, rules, angle) 100 | apply_path = p.apply_rules() 101 | p.draw_path(apply_path) 102 | -------------------------------------------------------------------------------- /Dragon curve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/Dragon curve.png -------------------------------------------------------------------------------- /Dragon curve.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:18 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | from turtle import * 9 | length = 5 10 | angle = 90 11 | setup(1280,720) 12 | up() 13 | color("#262626;") 14 | goto(-600,300) 15 | write('Author:Mifen',font=("微软雅黑", 18)) 16 | goto(-600,250) 17 | write('E-mail :2952277346@qq.com',font=("微软雅黑", 18)) 18 | goto(-600, 200) 19 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 20 | goto(300,-100) 21 | 22 | down() 23 | def draw_path(path): 24 | for symbol in path: 25 | if symbol == 'f': 26 | import random 27 | colormode(255) 28 | color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 29 | fd(length) 30 | elif symbol == '-': 31 | lt(angle) 32 | elif symbol == '+': 33 | rt(angle) 34 | 35 | def apply_path(rules,path): 36 | lit = [x for x in path] 37 | for i in range(len(lit)): 38 | symbol = lit[i] 39 | if symbol == 'x': 40 | lit[i] = rules[symbol] 41 | elif symbol == 'y': 42 | lit[i] = rules[symbol] 43 | path = ''.join(lit) 44 | return path 45 | 46 | rules = { 47 | 'x':'x+yf+', 48 | 'y':'-fx-y' 49 | } 50 | path = 'fx' 51 | speed(0) 52 | for i in range(13): 53 | path = apply_path(rules,path) 54 | draw_path(path) 55 | done() -------------------------------------------------------------------------------- /Draw.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2026 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Draw", "Draw\Draw.pyproj", "{F7B2E50A-CA99-4B58-AFF8-6DFA5F506E1F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F7B2E50A-CA99-4B58-AFF8-6DFA5F506E1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F7B2E50A-CA99-4B58-AFF8-6DFA5F506E1F}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ExtensibilityGlobals) = postSolution 21 | SolutionGuid = {6CED62C0-435C-49F7-BE1A-7D80193475FE} 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /Koch曲线.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/Koch曲线.png -------------------------------------------------------------------------------- /Koch曲线.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:06 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | from turtle import * 8 | 9 | import random 10 | length = 2 11 | angle = 90 12 | setup(1280,720) 13 | up() 14 | color("#262626;") 15 | goto(-600,300) 16 | write('Author:Mifen',font=("微软雅黑", 18)) 17 | goto(-600,250) 18 | write('E-mail :2952277346@qq.com',font=("微软雅黑", 18)) 19 | goto(-600, 200) 20 | write('代码 :https://github.com/Amd794', font=("微软雅黑", 18)) 21 | goto(-600,-350) 22 | down() 23 | def draw_path(path): 24 | for symbol in path: 25 | if symbol == 'F': 26 | colormode(255) 27 | color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 28 | forward(length) 29 | elif symbol == '-': 30 | right(angle) 31 | elif symbol == '+': 32 | left(angle) 33 | ht() 34 | 35 | def apply_rule(path): 36 | rule = 'F+F-F-F+F' 37 | return path.replace('F',rule) 38 | 39 | path = 'F' 40 | speed(0) 41 | for i in range(5): 42 | path = apply_rule(path) 43 | for i in range(5): 44 | draw_path(path) 45 | up() 46 | goto(-478,-228) 47 | down() 48 | for i in range(4): 49 | draw_path(path) 50 | up() 51 | goto(-356,-106) 52 | down() 53 | for i in range(3): 54 | draw_path(path) 55 | up() 56 | goto(-235,16) 57 | down() 58 | for i in range(2): 59 | draw_path(path) 60 | up() 61 | goto(-115,137) 62 | down() 63 | draw_path(path) 64 | -------------------------------------------------------------------------------- /Lsystem21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/Lsystem21.png -------------------------------------------------------------------------------- /Lsystem21.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/6 16:25 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | import pathlib 8 | import sys 9 | 10 | sys.path.append(pathlib.Path()) 11 | from BaseLsystem import Pic 12 | 13 | angle = 90 14 | rules = { 15 | 'F': 'F+F-F-FF+F+F-F' # 转换规则 16 | } 17 | init_path = 'F+F+F+F' 18 | p = Pic(init_path, rules, angle, ) 19 | apply_path = p.apply_rules() 20 | p.draw_path(apply_path) 21 | -------------------------------------------------------------------------------- /Lsystem22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/Lsystem22.png -------------------------------------------------------------------------------- /Lsystem22.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/6 20:16 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle as t 9 | import random 10 | 11 | 12 | def draw_path(length, angle, path, expalnation): 13 | posList, angleList = [], [] 14 | 15 | for symbol in path: 16 | # print(expalnation[symbol]) 17 | if symbol == 'F': 18 | t.color(getColor(), getColor(), getColor()) 19 | t.forward(length) 20 | elif symbol == '+': 21 | t.left(angle) 22 | elif symbol == '-': 23 | t.rt(angle) 24 | elif symbol == '[': 25 | posList.append(t.pos()) 26 | angleList.append(t.heading()) 27 | elif symbol == 'a': 28 | t.pensize(4) 29 | t.color("#8c503c") 30 | elif symbol == 'b': 31 | t.color("#4ab441") 32 | t.pensize(3) 33 | elif symbol == 'c': 34 | t.pensize(2) 35 | t.color("#18b418") 36 | elif symbol == ']': 37 | t.up() 38 | t.home() 39 | t.goto(posList.pop()) 40 | t.left(angleList.pop()) 41 | t.down() 42 | 43 | 44 | def apply_rules(path, rules): 45 | L = [_ for _ in path] 46 | for i in range(len(L)): 47 | symbol = L[i] 48 | if symbol == 'F': 49 | L[i] = rules[symbol] 50 | path = ''.join(L) 51 | return path 52 | 53 | 54 | def getColor(): 55 | t.colormode(255) 56 | return random.randint(0, 255) 57 | 58 | 59 | def Introduction(x=-600, y=-350): 60 | t.up() 61 | t.color(getColor(), getColor(), getColor()) 62 | t.goto(-600, 300) 63 | t.write('Author:Mifen', font=("微软雅黑", 18)) 64 | t.goto(-600, 250) 65 | t.write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 66 | t.goto(-600, 200) 67 | t.write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 68 | t.goto(x, y) 69 | t.down() 70 | 71 | 72 | def initialization(): 73 | t.setup(1280, 720) 74 | t.bgcolor("black") 75 | t.speed(0) 76 | t.pensize(1) 77 | 78 | 79 | def run(n, angle, length, path, rules): 80 | initialization() 81 | Introduction(200, -100) 82 | expalnation = { 83 | 'F': '画线', 84 | 'x': '-', 85 | '+': '逆时针旋转', 86 | '-': '顺时针旋转', 87 | '[': '记录当前位置', 88 | ']': '恢复上一个位置', 89 | 'a': '上色', 90 | 'b': '上色', 91 | 'c': '上色' 92 | } 93 | for _ in range(n): 94 | path = apply_rules(path, rules) 95 | draw_path(length, angle, path, expalnation) 96 | t.done() 97 | 98 | 99 | if __name__ == '__main__': 100 | angle = 90 101 | length = 20 102 | path = 'F+F+F+F' # 初始路径 103 | rules = { 104 | 'F': 'FF+F-F+F+FF' # 转换规则 105 | } 106 | run(2, angle, length, path, rules) 107 | -------------------------------------------------------------------------------- /Lsystem23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/Lsystem23.png -------------------------------------------------------------------------------- /Lsystem23.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/6 20:16 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle as t 9 | import random 10 | 11 | 12 | def draw_path(length, angle, path, expalnation, lengthFactor): 13 | posList, angleList = [], [] 14 | 15 | for symbol in path: 16 | # print(expalnation[symbol]) 17 | if symbol == 'F': 18 | # t.color(getColor(), getColor(), getColor()) 19 | t.forward(length) 20 | elif symbol == '>': 21 | length = length * lengthFactor 22 | elif symbol == '<': 23 | length = length / lengthFactor 24 | elif symbol == '+': 25 | t.left(angle) 26 | elif symbol == '-': 27 | t.rt(angle) 28 | elif symbol == '[': 29 | posList.append(t.pos()) 30 | angleList.append(t.heading()) 31 | elif symbol == 'a': 32 | t.pensize(4) 33 | t.color("green") 34 | elif symbol == 'b': 35 | t.color("green") 36 | t.pensize(3) 37 | elif symbol == 'c': 38 | t.pensize(2) 39 | t.color("#18b418") 40 | elif symbol == ']': 41 | t.up() 42 | t.home() 43 | t.goto(posList.pop()) 44 | t.left(angleList.pop()) 45 | t.down() 46 | 47 | 48 | def apply_rules(path, rules): 49 | L = [_ for _ in path] 50 | for i in range(len(L)): 51 | symbol = L[i] 52 | characters = 'Fabxy' 53 | for character in characters: 54 | if symbol == character: 55 | L[i] = rules[symbol] 56 | path = ''.join(L) 57 | return path 58 | 59 | 60 | def getColor(): 61 | t.colormode(255) 62 | return random.randint(0, 255) 63 | 64 | 65 | def Introduction(x=-600, y=-350): 66 | t.up() 67 | t.color(getColor(), getColor(), getColor()) 68 | t.goto(-600, 300) 69 | t.write('Author:Mifen', font=("微软雅黑", 18)) 70 | t.goto(-600, 250) 71 | t.write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 72 | t.goto(-600, 200) 73 | t.write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 74 | t.color("black") 75 | t.goto(x, y) 76 | t.down() 77 | 78 | 79 | def initialization(): 80 | t.setup(1280, 720) 81 | t.bgcolor("grey") 82 | t.speed(0) 83 | t.pensize(1) 84 | 85 | 86 | def run(n, angle, length, path, rules, lengthFactor): 87 | initialization() 88 | Introduction(200, -300) 89 | expalnation = { 90 | 'F': '画线', 91 | 'x': '-', 92 | '+': '逆时针旋转', 93 | '-': '顺时针旋转', 94 | '[': '记录当前位置', 95 | ']': '恢复上一个位置', 96 | 'a': '上色', 97 | 'b': '上色', 98 | 'c': '上色', 99 | '>': '伸长', 100 | '<': '缩短', 101 | 'y': '-' 102 | } 103 | for _ in range(n): 104 | path = apply_rules(path, rules) 105 | draw_path(length, angle, path, expalnation, lengthFactor) 106 | t.done() 107 | 108 | 109 | if __name__ == '__main__': 110 | angle = 45 111 | length = 5 112 | lengthFactor = 1.36 113 | path = 'a' # 初始路径 114 | rules = { 115 | 'F': '>F<', # 转换规则 116 | 'a': 'F[+x]Fb', # 转换规则 117 | 'b': 'F[-y]Fa', # 转换规则 118 | 'x': 'a', # 转换规则 119 | 'y': 'b' # 转换规则 120 | } 121 | t.lt(90) 122 | run(12, angle, length, path, rules, lengthFactor) 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Python 海龟创意绘画 2 | =========================== 3 | 4 | [![瘦小的圆角矩形](https://img.shields.io/badge/More-Turtle-brightgreen.svg?style=plastic)](https://www.python123.io/index/turtles/colleges/%E5%B9%BF%E7%94%9F%E6%80%81 "python海龟创意绘画") 5 | [![瘦小的圆角矩形](https://img.shields.io/badge/Python-3.5|3.6|3.7-purple.svg?style=plastic)](https://github.com/Amd794/Python123) 6 | **** 7 | |Author|Mifen| 8 | |---|--- 9 | |Blog|[博客地址](https://blog.amd794.com/) 10 | **** 11 | # 演示 12 | ![](./font.gif) 13 | ![](./优雅画树.gif) 14 | ![](./月亮代表我的心.gif) 15 | ![](./%E4%BC%98%E9%9B%85%E7%94%BB%E4%B8%80%E9%A2%97%E5%A4%A7%E6%A0%91.gif) 16 | 17 | 18 | # Symbols The following characters have a geometric interpretation. 19 | |#|Character |Meaning| 20 | |---|----|-----| 21 | |1|`F`| Move forward by line length drawing a line| 22 | |2|`f `|Move forward by line length without drawing a line| 23 | |3|`+`|Turn left by turning angle| 24 | |4|`-`|Turn right by turning angle| 25 | |5|/|Reverse direction (ie: turn by 180 degrees)| 26 | |6|`[`|Push current drawing state onto stack| 27 | |7|`]`|Pop current drawing state from the stack| 28 | |8|`#`|Increment the line width by line width increment| 29 | |9|`!`| Decrement the line width by line width increment| 30 | |10|`@`| Draw a dot with line width radius| 31 | |11|`{`|Open a polygon| 32 | |12|`}`|Close a polygon and fill it with fill colour| 33 | |13|`<`| Multiply the line length by the line length scale factor| 34 | |14|`>`|Divide the line length by the line length scale factor| 35 | |15|`&`|Swap the meaning of + and -| 36 | |16|`(`|Decrement turning angle by turning angle increment| 37 | |17|`)`|Increment turning angle by turning angle increment| 38 | **** 39 | # 以下符号字符的几何解释。 40 | |#|字符 |含义| 41 | |---|----|-----| 42 | |1|`F`|按行绘制一条线向前移动| 43 | |2|`f `|按线条长度向前移动而不绘制线条| 44 | |3|`+`|通过转动角度向左转动| 45 | |4|`-`|通过转动角度向右转动| 46 | |5|/|反向(即:转动180度)| 47 | |6|`[`|将当前绘图状态推入堆栈| 48 | |7|`]`|从堆栈弹出当前绘图状态| 49 | |8|`#`|按线宽增量增加线宽| 50 | |9|`!`| 通过线宽增量减小线宽| 51 | |10|`@`| 绘制带有线宽半径的点 52 | |12|`}`|关闭多边形并用填充颜色填充 53 | |13|`<`| 将线长乘以线长比例因子| 54 | |14|`>`|将线长除以线长比例因子| 55 | |15|`&`|交换+和 - 的含义| 56 | |16|`(`|通过转动角度增量减小转动角度| 57 | |17|`)`|通过转动角度增量来增加转动角度 | 58 | |18|`{`|打开多边形| 59 | 60 | **** 61 | # 函数介绍 62 | * draw_path(length, angle, path, expalnation) 63 | * 主要用来绘制海龟行走路径 64 | * length ---->每次行走的距离 65 | * angle ---->偏移的角度 66 | * path ---->初始路径图案,即0阶的形状 67 | * expalnation ---->用来记录打印每一步操作 68 | * apply_rules(path, rules) 69 | * 主要是转换每一阶段的path 70 | * path ---->初始路径图案,即0阶的形状 71 | * rules ---->转换的规则 72 | * getColor() 73 | * 提供一个随机rgb值 74 | * initialization() 75 | * 初始化各种参数 76 | * Introduction(x=-600, y=-350) 77 | * 注解 78 | * 默认海龟初始位置(-600,-350) 79 | * run(n,angle,length,path,rules) 80 | * 启动程序 81 | -------------------------------------------------------------------------------- /Sierpinski三角形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/Sierpinski三角形.png -------------------------------------------------------------------------------- /Sierpinski三角形.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:14 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | from turtle import * 9 | length = 13 10 | angle = -120 11 | setup(1280,720) 12 | up() 13 | color("#262626;") 14 | goto(-600,300) 15 | write('Author:Mifen',font=("微软雅黑", 18)) 16 | goto(-600,250) 17 | write('E-mail :2952277346@qq.com',font=("微软雅黑", 16)) 18 | goto(-600, 200) 19 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 20 | goto(-640,-360) 21 | # home() 22 | down() 23 | def draw_path(path): 24 | for symbol in path: 25 | if symbol == 'A' or symbol == 'B': 26 | import random 27 | colormode(255) 28 | color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 29 | forward(length) 30 | elif symbol == '-': 31 | right(angle) 32 | elif symbol == '+': 33 | left(angle) 34 | ht() 35 | 36 | def apply_rules(path,rules): 37 | lit = [_ for _ in path] 38 | for i in range(len(lit)): 39 | symbol = lit[i] 40 | if symbol in rules: 41 | lit[i] = rules[symbol] 42 | path = ''.join(lit) 43 | return path 44 | 45 | 46 | rules = { 47 | 'A':'A-B+A+B-A', 48 | 'B':'BB' 49 | } 50 | path = 'A-B-B' 51 | speed(0) 52 | for i in range(6): 53 | path = apply_rules(path,rules) 54 | draw_path(path) 55 | angle = 120 56 | up() 57 | goto(640,360) 58 | down() 59 | draw_path(path) 60 | # for i in range(5): 61 | # goto(-640+100*i,-350) 62 | # draw_path(path) -------------------------------------------------------------------------------- /Sierpiński箭头曲线.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/Sierpiński箭头曲线.png -------------------------------------------------------------------------------- /Sierpiński箭头曲线.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:16 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | from turtle import * 8 | length = 5 9 | angle = -60 10 | setup(1280,720) 11 | up() 12 | color("#262626;") 13 | goto(-600,300) 14 | write('Author:Mifen',font=("微软雅黑", 18)) 15 | goto(-600,250) 16 | write('E-mail :2952277346@qq.com',font=("微软雅黑", 18)) 17 | goto(-600, 200) 18 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 19 | goto(-640,-350) 20 | down() 21 | def draw_path(path): 22 | for symbol in path: 23 | if symbol == 'A' or symbol == 'B': 24 | import random 25 | colormode(255) 26 | color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 27 | forward(length) 28 | elif symbol == '-': 29 | right(angle) 30 | elif symbol == '+': 31 | left(angle) 32 | ht() 33 | 34 | def apply_rules(path,rules): 35 | lit = [_ for _ in path] 36 | for i in range(len(lit)): 37 | symbol = lit[i] 38 | if symbol in rules: 39 | lit[i] = rules[symbol] 40 | path = ''.join(lit) 41 | return path 42 | 43 | 44 | rules = { 45 | 'A':'B-A-B', 46 | 'B':'A+B+A' 47 | } 48 | path = 'A' 49 | speed(0) 50 | for i in range(7): 51 | path = apply_rules(path,rules) 52 | draw_path(path) 53 | up() 54 | goto(0,-340) 55 | angle = 60 56 | down() 57 | draw_path(path) 58 | up() 59 | goto(0,-340) 60 | angle = -60 61 | down() 62 | draw_path(path) 63 | 64 | -------------------------------------------------------------------------------- /font.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/font.gif -------------------------------------------------------------------------------- /lsystem24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/lsystem24.png -------------------------------------------------------------------------------- /lsystem24.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/6 21:06 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle as t 9 | import random 10 | 11 | 12 | def draw_path(length, angle, path, expalnation, lengthFactor): 13 | posList, angleList = [], [] 14 | 15 | for symbol in path: 16 | # print(expalnation[symbol]) 17 | if symbol == 'F': 18 | # t.color(getColor(), getColor(), getColor()) 19 | t.forward(length) 20 | elif symbol == '>': 21 | length = length * lengthFactor 22 | elif symbol == '<': 23 | length = length / lengthFactor 24 | elif symbol == '+': 25 | t.left(angle) 26 | elif symbol == '-': 27 | t.rt(angle) 28 | elif symbol == '[': 29 | posList.append(t.pos()) 30 | angleList.append(t.heading()) 31 | elif symbol == 'a': 32 | t.pensize(4) 33 | t.color("green") 34 | elif symbol == 'b': 35 | t.color("green") 36 | t.pensize(3) 37 | elif symbol == 'c': 38 | t.pensize(2) 39 | t.color("#18b418") 40 | elif symbol == ']': 41 | t.up() 42 | t.home() 43 | t.goto(posList.pop()) 44 | t.left(angleList.pop()) 45 | t.down() 46 | 47 | 48 | def apply_rules(path, rules): 49 | L = [_ for _ in path] 50 | for i in range(len(L)): 51 | symbol = L[i] 52 | characters = 'xy' 53 | for character in characters: 54 | if symbol == character: 55 | L[i] = rules[symbol] 56 | path = ''.join(L) 57 | return path 58 | 59 | 60 | def getColor(): 61 | t.colormode(255) 62 | return random.randint(0, 255) 63 | 64 | 65 | def Introduction(x=-600, y=-350): 66 | t.up() 67 | t.color(getColor(), getColor(), getColor()) 68 | t.goto(-600, 300) 69 | t.write('Author:Mifen', font=("微软雅黑", 18)) 70 | t.goto(-600, 250) 71 | t.write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 72 | t.goto(-600, 200) 73 | t.write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 74 | t.color("black") 75 | t.goto(x, y) 76 | t.down() 77 | 78 | 79 | def initialization(): 80 | t.setup(1280, 720) 81 | t.bgcolor("grey") 82 | t.speed(0) 83 | t.pensize(1) 84 | 85 | 86 | def run(n, angle, length, path, rules, lengthFactor): 87 | initialization() 88 | Introduction(200, -300) 89 | expalnation = { 90 | 'F': '画线', 91 | 'x': '-', 92 | '+': '逆时针旋转', 93 | '-': '顺时针旋转', 94 | '[': '记录当前位置', 95 | ']': '恢复上一个位置', 96 | 'a': '上色', 97 | 'b': '上色', 98 | 'c': '上色', 99 | '>': '伸长', 100 | '<': '缩短', 101 | 'y': '-' 102 | } 103 | for _ in range(n): 104 | path = apply_rules(path, rules) 105 | print(path) 106 | draw_path(length, angle, path, expalnation, lengthFactor) 107 | t.done() 108 | 109 | 110 | if __name__ == '__main__': 111 | angle = 25.7 112 | length = 15 113 | lengthFactor = 1.36 114 | path = 'y' # 初始路径 115 | rules = { 116 | 'x': 'x[-FFF][+FFF]Fx', # 转换规则 117 | 'y': 'yFx[+y][-y]' # 转换规则 118 | } 119 | t.lt(90) 120 | run(5, angle, length, path, rules, lengthFactor) 121 | -------------------------------------------------------------------------------- /lsystem25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/lsystem25.png -------------------------------------------------------------------------------- /lsystem25.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/6 21:20 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle as t 9 | import random 10 | 11 | 12 | def draw_path(length, angle, path, expalnation, lengthFactor): 13 | posList, angleList = [], [] 14 | 15 | for symbol in path: 16 | # print(expalnation[symbol]) 17 | if symbol == 'F': 18 | t.color(getColor(), getColor(), getColor()) 19 | t.forward(length) 20 | elif symbol == '>': 21 | length = length * lengthFactor 22 | elif symbol == '<': 23 | length = length / lengthFactor 24 | elif symbol == '+': 25 | t.left(angle) 26 | elif symbol == '-': 27 | t.rt(angle) 28 | elif symbol == '[': 29 | posList.append(t.pos()) 30 | angleList.append(t.heading()) 31 | elif symbol == 'a': 32 | t.pensize(4) 33 | t.color("green") 34 | elif symbol == 'b': 35 | t.color("green") 36 | t.pensize(3) 37 | elif symbol == 'c': 38 | t.pensize(2) 39 | t.color("#18b418") 40 | elif symbol == ']': 41 | t.up() 42 | t.home() 43 | t.goto(posList.pop()) 44 | t.left(angleList.pop()) 45 | t.down() 46 | 47 | 48 | def apply_rules(path, rules): 49 | L = [_ for _ in path] 50 | for i in range(len(L)): 51 | symbol = L[i] 52 | characters = 'Fa' 53 | for character in characters: 54 | if symbol == character: 55 | try: 56 | L[i] = rules[symbol] 57 | except KeyError: 58 | continue 59 | path = ''.join(L) 60 | return path 61 | 62 | 63 | def getColor(): 64 | t.colormode(255) 65 | return random.randint(0, 255) 66 | 67 | 68 | def Introduction(x=-600, y=-350): 69 | t.up() 70 | t.color(getColor(), getColor(), getColor()) 71 | t.goto(-600, 300) 72 | t.write('Author:Mifen', font=("微软雅黑", 18)) 73 | t.goto(-600, 250) 74 | t.write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 75 | t.goto(-600, 200) 76 | t.write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 77 | t.color("black") 78 | t.goto(x, y) 79 | t.down() 80 | 81 | 82 | def initialization(): 83 | t.setup(1280, 720) 84 | t.bgcolor("grey") 85 | t.speed(0) 86 | t.pensize(1) 87 | 88 | 89 | def run(n, angle, length, path, rules, lengthFactor): 90 | initialization() 91 | Introduction(200, -300) 92 | expalnation = { 93 | 'F': '画线', 94 | 'x': '-', 95 | '+': '逆时针旋转', 96 | '-': '顺时针旋转', 97 | '[': '记录当前位置', 98 | ']': '恢复上一个位置', 99 | 'a': '上色', 100 | 'b': '上色', 101 | 'c': '上色', 102 | '>': '伸长', 103 | '<': '缩短', 104 | 'y': '-' 105 | } 106 | for _ in range(n): 107 | path = apply_rules(path, rules) 108 | print(path) 109 | draw_path(length, angle, path, expalnation, lengthFactor) 110 | t.done() 111 | 112 | 113 | if __name__ == '__main__': 114 | angle = 35 115 | length = 15 116 | lengthFactor = 1.36 117 | path = 'F' # 初始路径 118 | rules = { 119 | 'F': 'F[+FF][-FF]F[-F][+F]F' # 转换规则 120 | } 121 | t.lt(90) 122 | run(5, angle, length, path, rules, lengthFactor) 123 | 124 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/requirements.txt -------------------------------------------------------------------------------- /wordcloud/1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/1.txt -------------------------------------------------------------------------------- /wordcloud/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/2.jpg -------------------------------------------------------------------------------- /wordcloud/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/3.jpg -------------------------------------------------------------------------------- /wordcloud/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/3.png -------------------------------------------------------------------------------- /wordcloud/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/4.jpg -------------------------------------------------------------------------------- /wordcloud/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/4.png -------------------------------------------------------------------------------- /wordcloud/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/5.jpg -------------------------------------------------------------------------------- /wordcloud/Draw.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Debug 4 | 2.0 5 | f7b2e50a-ca99-4b58-aff8-6dfa5f506e1f 6 | . 7 | Draw.py 8 | 9 | 10 | . 11 | . 12 | Draw 13 | Draw 14 | 15 | 16 | true 17 | false 18 | 19 | 20 | true 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /wordcloud/__pycache__/wordcloud.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/wordcloud/__pycache__/wordcloud.cpython-36.pyc -------------------------------------------------------------------------------- /wordcloud/wordcloud.py: -------------------------------------------------------------------------------- 1 | import jieba # 词语切割 2 | import matplotlib 3 | import matplotlib.pyplot as plt # 数据可视化 4 | import numpy as np # 科学计算 5 | from PIL import Image # 处理图片 6 | 7 | from wordcloud import WordCloud, ImageColorGenerator, STOPWORDS # 词云,颜色生成器,停止 8 | 9 | 10 | def draw_photo(): 11 | matplotlib.rcParams['font.sans-serif'] = ['simhei'] # 配置字体,解决中文乱码问题 12 | # matplotlib.rcParams['font.family'] = 'sans-serif' 13 | 14 | # bar柱形图 15 | plt.bar([0], [1223], label='广东1', color='g') 16 | plt.bar([1], [31233], label='广东2', color='y') 17 | plt.bar([2], [11142], label='广东3', color='r') 18 | plt.bar([3], [21312], label='广东4', color='b') 19 | plt.bar([4], [22222], label='广东5', color='m') 20 | plt.bar([5], [55333], label='广东6') 21 | plt.bar([6], [45646], label='广东7', color='k') 22 | plt.legend() # 绘制 23 | plt.show() # 显示 24 | # plt.savefig('1.png')#保存 25 | 26 | 27 | def cut(): 28 | seg_list = jieba.cut("我来到北京清华大学", cut_all=True) 29 | print("Full Mode: " + "/ ".join(seg_list)) # 全模式 30 | 31 | seg_list = jieba.cut("我来到北京清华大学", cut_all=False) 32 | print("Default Mode: " + "/ ".join(seg_list)) # 精确模式 33 | 34 | seg_list = jieba.cut("他来到了网易杭研大厦") # 默认是精确模式 35 | print(", ".join(seg_list)) 36 | 37 | seg_list = jieba.cut_for_search("小明硕士毕业于中国科学院计算所,后在日本京都大学深造") # 搜索引擎模式 38 | print(", ".join(seg_list)) 39 | 40 | 41 | def ciyun(): 42 | # 打开文本 43 | textfile = open('1.txt').read() # 读取文本内容 44 | wordlist = jieba.cut_for_search(textfile) # 切割词语 45 | space_list = ' '.join(wordlist) # 链接词语 46 | backgroud = np.array(Image.open('2.jpg')) # 背景图片,只有黑白图才能按照形状生成词云 47 | mywordcloud = WordCloud(width=1400, height=1200, 48 | background_color='white', # 背景颜色 49 | mask=backgroud, # 写字用的背景图,从图片中提取颜色 50 | max_words=500, # 最大词语数 51 | stopwords=STOPWORDS, # 停止的默认词语 52 | font_path='simkai.ttf', # 源码自带字体 53 | max_font_size=100, # 最大字体尺寸 54 | random_state=50, # 随机角度 55 | scale=1).generate(space_list) # 生成词云 56 | image_color = ImageColorGenerator(backgroud) # 生成词云的颜色 57 | plt.imshow(mywordcloud) # 显示词云 58 | plt.axis('off') # 关闭坐标(x,y轴) 59 | # plt.savefig('4.png') #保存图片 60 | plt.show() # 显示 61 | 62 | 63 | def main(): 64 | ciyun() 65 | 66 | 67 | if __name__ == '__main__': 68 | main() 69 | -------------------------------------------------------------------------------- /xm.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | 3 | painter = turtle.Turtle() 4 | 5 | painter.pensize(3) 6 | painter.speed(1) 7 | 8 | 9 | #Draw face 10 | 11 | painter.color('black', 'black') 12 | painter.pendown() 13 | painter.circle(100) 14 | 15 | 16 | #Draw right ear 17 | 18 | painter.penup() 19 | painter.setx(50) 20 | painter.sety(185) 21 | painter.pendown() 22 | 23 | painter.begin_fill() 24 | painter.right(90) 25 | painter.circle(30, -260) 26 | painter.end_fill() 27 | 28 | 29 | #Draw left ear 30 | 31 | painter.penup() 32 | painter.setx(-50) 33 | painter.sety(185) 34 | painter.pendown() 35 | 36 | painter.left(170) 37 | painter.begin_fill() 38 | painter.right(90) 39 | painter.circle(30, 260) 40 | painter.end_fill() 41 | 42 | 43 | #Draw left eye 44 | 45 | painter.penup() 46 | painter.setx(-40) 47 | painter.sety(90) 48 | painter.pendown() 49 | 50 | painter.begin_fill() 51 | painter.circle(30) 52 | painter.end_fill() 53 | 54 | painter.left(10) 55 | painter.penup() 56 | painter.setx(-30) 57 | painter.sety(110) 58 | painter.pendown() 59 | 60 | painter.color('white', 'white') 61 | painter.begin_fill() 62 | painter.circle(15) 63 | painter.end_fill() 64 | 65 | painter.penup() 66 | painter.setx(-30) 67 | painter.sety(115) 68 | painter.pendown() 69 | 70 | painter.color('black', 'black') 71 | painter.begin_fill() 72 | painter.circle(5) 73 | painter.end_fill() 74 | 75 | 76 | #Draw right eye 77 | 78 | painter.penup() 79 | painter.setx(40) 80 | painter.sety(90) 81 | painter.pendown() 82 | 83 | painter.color('black', 'black') 84 | painter.begin_fill() 85 | painter.circle(30) 86 | painter.end_fill() 87 | 88 | painter.penup() 89 | painter.setx(30) 90 | painter.sety(110) 91 | painter.pendown() 92 | 93 | painter.color('white', 'white') 94 | painter.begin_fill() 95 | painter.circle(15) 96 | painter.end_fill() 97 | 98 | painter.penup() 99 | painter.setx(30) 100 | painter.sety(115) 101 | painter.pendown() 102 | 103 | painter.color('black', 'black') 104 | painter.begin_fill() 105 | painter.circle(5) 106 | painter.end_fill() 107 | 108 | 109 | #Draw mouth and nose 110 | 111 | painter.color('black', 'black') 112 | painter.penup() 113 | painter.setx(0) 114 | painter.sety(50) 115 | painter.pendown() 116 | 117 | painter.begin_fill() 118 | painter.circle(10) 119 | painter.end_fill() 120 | 121 | painter.right(90) 122 | painter.circle(20, 180) 123 | 124 | painter.penup() 125 | painter.setx(0) 126 | painter.sety(50) 127 | painter.pendown() 128 | 129 | painter.circle(20, -180) 130 | 131 | turtle.done() -------------------------------------------------------------------------------- /yueliang.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/yueliang.jpg -------------------------------------------------------------------------------- /个人名片.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/个人名片.png -------------------------------------------------------------------------------- /个人名片.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:42 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | from turtle import * 9 | import time 10 | 11 | angle = 60 #通过改变角度,绘制出各种多边形 12 | colormode(255) 13 | bgcolor(246, 246, 246) 14 | up() 15 | goto(-250,-150) 16 | down() 17 | pensize(.5) 18 | begin_fill() 19 | color(255,255,255) 20 | pencolor("grey") 21 | fd(500) 22 | lt(90) 23 | fd(250) 24 | lt(90) 25 | fd(500) 26 | lt(90) 27 | fd(250) 28 | lt(90) 29 | end_fill() 30 | up() 31 | goto(-235,60) 32 | color("#208fd7") 33 | write('Mifen',font=("微软雅黑", 18)) 34 | goto(-235,30) 35 | write('2952277346@qq.com',font=("微软雅黑", 8)) 36 | goto(-115,30) 37 | color("grey") 38 | write('|',font=("微软雅黑", 8)) 39 | color("#208fd7") 40 | goto(-105,30) 41 | write('https://github.com/Amd794/Python123',font=("微软雅黑", 8)) 42 | goto(-235,0) 43 | write('基本信息',font=("微软雅黑", 12)) 44 | goto(-235,-10) 45 | down() 46 | color("#64b5ec") 47 | fd(470) 48 | up() 49 | color("grey") 50 | goto(-235,-40) 51 | write('性别',font=("微软雅黑", 12)) 52 | goto(-235,-70) 53 | write('爱好',font=("微软雅黑", 12)) 54 | goto(-235,-100) 55 | write('技能',font=("微软雅黑", 12)) 56 | goto(-185,-40) 57 | down() 58 | def ipu(): 59 | begin_fill() 60 | color("#f1f1f1") 61 | fd(420) 62 | lt(90) 63 | fd(13) 64 | lt(90) 65 | fd(420) 66 | lt(90) 67 | fd(13) 68 | lt(90) 69 | end_fill() 70 | ipu() 71 | up() 72 | goto(-185,-70) 73 | down() 74 | ipu() 75 | up() 76 | goto(-185,-100) 77 | down() 78 | ipu() 79 | fd(200) 80 | ht() 81 | -------------------------------------------------------------------------------- /二叉树.py: -------------------------------------------------------------------------------- 1 | import turtle as t 2 | def tree(length,level): #树的层次 3 | if level <= 0: 4 | return 5 | t.forward(length) #前进方向画 length距离 6 | t.left(45) 7 | tree(0.6*length,level-1) 8 | t.right(90) 9 | tree(0.6*length,level-1) 10 | t.left(45) 11 | t.backward(length) 12 | return 13 | t.pensize(3) 14 | t.color('green') 15 | t.left(90) 16 | tree(100,6) 17 | -------------------------------------------------------------------------------- /优雅画一颗大树.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/优雅画一颗大树.gif -------------------------------------------------------------------------------- /优雅画树.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/优雅画树.gif -------------------------------------------------------------------------------- /优雅画树.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/优雅画树.png -------------------------------------------------------------------------------- /优雅画树.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:20 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import pathlib 9 | import sys 10 | 11 | sys.path.append(pathlib.Path()) 12 | from BaseLsystem import Pic 13 | 14 | rules = { 15 | 'F': 'aFF-[b-F+F]+[c+F-F]', 16 | 'X': 'aFF+[b+F]+[c-F]' 17 | } 18 | angle = 25 19 | init_path = 'FX' 20 | p = Pic(init_path, rules, angle) 21 | apply_path = p.apply_rules() 22 | p.draw_path(apply_path) 23 | -------------------------------------------------------------------------------- /分形4阶.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/分形4阶.png -------------------------------------------------------------------------------- /分形4阶.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:29 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | 9 | import time 10 | import turtle as t 11 | from turtle import * 12 | t.setup(1280,720) 13 | t.speed(0) 14 | t.pensize(1) 15 | length = 8 16 | path = 'F-F-F-F-F' 17 | angle = 72 18 | up() 19 | color("blue") 20 | goto(-600, 300) 21 | write('Author:Mifen', font=("微软雅黑", 18)) 22 | goto(-600, 250) 23 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 24 | goto(-600, 200) 25 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 26 | goto(-600, -350) 27 | down() 28 | expalnation = { 29 | 'F': '画线', 30 | 'x': '-', 31 | '+': '逆时针旋转', 32 | '-': '顺时针旋转', 33 | '[': '记录当前位置', 34 | ']': '恢复上一个位置', 35 | 'a': '上色', 36 | 'b': '上色', 37 | 'c': '上色' 38 | } 39 | rules = { 40 | 'F': 'F-F++F+F-F-F', 41 | 'X': 'aF-[b[X]+cX]+aF[c+FX]-X' 42 | } 43 | 44 | 45 | def draw_path(path, expalnation): 46 | posList, angleList = [], [] 47 | t.up() 48 | t.bgcolor("black") 49 | t.goto(400,0) 50 | t.down() 51 | t.lt(90) 52 | for symbol in path: 53 | if symbol == 'F': 54 | import random 55 | colormode(255) 56 | color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 57 | t.forward(length) 58 | elif symbol == '+': 59 | t.left(angle) 60 | elif symbol == '-': 61 | t.rt(angle) 62 | elif symbol == '[': 63 | posList.append(t.pos()) 64 | angleList.append(t.heading()) 65 | elif symbol == 'a': 66 | t.pensize(3) 67 | t.color("#8c503c") 68 | elif symbol == 'b': 69 | t.pensize(2) 70 | t.color("#4ab441") 71 | elif symbol == 'c': 72 | t.pensize(2) 73 | t.color("#18b418") 74 | elif symbol == ']': 75 | t.up() 76 | t.home() 77 | t.goto(posList.pop()) 78 | t.left(angleList.pop()) 79 | t.down() 80 | 81 | 82 | def apply_rules(path, rules): 83 | L = [_ for _ in path] 84 | for i in range(len(L)): 85 | symbol = L[i] 86 | if symbol == 'F': 87 | L[i] = rules[symbol] 88 | if symbol == 'X': 89 | L[i] = rules[symbol] 90 | path = ''.join(L) 91 | return path 92 | 93 | 94 | for _ in range(4): 95 | path = apply_rules(path, rules) 96 | draw_path(path, expalnation) -------------------------------------------------------------------------------- /如何优雅的画一颗大树(有详细注释).py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author : Mifen 3 | # Email : 2952277346@qq.com 4 | # Date : 2018/9/7 5 | 6 | 7 | import time 8 | import turtle as t 9 | from turtle import * 10 | 11 | t.setup(1280,720) 12 | t.speed(0) 13 | t.pensize(1) 14 | length = 13 15 | path = 'F' # 初始规则 16 | angle = 22 17 | up() 18 | color("#262626;") 19 | goto(-600,300) 20 | write('Author:Mifen',font=("微软雅黑", 18)) 21 | goto(-600,250) 22 | write('E-mail :2952277346@qq.com',font=("微软雅黑", 18)) 23 | goto(-600,-350) 24 | down() 25 | expalnation = { 26 | 'F':'画线', 27 | 'x':'-', 28 | '+':'逆时针旋转', 29 | '-':'顺时针旋转', 30 | '[':'记录当前位置', 31 | ']':'恢复上一个位置', 32 | 'a':'上色', 33 | 'b':'上色', 34 | 'c':'上色' 35 | } 36 | rules = { 37 | # 每一次迭代后 F 都将被替换为 aFF-[b-F+F+F]+[c+F-F-F] ==> 如: 初始为F --第一次迭代后-->aFF-[b-F+F+F]+[c+F-F-F] --第一次迭代后-->a aFF-[b-F+F+F]+[c+F-F-F] aFF-[b-F+F+F]+[c+F-F-F] -太长不写了 38 | 'F':'aFF-[b-F+F+F]+[c+F-F-F]' 39 | } 40 | 41 | 42 | def draw_path(path,expalnation): 43 | posList ,angleList= [],[] 44 | t.up() 45 | t.goto(0,-350) 46 | t.down() 47 | t.lt(90) 48 | for symbol in path: 49 | if symbol == 'F': 50 | t.forward(length) # 向前画出length长度 51 | elif symbol == '+': 52 | t.left(angle) # 向左边旋转出angle角度 53 | elif symbol == '-': 54 | t.rt(angle) # 向右边旋转出angle角度 55 | elif symbol == '[': 56 | posList.append(t.pos()) # 记录当前位置的坐标值,将当前的坐标值放到一个列表中 57 | angleList.append(t.heading()) # 记录当前位置的角度值,将当前的角度值放到一个列表中 58 | # abc分别代表树干 树枝和树叶的颜色 59 | elif symbol == 'a': 60 | t.pensize(4) 61 | t.color("#8c503c") 62 | elif symbol == 'b': 63 | t.color("#4ab441") 64 | t.pensize(3) 65 | elif symbol == 'c': 66 | t.pensize(2) 67 | t.color("#18b418") 68 | elif symbol == ']': 69 | t.up() 70 | t.home() 71 | t.goto(posList.pop()) # 复原最近添加的一个坐标值 72 | t.left(angleList.pop()) # 复原最近添加的一个角度值 73 | t.down() 74 | 75 | def apply_rules(path,rules): 76 | L = [_ for _ in path] 77 | for i in range(len(L)): 78 | symbol = L[i] 79 | if symbol == 'F': 80 | L[i] = rules[symbol] 81 | path = ''.join(L) 82 | return path 83 | 84 | 85 | for _ in range(4): 86 | path = apply_rules(path,rules) # 获取迭代4此后的最总规则, 一串很长的字符串 87 | draw_path(path,expalnation) # 开始绘画 88 | 89 | -------------------------------------------------------------------------------- /如何优雅的画一颗大树.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/如何优雅的画一颗大树.png -------------------------------------------------------------------------------- /小树.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/小树.png -------------------------------------------------------------------------------- /小树.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:27 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import time 9 | import turtle as t 10 | from turtle import * 11 | t.setup(1280,720) 12 | t.speed(0) 13 | t.pensize(1) 14 | length = 3 15 | path = 'X' 16 | angle = 25 17 | up() 18 | color("#262626;") 19 | goto(-600, 300) 20 | write('Author:Mifen', font=("微软雅黑", 18)) 21 | goto(-600, 250) 22 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 23 | goto(-600, 200) 24 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 25 | goto(-600, -350) 26 | down() 27 | expalnation = { 28 | 'F': '画线', 29 | 'x': '-', 30 | '+': '逆时针旋转', 31 | '-': '顺时针旋转', 32 | '[': '记录当前位置', 33 | ']': '恢复上一个位置', 34 | 'a': '上色', 35 | 'b': '上色', 36 | 'c': '上色' 37 | } 38 | rules = { 39 | 'F': 'FF', 40 | 'X': 'aF-[b[X]+cX]+aF[c+FX]-X' 41 | } 42 | 43 | 44 | def draw_path(path, expalnation): 45 | posList, angleList = [], [] 46 | t.up() 47 | t.goto(0, -350) 48 | t.down() 49 | t.lt(90) 50 | for symbol in path: 51 | if symbol == 'F': 52 | t.forward(length) 53 | elif symbol == '+': 54 | t.left(angle) 55 | elif symbol == '-': 56 | t.rt(angle) 57 | elif symbol == '[': 58 | posList.append(t.pos()) 59 | angleList.append(t.heading()) 60 | elif symbol == 'a': 61 | t.pensize(3) 62 | t.color("#8c503c") 63 | elif symbol == 'b': 64 | t.pensize(2) 65 | t.color("#4ab441") 66 | elif symbol == 'c': 67 | t.pensize(2) 68 | t.color("#18b418") 69 | elif symbol == ']': 70 | t.up() 71 | t.home() 72 | t.goto(posList.pop()) 73 | t.left(angleList.pop()) 74 | t.down() 75 | 76 | 77 | def apply_rules(path, rules): 78 | L = [_ for _ in path] 79 | for i in range(len(L)): 80 | symbol = L[i] 81 | if symbol == 'F': 82 | L[i] = rules[symbol] 83 | if symbol == 'X': 84 | L[i] = rules[symbol] 85 | path = ''.join(L) 86 | return path 87 | 88 | 89 | for _ in range(6): 90 | path = apply_rules(path, rules) 91 | draw_path(path, expalnation) 92 | -------------------------------------------------------------------------------- /希尔伯特曲线.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/希尔伯特曲线.png -------------------------------------------------------------------------------- /希尔伯特曲线.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:12 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | from turtle import * 8 | import random 9 | length = 10 10 | angle = 90 11 | setup(1280,720) 12 | up() 13 | color("#262626;") 14 | goto(-600,300) 15 | write('Author:Mifen',font=("微软雅黑", 18)) 16 | goto(-600,250) 17 | write('E-mail :2952277346@qq.com',font=("微软雅黑", 18)) 18 | goto(-600, 200) 19 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 20 | goto(-640,-360) 21 | down() 22 | def draw_path(path): 23 | for symbol in path: 24 | if symbol == 'f': 25 | colormode(255) 26 | color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 27 | fd(length) 28 | elif symbol == '+': 29 | lt(angle) 30 | elif symbol == '-': 31 | rt(angle) 32 | 33 | def apply_path(rules,path): 34 | lit = [x for x in path] 35 | for i in range(len(lit)): 36 | symbol = lit[i] 37 | if symbol == 'x': 38 | lit[i] = rules[symbol] 39 | elif symbol == 'y': 40 | lit[i] = rules[symbol] 41 | path = ''.join(lit) 42 | return path 43 | 44 | rules = { 45 | 'x':'+yf-xfx-fy+', 46 | 'y':'-xf+yfy+fx-' 47 | } 48 | path = 'x' 49 | speed(0) 50 | for i in range(7): 51 | path = apply_path(rules,path) 52 | draw_path(path) 53 | done() -------------------------------------------------------------------------------- /康托尔集-深度大,相距间隔短..py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 17:57 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Software: PyCharm 6 | 7 | from turtle import * 8 | import random 9 | length = 1000 10 | setup(1280,720) 11 | up() 12 | color("#0fe6ca") 13 | goto(-600, 300) 14 | write('Author:Mifen', font=("微软雅黑", 18)) 15 | goto(-600, 250) 16 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 17 | goto(0,0) 18 | down() 19 | def draw_path(path,y): 20 | up() 21 | goto(-500,200) 22 | sety(-y) 23 | down() 24 | pensize(2) 25 | colormode(255) 26 | color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) 27 | for symbol in path: 28 | if symbol == 'A': 29 | fd(length/len(path)) 30 | elif symbol == 'B': 31 | up() 32 | fd(length/len(path)) 33 | down() 34 | ht() 35 | def apply_path(rules,path): 36 | lit = [_ for _ in path] 37 | for i in range(len(lit)): 38 | symbol = lit[i] 39 | if symbol in rules: 40 | lit[i] = rules[symbol] 41 | path = ''.join(lit) 42 | return path 43 | path = 'A' 44 | rules = { 45 | 'A':'ABA', 46 | 'B':'BBB' 47 | } 48 | speed(0) 49 | path_list = ['A'] 50 | n = 8 51 | for i in range(n): 52 | path = apply_path(rules, path) 53 | path_list.append(path) 54 | for y in range(0,n*10,10): 55 | draw_path(path_list.pop(0),y) 56 | exitonclick() -------------------------------------------------------------------------------- /康托尔集-深度大,相距间隔短.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/康托尔集-深度大,相距间隔短.png -------------------------------------------------------------------------------- /文字.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/文字.png -------------------------------------------------------------------------------- /文字.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:44 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | from turtle import * 9 | import random 10 | import time 11 | 12 | str_ = """ 13 | 守一段情 念一个人。 14 | 时光不老 我们不散。 15 | 厮守终生 不离不弃。 16 | 天暗下来 你就是光。 17 | 亡魂溺海 止于终老。 18 | 生死挈阔 与子成说。 19 | 柔情似水 佳期如梦。 20 | 我中有你 你中有我。 21 | 青山不老 为雪白头。 22 | 心若向阳 无畏悲伤。 23 | 一人一心 白首不离。 24 | 心如荒岛 囚我终老。 25 | 我的世界 只有你懂。 26 | 你若安好 便是晴天。 27 | 心有灵犀 一点就通。 28 | 厮守海角 非你不娶。 29 | 执子的手 漫漫的走。 30 | 执子之手 与子偕老。 31 | 山河拱手 为君一笑。 32 | 红尘初妆 山河无疆。 33 | 千秋功名 一世葬你。 34 | 既不回头 何必不忘。 35 | 既然无缘 何须誓言。 36 | 今日种种 似水无痕。 37 | 明夕何夕 君已陌路。 38 | 才会相思 便害相思。 39 | 人来人往 繁华似锦。 40 | 回首万年 情衷伊人。 41 | 生能尽欢 死亦无憾。 42 | 执手若无 泪溅花上。 43 | 花开花落 人世无常。 44 | 入我心者 待以君王。 45 | 为醉而醉 似醉非醉。 46 | 伤心鸿影 爱已惘然。 47 | 只要你要 只要我有。 48 | 日久生情 日久情疏。 49 | 忧佳相随 风雨无悔。 50 | 有生之年 誓死娇宠 51 | 引喻山河 指日可诚。 52 | 水上鸳鸯 云中翡翠。 53 | 天荒地老 海誓山盟。 54 | 生则同襟 死则同穴。 55 | 生有此女 夫复何求""".split("。") 56 | setup(1280,720) # 设置窗口大小 57 | colormode(255) # 使用的颜色模式, 整数还是小数 58 | up() 59 | a, b = -500, 280 60 | goto(a,b) 61 | bgcolor("black") 62 | 63 | 64 | down() 65 | def w(str_,b): 66 | bgcolor( random.randint(0,255),random.randint(0,255),random.randint(0,255)) # 随机生成RGB值, 每次调用函数改变背景颜色 67 | for i in range(len(str_)): 68 | up() 69 | goto(a+100*i,b) 70 | down() 71 | size = random.randint(12,68) # 随机字体大小 72 | color( random.randint(0,255),random.randint(0,255),random.randint(0,255)) # 随机字体颜色 73 | write(str_[i], align="center",font=("楷体",size)) 74 | 75 | 76 | for k in range(4): 77 | for i in range(7): 78 | w(str_[i+7*k],b-100*i) 79 | reset() # 清屏 80 | 81 | 82 | for i in range(7): 83 | w(str_[i+7*4],b-100*i) 84 | up() 85 | color("#262626;") 86 | goto(-600,300) 87 | write('Author:Mifen',font=("微软雅黑", 18)) 88 | goto(-600,250) 89 | write('E-mail :2952277346@qq.com',font=("微软雅黑", 18)) 90 | goto(-600, 200) 91 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 92 | goto(-600,-350) 93 | down() 94 | ht() 95 | -------------------------------------------------------------------------------- /月亮代表我的心.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/月亮代表我的心.gif -------------------------------------------------------------------------------- /月亮代表我的心.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/6 22:45 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | from turtle import * 9 | import time 10 | import turtle as t 11 | 12 | 13 | def gotopos(x, y): 14 | up() 15 | goto(x, y) 16 | down() 17 | ht() 18 | 19 | 20 | def author(): 21 | pensize(2) 22 | gotopos(610, -315) 23 | lt(-90) 24 | fd(80) 25 | pensize(1) 26 | lt(-270) 27 | gotopos(525, -330) 28 | color("#772a2b") 29 | write("Mifen", font=("华文隶书", 24)) 30 | gotopos(409, -360) 31 | write("2952277346@qq.com", font=("华文隶书", 18)) 32 | gotopos(250, -390) 33 | write("https://github.com/Amd794/Python123", font=("华文隶书", 18)) 34 | 35 | 36 | def apply_rules(path, rules): 37 | L = [_ for _ in path] 38 | for i in range(len(L)): 39 | symbol = L[i] 40 | if symbol == 'F': 41 | L[i] = rules[symbol] 42 | if symbol == 'X': 43 | L[i] = rules[symbol] 44 | path = ''.join(L) 45 | return path 46 | 47 | 48 | def draw_path(path): 49 | posList, angleList = [], [] 50 | for symbol in path: 51 | if symbol == 'F': 52 | t.forward(length) 53 | elif symbol == '+': 54 | t.left(angle) 55 | elif symbol == '-': 56 | t.rt(angle) 57 | elif symbol == '[': 58 | posList.append(t.pos()) 59 | angleList.append(t.heading()) 60 | elif symbol == 'a': 61 | t.pensize(3) 62 | t.color("#867b68") 63 | elif symbol == 'b': 64 | t.pensize(2) 65 | t.color("#867b68") 66 | elif symbol == 'c': 67 | t.pensize(2) 68 | t.color("#867b68") 69 | elif symbol == ']': 70 | t.up() 71 | t.home() 72 | t.goto(posList.pop()) 73 | t.left(angleList.pop()) 74 | t.down() 75 | 76 | 77 | def writez(x, y, str_, size=56, font="华文行楷"): 78 | gotopos(x, y) 79 | write(str_, font=(font, size)) 80 | 81 | 82 | setup(1280, 800) 83 | speed(5) 84 | bgcolor("#9c917f") 85 | color("#afa697") 86 | begin_fill() 87 | gotopos(0, -400) 88 | circle(400) 89 | end_fill() 90 | author() 91 | color("#7d776d") 92 | s = "愿天化作比翼鸟" 93 | s2 = "在地愿为连理枝" 94 | for i in range(len(s)): 95 | writez(560, 350 - i * 50, s[i], 36) 96 | for i in range(len(s2)): 97 | writez(460, 350 - i * 50, s2[i], 36) 98 | color("#888475") 99 | writez(-50, 100, "我") 100 | writez(-50, 40, "的") 101 | writez(-160, 0, "心", 96) 102 | writez(-50, 0, "月", 176) 103 | writez(33, -30, "代", 62) 104 | writez(-18, -95, "表", 78) 105 | writez(-213, -210, "亮", 196) 106 | 107 | gotopos(249, -26) 108 | color("#867b68") 109 | speed(0) 110 | gotopos(-650, -100) 111 | length = 6 112 | path = 'F' 113 | angle = 27 114 | rules = { 115 | 'F': 'aFF[b-F++F][c+F--F]c++F--F', 116 | 'X': 'aFF+[b+F]+[c-F]' 117 | } 118 | 119 | for _ in range(4): 120 | path = apply_rules(path, rules) 121 | draw_path(path) 122 | gotopos(570, -330) 123 | done() 124 | -------------------------------------------------------------------------------- /树干也要骚.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/树干也要骚.png -------------------------------------------------------------------------------- /树干也要骚.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:38 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle 9 | 10 | toplevel = 6 # 一共递归6层 11 | angle = 30 12 | 13 | 14 | def drawTree(length, level): 15 | turtle.left(angle) # 绘制左枝 16 | turtle.forward(length) 17 | 18 | if level < toplevel: # 在左枝退回去之前递归 19 | drawTree(length - 10, level + 1) 20 | turtle.back(length) 21 | 22 | turtle.right(angle * 2) # 绘制右枝 23 | turtle.forward(length) 24 | 25 | if level < toplevel: # 在右枝退回去之前递归 26 | drawTree(length - 10, level + 1) 27 | turtle.back(length) 28 | turtle.left(angle) 29 | 30 | turtle.speed(1) 31 | turtle.tracer(0) # 不刷新 32 | turtle.left(90) 33 | drawTree(80, 1) 34 | turtle.update() # 刷新,和上面的tracer(0)配合,直接出图形,忽略过程 35 | 36 | turtle.done() -------------------------------------------------------------------------------- /樱桃树.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/樱桃树.png -------------------------------------------------------------------------------- /樱桃树.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:39 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | import turtle 8 | 9 | toplevel = 8 # 一共递归6层 10 | angle = 30 11 | rangle = 15 12 | 13 | 14 | def drawTree(length, level): 15 | turtle.left(angle) # 绘制左枝 16 | turtle.color("black") 17 | turtle.forward(length) 18 | 19 | if level == toplevel: # 叶子 20 | turtle.color("pink") 21 | turtle.circle(2, 360) 22 | 23 | if level < toplevel: # 在左枝退回去之前递归 24 | drawTree(length - 10, level + 1) 25 | turtle.back(length) 26 | 27 | turtle.right(angle + rangle) # 绘制右枝 28 | turtle.color("black") 29 | turtle.forward(length) 30 | 31 | if level == toplevel: # 叶子 32 | turtle.color("pink") 33 | turtle.circle(2, 360) 34 | 35 | if level < toplevel: # 在右枝退回去之前递归 36 | drawTree(length - 10, level + 1) 37 | turtle.color("black") 38 | turtle.back(length) 39 | turtle.left(rangle) 40 | 41 | 42 | turtle.left(90) 43 | turtle.penup() 44 | turtle.back(300) 45 | turtle.pendown() 46 | turtle.forward(100) 47 | turtle.speed('fastest') 48 | drawTree(80, 1) 49 | 50 | turtle.done() 51 | -------------------------------------------------------------------------------- /汉诺塔高级玩法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/汉诺塔高级玩法.png -------------------------------------------------------------------------------- /汉诺塔高级玩法.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:35 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle 9 | 10 | 11 | class Stack: 12 | def __init__(self): 13 | self.items = [] 14 | 15 | def isEmpty(self): 16 | return len(self.items) == 0 17 | 18 | def push(self, item): 19 | self.items.append(item) 20 | 21 | def pop(self): 22 | return self.items.pop() 23 | 24 | def peek(self): 25 | if not self.isEmpty(): 26 | return self.items[len(self.items) - 1] 27 | 28 | def size(self): 29 | return len(self.items) 30 | 31 | 32 | def drawpole_3(): # 画出汉诺塔的poles 33 | t = turtle.Turtle() 34 | t.hideturtle() 35 | 36 | def drawpole_1(k): 37 | t.up() 38 | t.pensize(10) 39 | t.speed(100) 40 | t.goto(400 * (k - 1), 100) 41 | t.down() 42 | t.goto(400 * (k - 1), -100) 43 | t.goto(400 * (k - 1) - 20, -100) 44 | t.goto(400 * (k - 1) + 20, -100) 45 | 46 | drawpole_1(0) # 画出汉诺塔的poles[0] 47 | drawpole_1(1) # 画出汉诺塔的poles[1] 48 | drawpole_1(2) # 画出汉诺塔的poles[2] 49 | 50 | 51 | def creat_plates(n): # 制造n个盘子 52 | turtle.colormode(255) 53 | plates = [turtle.Turtle() for i in range(n)] 54 | for i in range(n): 55 | plates[i].up() 56 | plates[i].hideturtle() 57 | plates[i].shape("square") 58 | import random 59 | plates[i].pencolor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) 60 | plates[i].fillcolor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) 61 | # plates[i].shape(1,8-i) 62 | plates[i].goto(-400, -90 + 20 * i) 63 | plates[i].showturtle() 64 | return plates 65 | 66 | 67 | def pole_stack(): # 制造poles的栈 68 | poles = [Stack() for i in range(3)] 69 | return poles 70 | 71 | 72 | def moveDisk(plates, poles, fp, tp): # 把poles[fp]顶端的盘子plates[mov]从poles[fp]移到poles[tp] 73 | mov = poles[fp].peek() 74 | plates[mov].goto((fp - 1) * 400, 150) 75 | plates[mov].goto((tp - 1) * 400, 150) 76 | l = poles[tp].size() # 确定移动到底部的高度(恰好放在原来最上面的盘子上面) 77 | plates[mov].goto((tp - 1) * 400, -90 + 20 * l) 78 | 79 | 80 | def moveTower(plates, poles, height, fromPole, toPole, withPole): # 递归放盘子 81 | if height >= 1: 82 | moveTower(plates, poles, height - 1, fromPole, withPole, toPole) 83 | moveDisk(plates, poles, fromPole, toPole) 84 | poles[toPole].push(poles[fromPole].pop()) 85 | moveTower(plates, poles, height - 1, withPole, toPole, fromPole) 86 | 87 | 88 | myscreen = turtle.Screen() 89 | drawpole_3() 90 | n = 8 91 | plates = creat_plates(n) 92 | poles = pole_stack() 93 | for i in range(n): 94 | poles[0].push(i) 95 | moveTower(plates, poles, n, 0, 2, 1) 96 | myscreen.exitonclick() 97 | -------------------------------------------------------------------------------- /爱心挂满树.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/爱心挂满树.png -------------------------------------------------------------------------------- /爱心挂满树.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:37 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle 9 | import random 10 | 11 | turtle.bgcolor("black") 12 | 13 | 14 | def love(x, y): # 在(x,y)处画爱心lalala 15 | lv = turtle.Turtle() 16 | lv.hideturtle() 17 | lv.up() 18 | lv.goto(x, y) # 定位到(x,y) 19 | 20 | def curvemove(): # 画圆弧 21 | for i in range(20): 22 | lv.right(10) 23 | lv.forward(2) 24 | 25 | lv.color('red', 'pink') 26 | lv.speed(10000000) 27 | lv.pensize(1) 28 | # 开始画爱心lalala 29 | lv.down() 30 | lv.begin_fill() 31 | lv.left(140) 32 | lv.forward(22) 33 | curvemove() 34 | lv.left(120) 35 | curvemove() 36 | lv.forward(22) 37 | lv.left(140) # 画完复位 38 | lv.end_fill() 39 | 40 | 41 | def tree(branchLen, t): 42 | if branchLen > 5: # 剩余树枝太少要结束递归 43 | if branchLen < 20: # 如果树枝剩余长度较短则变绿 44 | t.color("green") 45 | t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5)) 46 | t.down() 47 | t.forward(branchLen) 48 | love(t.xcor(), t.ycor()) # 传输现在turtle的坐标 49 | t.up() 50 | t.backward(branchLen) 51 | t.color("brown") 52 | return 53 | t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5)) 54 | t.down() 55 | t.forward(branchLen) 56 | # 以下递归 57 | ang = random.uniform(15, 45) 58 | t.right(ang) 59 | tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度 60 | t.left(2 * ang) 61 | tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度 62 | t.right(ang) 63 | t.up() 64 | t.backward(branchLen) 65 | 66 | 67 | myWin = turtle.Screen() 68 | t = turtle.Turtle() 69 | t.hideturtle() 70 | t.speed(1000) 71 | t.left(90) 72 | t.up() 73 | t.backward(200) 74 | t.down() 75 | t.color("brown") 76 | t.pensize(32) 77 | t.forward(60) 78 | tree(100, t) -------------------------------------------------------------------------------- /科赫雪花.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/科赫雪花.png -------------------------------------------------------------------------------- /科赫雪花.py: -------------------------------------------------------------------------------- 1 | import turtle as t 2 | from turtle import * 3 | import random 4 | 5 | 6 | 7 | def draw_path(path): 8 | t.colormode(255) 9 | t.color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 10 | for symbol in path: 11 | if symbol == 'F': 12 | forward(length) 13 | elif symbol == '-': 14 | right(angle) 15 | elif symbol == '+': 16 | left(angle) 17 | 18 | def apply_rule(path): 19 | rule = 'F+F--F+F' 20 | return path.replace('F',rule) 21 | 22 | length = .5 23 | angle = 60 24 | setup(1280,720) 25 | bgcolor('black') 26 | up() 27 | color("#0fe6ca") 28 | goto(-600, 300) 29 | write('Author:Mifen', font=("微软雅黑", 18)) 30 | goto(-600, 250) 31 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 32 | goto(0,0) 33 | down() 34 | path = 'F--F--F' 35 | speed(0) 36 | up() 37 | goto(-440,-250) 38 | down() 39 | for i in range(5): 40 | path = apply_rule(path) 41 | draw_path(path) 42 | draw_path(path) 43 | draw_path(path) 44 | a,b = pos() 45 | for i in range(3): 46 | up() 47 | a += 250 48 | goto(a,b) 49 | down() 50 | draw_path(path) 51 | draw_path(path) 52 | draw_path(path) 53 | b += 220 54 | for i in range(2): 55 | up() 56 | a -= 250 57 | goto(a,b) 58 | down() 59 | draw_path(path) 60 | draw_path(path) 61 | draw_path(path) 62 | b += 220 63 | for i in range(2): 64 | 65 | draw_path(path) 66 | draw_path(path) 67 | draw_path(path) 68 | up() 69 | a += 130 70 | goto(a,b) 71 | down() 72 | -------------------------------------------------------------------------------- /藤曼还是花蕾.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/藤曼还是花蕾.png -------------------------------------------------------------------------------- /藤曼还是花蕾.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:25 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | 9 | 10 | import time 11 | import turtle as t 12 | from turtle import * 13 | t.setup(1280,720) 14 | t.speed(0) 15 | t.pensize(1) 16 | length = 6 17 | path = 'F' 18 | angle = 27 19 | up() 20 | color("#262626;") 21 | goto(-600, 300) 22 | write('Author:Mifen', font=("微软雅黑", 18)) 23 | goto(-600, 250) 24 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 25 | goto(-600, 200) 26 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 27 | goto(-600, -350) 28 | down() 29 | expalnation = { 30 | 'F': '画线', 31 | 'x': '-', 32 | '+': '逆时针旋转', 33 | '-': '顺时针旋转', 34 | '[': '记录当前位置', 35 | ']': '恢复上一个位置', 36 | 'a': '上色', 37 | 'b': '上色', 38 | 'c': '上色' 39 | } 40 | rules = { 41 | 'F': 'aFF[b-F++F][c+F--F]c++F--F', 42 | 'X': 'aFF+[b+F]+[c-F]' 43 | } 44 | 45 | 46 | def draw_path(path, expalnation): 47 | posList, angleList = [], [] 48 | t.up() 49 | t.goto(600, -350) 50 | t.down() 51 | t.lt(90) 52 | for symbol in path: 53 | if symbol == 'F': 54 | t.forward(length) 55 | elif symbol == '+': 56 | t.left(angle) 57 | elif symbol == '-': 58 | t.rt(angle) 59 | elif symbol == '[': 60 | posList.append(t.pos()) 61 | angleList.append(t.heading()) 62 | elif symbol == 'a': 63 | t.pensize(3) 64 | t.color("#8c503c") 65 | elif symbol == 'b': 66 | t.pensize(2) 67 | t.color("#4ab441") 68 | elif symbol == 'c': 69 | t.pensize(2) 70 | t.color("#18b418") 71 | elif symbol == ']': 72 | t.up() 73 | t.home() 74 | t.goto(posList.pop()) 75 | t.left(angleList.pop()) 76 | t.down() 77 | 78 | 79 | def apply_rules(path, rules): 80 | L = [_ for _ in path] 81 | for i in range(len(L)): 82 | symbol = L[i] 83 | if symbol == 'F': 84 | L[i] = rules[symbol] 85 | if symbol == 'X': 86 | L[i] = rules[symbol] 87 | path = ''.join(L) 88 | return path 89 | 90 | 91 | for _ in range(4): 92 | path = apply_rules(path, rules) 93 | draw_path(path, expalnation) -------------------------------------------------------------------------------- /视觉3.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | import time 3 | 4 | speed(0) 5 | colormode(255) 6 | clrs = ["MidnightBlue", "Navy", "DarkBlue", "MediumBlue", "RoyalBlue", "MediumSlateBlue", "CornflowerBlue", 7 | "DodgerBlue", "DeepskyBlue", "LightSkyBlue", "SkyBlue", "LightBlue"] 8 | 9 | time.sleep(2) 10 | 11 | for j in range(120): 12 | 13 | cn = 0 14 | c = 30 15 | f = 70 16 | 17 | for i in range(12): 18 | pencolor(clrs[cn]) 19 | circle(c) 20 | left(90) 21 | penup() 22 | forward(f) 23 | right(90) 24 | pendown() 25 | c = c * 0.8 26 | f = f * 0.8 27 | circle(c) 28 | cn = cn + 1 29 | 30 | penup() 31 | goto(0, 0) 32 | forward(5) 33 | right(3) 34 | pendown() -------------------------------------------------------------------------------- /视觉冲击.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/视觉冲击.png -------------------------------------------------------------------------------- /视觉冲击.py: -------------------------------------------------------------------------------- 1 | import turtle as t 2 | from turtle import * 3 | 4 | 5 | angle = 60 #通过改变角度,绘制出各种多边形 6 | t.setup(1280,720) 7 | t.bgcolor('black') 8 | t.pensize(2) 9 | randomColor = ['red','blue','green','purple','gold','pink'] 10 | t.speed(0) 11 | for i in range(600): 12 | t.color(randomColor[i%6]) 13 | t.fd(i) 14 | t.rt(angle+1) 15 | up() 16 | color("#0fe6ca") 17 | goto(-600, 300) 18 | write('Author:Mifen', font=("微软雅黑", 18)) 19 | goto(-600, 250) 20 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 21 | goto(0,0) 22 | down() 23 | t.done() 24 | -------------------------------------------------------------------------------- /视觉冲击2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/视觉冲击2.png -------------------------------------------------------------------------------- /视觉冲击2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:40 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | import turtle as t 9 | from turtle import * 10 | 11 | angle = 60 #通过改变角度,绘制出各种多边形 12 | t.bgcolor('black') 13 | t.pensize(2) 14 | randomColor = ['red','blue','green','purple','gold','pink'] 15 | t.speed(0) 16 | for i in range(200): 17 | t.color(randomColor[i%6]) 18 | t.circle(i) 19 | t.rt(angle+1) 20 | up() 21 | color("#0fe6ca") 22 | goto(-600, 300) 23 | write('Author:Mifen', font=("微软雅黑", 18)) 24 | goto(-600, 250) 25 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 26 | goto(-600, 200) 27 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 28 | goto(0,0) 29 | down() -------------------------------------------------------------------------------- /闪瞎你眼睛.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amd794/Python123/9309d5594029162f0b34cb8594451e0c3b68e18e/闪瞎你眼睛.png -------------------------------------------------------------------------------- /闪瞎你眼睛.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Time : 2019/4/5 22:32 3 | # Author : Mifen 4 | # Email : 2952277346@qq.com 5 | # Github : https://github.com/Amd794 6 | 7 | 8 | 9 | import time 10 | import turtle as t 11 | from turtle import * 12 | 13 | t.speed(0) 14 | t.pensize(1) 15 | length = 40 16 | path = 'F' 17 | angle = 90 18 | setup(1280,720) 19 | up() 20 | color("blue") 21 | goto(-600, 300) 22 | write('Author:Mifen', font=("微软雅黑", 18)) 23 | goto(-600, 250) 24 | write('E-mail :2952277346@qq.com', font=("微软雅黑", 18)) 25 | goto(-600, 200) 26 | write('Code :https://github.com/Amd794/Python123', font=("微软雅黑", 18)) 27 | goto(0,0) 28 | down() 29 | expalnation = { 30 | 'F': '画线', 31 | 'x': '-', 32 | '+': '逆时针旋转', 33 | '-': '顺时针旋转', 34 | '[': '记录当前位置', 35 | ']': '恢复上一个位置', 36 | 'a': '上色', 37 | 'b': '上色', 38 | 'c': '上色' 39 | } 40 | rules = { 41 | 'F': 'F+F-F-F-G+F+F+F-F', 42 | 'G': 'GGG' 43 | } 44 | 45 | 46 | def draw_path(path, expalnation,angle): 47 | posList, angleList = [], [] 48 | t.bgcolor("black") 49 | t.lt(90) 50 | for symbol in path: 51 | if symbol == 'F': 52 | import random 53 | colormode(255) 54 | color(random.randint(0,255),random.randint(0,255),random.randint(0,255)) 55 | t.forward(length) 56 | elif symbol == '+': 57 | t.left(angle) 58 | elif symbol == '-': 59 | t.rt(angle) 60 | elif symbol == '[': 61 | posList.append(t.pos()) 62 | angleList.append(t.heading()) 63 | elif symbol == 'a': 64 | t.pensize(3) 65 | t.color("#8c503c") 66 | elif symbol == 'b': 67 | t.pensize(2) 68 | t.color("#4ab441") 69 | elif symbol == 'c': 70 | t.pensize(2) 71 | t.color("#18b418") 72 | elif symbol == 'G': 73 | angle = -angle 74 | elif symbol == ']': 75 | t.up() 76 | t.home() 77 | t.goto(posList.pop()) 78 | t.left(angleList.pop()) 79 | t.down() 80 | 81 | 82 | def apply_rules(path, rules): 83 | L = [_ for _ in path] 84 | for i in range(len(L)): 85 | symbol = L[i] 86 | if symbol == 'F': 87 | L[i] = rules[symbol] 88 | if symbol == 'X': 89 | L[i] = rules[symbol] 90 | if symbol == 'G': 91 | L[i] = rules[symbol] 92 | path = ''.join(L) 93 | return path 94 | 95 | 96 | for _ in range(5): 97 | path = apply_rules(path, rules) 98 | draw_path(path, expalnation,angle) --------------------------------------------------------------------------------