用python函数画德国国旗代码_用Python的turtle模块画国旗
最近在学Python,发现Python的海龟绘图非常有趣,就分享一下!话不多说,先来Python turtle的官方文档链接: Python turtle。这里面有turtle的各类指令。turtle画国旗主要用到两个函数:draw_rentangle和draw_star。
import time
import turtle
import os
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的turtle模块画国旗用Python的turtle模块画国旗
感觉画的还不赖:)
用python函数画德国国旗代码_用Python的turtle模块画国旗相关推荐
- 用python函数画德国国旗代码_使用Python的turtle模块画国旗
Python的turtle模块画国旗主要用到两个函数:draw_rentangle和draw_star. 至于函数的调用就和我们学的C,C++是一样的.对于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画小猪佩奇
猪年农历春节前,朋友圈被一则走心的广告刷屏了.很多伙伴直呼:看哭了.当爷爷电话里听到儿子说「不回来啊」的打击是很沉重的,这位父亲想念自己的儿子和孙子,总想把最好的给他们. 如果你的孩子问你要佩奇,你除 ...
最新文章
- shell脚本编程之处理用户输入
- 使用uniapp开发婚庆应用的时候开发公共组件请求网络数据的方式
- angularjs 中的scope继承关系——(2)
- spring配置的相关文章
- guid oracle 生成不重复_可空类型和Guid的使用
- 个性化推荐之召回的方法
- 利用jquery getJSON 调用ashx实现ajax调用
- (转)百度文库浏览器分析及实现(续)
- java 获取web目录结构_Intellij Idea Javaweb 目录结构及获取项目内资源
- 方舟手游服务器设置文件翻译,方舟手游咋设置翻译
- 22考研计算机专业课——数据结构【❤️考研复习指导❤️】
- 部门角色权限rbac_直白的解说一下RBAC权限设计
- SpringBoot实现阿里云短信接口对接
- 2013程序员考证下午题练习
- Android获取基带版本
- ISP 和IAP 原理与区别
- dashboard android,Dashboard软件下载
- osgEarth示例分析——osgearth_terrainprofile
- uniapp开发微信小程序,出现[微信小程序开发者工具] [error] Error: Fail to open IDE 错误的原因--潘万丁
- 李嘉诚传给年青人的人生忠告