用python函数画德国国旗代码_使用Python的turtle模块画国旗
Python的turtle模块画国旗主要用到两个函数:draw_rentangle和draw_star。
至于函数的调用就和我们学的C,C++是一样的。对于turtle画国旗的程序中,首先是查找国旗的画法,才能用程序实现。自己在实现的过程中主要是对turtle.circle()没有准确掌握,所以花了一些不必要的时间。turtle.circle画弧时,海龟(turtle)的方向就是弧的切线方向,也就是说turtle的垂直方向就是圆心在的直线上,给定参数radius就可以画了,程序中第二注意的地方就是小五角星和大五角星的位置关系,主要是程序中的turtle.left(turtle.towards(center_x,center_y)-turtle.heading()),当然,我看有的人用了round()函数来获取近似值,但是,默认的已经足够了。下面是本人写的程序和结果演示。
import time
import turtle
import os
'''
想要学习Python?Python学习交流群:984632579满足你的需求,资料都已经上传群文件,可以自行下载!
'''
def draw_rectangle(start_x,start_y,rec_x,rec_y):
turtle.goto(start_x,start_y)
turtle.color('red')
turtle.fillcolor('red')
turtle.begin_fill()
for i in range(2):
turtle.forward(rec_x)
turtle.left(90)
turtle.forward(rec_y)
turtle.left(90)
turtle.end_fill()
def draw_star(center_x,center_y,radius):
turtle.setpos(center_x,center_y)
#find the peak of the five-pointed star
pt1=turtle.pos()
turtle.circle(-radius,72)
pt2=turtle.pos()
turtle.circle(-radius,72)
pt3=turtle.pos()
turtle.circle(-radius,72)
pt4=turtle.pos()
turtle.circle(-radius,72)
pt5=turtle.pos()
#draw the five-pointed star
turtle.color('yellow','yellow')
turtle.fill(True)
turtle.goto(pt3)
turtle.goto(pt1)
turtle.goto(pt4)
turtle.goto(pt2)
turtle.goto(pt5)
turtle.fill(False)
#start the project
turtle.speed(5)
turtle.penup()
#draw the rectangle
star_x=-320
star_y=-260
len_x=660
len_y=440
draw_rectangle(star_x,star_y,len_x,len_y)
#draw the big star
pice=660/30
big_center_x=star_x+5*pice
big_center_y=star_y+len_y-pice*5
turtle.goto(big_center_x,big_center_y)
turtle.left(90)
turtle.forward(pice*3)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice*3)
#draw the small star
turtle.goto(star_x+10*pice,star_y+len_y-pice*2)
turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice)
#draw the second star
turtle.goto(star_x+pice*12,star_y+len_y-pice*4)
turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice)
#draw the third
turtle.goto(star_x+pice*12,star_y+len_y-7*pice)
turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice)
#draw the final
turtle.goto(star_x+pice*10,star_y+len_y-9*pice)
turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice)
turtle.ht()
time.sleep(3)
os._exit(1)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
用python函数画德国国旗代码_使用Python的turtle模块画国旗相关推荐
- 用python函数画德国国旗代码_用Python的turtle模块画国旗
最近在学Python,发现Python的海龟绘图非常有趣,就分享一下!话不多说,先来Python turtle的官方文档链接: Python turtle.这里面有turtle的各类指令.turtle ...
- python好看图案的编程代码_利用Python绘制了一些有意思的图案
下载W3Cschool手机App,0基础随时随地学编程导语 花了点时间利用Python绘制了一些有意思的图案,也算是发掘了一下Python的可视化功能吧... PS: 部分图案参考了一些博客的一部分源 ...
- python画pr曲线代码_利用Python中的numpy包实现PR曲线和ROC曲线的计算
闲来无事,边理解PR曲线和ROC曲线,边写了一下计算两个指标的代码.在 python 环境下,sklearn里有现成的函数计算ROC曲线坐标点,这里为了深入理解这两个指标,写代码的时候只用到numpy ...
- 用python画小猪佩奇代码_用python画个小猪佩奇(turtle示例源码)
[实例简介]来副小猪佩奇,用python画个小猪佩奇 [实例截图] [核心代码]# coding:utf-8 import turtle as t def nose(x,y):#鼻子 t.pu() t ...
- python发邮件给女朋友代码_用python讨好女朋友是什么个操作?
原标题:用python讨好女朋友是什么个操作? 文章发布于公号[数智物语] (ID:decision_engine),关注公号不错过每一篇干货. 转自 |数据团学社(微信搜索metrodata_xue ...
- 用python函数画德国国旗代码_用Python绘制一面国旗
import turtle as tu tu.hideturtle() #隐藏海龟 tu.speed(10) tu.title("Chinese National Flag.") ...
- 用python函数画德国国旗代码_用python画个五星红旗
importturtle turtle.bgcolor("red") turtle.fillcolor("yellow") turtle.color('yell ...
- python画小狗代码_用Python画一只有点方的小狗狗——turtle库circle()函数实践
一只脑门有点方的小狗,其实还可以把脑门和后脑勺完善一下,更圆润一些. 但这样也挺可爱,就保有这样不完美但独一无二的它吧.绘制过程主要就是拼接和调整圆弧,尽量做到过度自然.turtle库的circle( ...
- 用python画小猪佩奇代码_用Python画小猪佩奇
猪年农历春节前,朋友圈被一则走心的广告刷屏了.很多伙伴直呼:看哭了.当爷爷电话里听到儿子说「不回来啊」的打击是很沉重的,这位父亲想念自己的儿子和孙子,总想把最好的给他们. 如果你的孩子问你要佩奇,你除 ...
最新文章
- 开源教程 「nlp-tutorial」!用百行代码搞定各类NLP模型
- 一个在分割、检测与定位、高分辨率通用的网络
- php中json_encode中文编码问题分析
- 关于bootstrap的一些想法
- tf.nn.embedding_lookup
- 飞利浦 f718 java 微信_第一次使用飞利浦F718手机感觉怎么样及优缺点
- simulink的pid参数自整定
- 产品经理OR售前支持
- 2019天津市二级计算机考试,天津市2019年9月计算机等级考试都有哪些考点可以报名?...
- 计算机win32时间问题,电脑无法修改时间并提示Windows找不到文件rundll32.exe怎么办...
- Ubuntu18.04安装ceres-solver
- countifs多条件排序_使用Excel COUNTIFS进行多个条件计数
- mysql中ddl是什么_MySQL中DDL是什么意思
- t460p和t470p对比评测_老模具小升级 ThinkPad T470p商务本评测
- Java后端面经(部分)
- WIFI驱动开发——WIFI基础知识汇总
- CDA Level 1 数据分析师:6.2 指标的应用与设计
- 从Redis、HTTP协议,看Nett协议设计,我发现了个惊天大秘密
- 抽象类不能声明主体_软件的主导地位能否继续
- 软件工程就业前景怎么样?大家对这个职业是否有什么误区?
热门文章
- 摘录一些知乎句子,挺好的句子.
- vue项目动态引入图片无法显示的问题
- html href链接中文乱码,javascript如何解决url中文乱码?
- java图片上传代码_java 图片上传
- PERTII型管/聚氨酯保温管如何安装施工
- 伍迷创意随想集 之 爱情博物馆
- Oracle进阶(二)存储过程(Procedure)
- $(...).modal is not a function的解决办法
- WebSocket心跳机制
- AutoCAD文件清晰线条打印方法