❶ 急求!这是一个用python画国旗的程序,请求大神解释一下每一步是干嘛的
import turtle //导入模块
import time
import os
def draw_square(org_x, org_y, x, y): //定义红旗绘制函数
turtle.setpos(org_x, org_y) //定义画笔初始位置
turtle.color('red', 'red') //颜色
turtle.begin_fill() //开始绘制
turtle.fd(x) //绘制偏转方向和角度
turtle.lt(90)
turtle.fd(y)
turtle.lt(90)
turtle.fd(x)
turtle.lt(90)
turtle.fd(y)
turtle.end_fill() //绘制结束
def draw_star(center_x, center_y, radius): //定义星星绘制函数
print(center_x, center_y) //显示位置
turtle.pencolor('black') //画笔轨迹颜色
turtle.setpos(center_x, center_y) //中心点位置
pt1 = turtle.pos() //偏转角度计算
turtle.circle(-radius, 360 / 5)
pt2 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt3 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt4 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt5 = turtle.pos()
turtle.color('yellow', 'yellow') //星星颜色
turtle.begin_fill() //开是绘制
turtle.goto(pt3)
turtle.goto(pt1)
turtle.goto(pt4)
turtle.goto(pt2)
turtle.goto(pt5)
turtle.end_fill() //绘制结束
print(turtle.pos())
turtle.pu() //隐藏画笔轨迹
draw_square(-320, -260, 660, 440) //绘制红旗
star_part_x = -320 //自定义星星大小等属性
star_part_y = -260 + 440
star_part_s = 660 / 30
center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5 //计算星星中心点位置
turtle.setpos(center_x, center_y)
turtle.lt(90)
draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2, star_part_s * 3) //绘制星星
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2) //同上
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 4)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 7)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 9)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.ht()
time.sleep(5) //设置挂起时间
os._exit(1)
❷ 如何用Python画澳大利亚国旗
把整个国旗换成直角坐标系。
在Python中绘制标准国旗并不简单,我们采用的方法在数学上称为解析法。把整个国旗换成直角坐标系,中心坐标为(0,0)。每个小格边长20,则国旗左上角坐标为(-300,200)、国旗长600,高400。Turtle是小海龟绘图库,Math是数学库,要用到里面的三角函数和反三角函数,以及圆周率pi值。
Python是一种解释型、面向对象、动态数据类型的高级程序设计语言。 Python于1989年底发明,第一个公开发行版发行于1991年。
❸ 如何用Python绘画日本国旗
使用Python自己的绘图工具即可,turtle。
#encoding:utf-8
#python3.6
importturtle
defdraw_japan_flag():
#日本国旗为“太阳旗”,呈长方形,长与宽之比为3∶2。旗面为白色,正中有一轮红日。
#红日半径
r=150
#画布尺寸(宽,高)
turtle.screensize(900,600)
#设置显示窗口像素
turtle.setup(width=900,height=600)
#移动画笔起点
turtle.penup()
turtle.goto(0,-r)
turtle.pendown()
#设置画笔属性
turtle.pensize(5)
turtle.pencolor("red")
turtle.fillcolor("red")
#绘制速度,1~10个不同速度等级,小于1或者大于10立即绘制
turtle.speed(0)
#开始绘制红日
turtle.begin_fill()
turtle.circle(r)
turtle.end_fill()
turtle.mainloop()
if__name__=="__main__":
draw_japan_flag()
❹ 请问一下网友老铁们 美国国旗用python怎么做呀 求其代码 谢谢拉
参考下五星红旗
<code>#!/usr/bin/env python
# -*- coding: utf-8 –*-
''' 对于turtle类的一些封装方法,包括画正多边形,正多角形和五星红旗。'''
__author__ = 'Hu Wenchao'
import turtle
import math
def draw_polygon(aTurtle, size=50, n=3):
''' 绘制正多边形
args:
aTurtle: turtle对象实例
size: int类型,正多边形的边长
n: int类型,是几边形
'''
for i in xrange(n):
aTurtle.forward(size)
aTurtle.left(360.0/n)
def draw_n_angle(aTurtle, size=50, num=5, color=None):
''' 绘制正n角形,默认为黄色
args:
aTurtle: turtle对象实例
size: int类型,正多角形的边长
n: int类型,是几角形
color: str, 图形颜色,默认不填色
'''
if color:
aTurtle.begin_fill()
aTurtle.fillcolor(color)
for i in xrange(num):
aTurtle.forward(size)
aTurtle.left(360.0/num)
aTurtle.forward(size)
aTurtle.right(2*360.0/num)
if color:
aTurtle.end_fill()
def draw_5_angle(aTurtle=None, start_pos=(0,0), end_pos=(0,10), radius=100, color=None):
''' 根据起始位置、结束位置和外接圆半径画五角星
args:
aTurtle: turtle对象实例
start_pos: int的二元tuple,要画的五角星的外接圆圆心
end_pos: int的二元tuple,圆心指向的位置坐标点
radius: 五角星外接圆半径
color: str, 图形颜色,默认不填色
'''
aTurtle = aTurtle or turtle.Turtle()
size = radius * math.sin(math.pi/5)/math.sin(math.pi*2/5)
aTurtle.left(math.degrees(math.atan2(end_pos[1]-start_pos[1], end_pos[0]-start_pos[0])))
aTurtle.penup()
aTurtle.goto(start_pos)
aTurtle.fd(radius)
aTurtle.pendown()
aTurtle.right(math.degrees(math.pi*9/10))
draw_n_angle(aTurtle, size, 5, color)
def draw_5_star_flag(times=20.0):
''' 绘制五星红旗
args:
times: 五星红旗的规格为30*20, times为倍数,默认大小为10倍, 即300*200
'''
width, height = 30*times, 20*times
# 初始化屏幕和海龟
window = turtle.Screen()
aTurtle = turtle.Turtle()
aTurtle.hideturtle()
aTurtle.speed(10)
# 画红旗
aTurtle.penup()
aTurtle.goto(-width/2, height/2)
aTurtle.pendown()
aTurtle.begin_fill()
aTurtle.fillcolor('red')
aTurtle.fd(width)
aTurtle.right(90)
aTurtle.fd(height)
aTurtle.right(90)
aTurtle.fd(width)
aTurtle.right(90)
aTurtle.fd(height)
aTurtle.right(90)
aTurtle.end_fill()
# 画大星星
draw_5_angle(aTurtle, start_pos=(-10*times, 5*times), end_pos=(-10*times, 8*times), radius=3*times, color='yellow')
# 画四个小星星
stars_start_pos = [(-5, 8), (-3, 6), (-3, 3), (-5, 1)]
for pos in stars_start_pos:
draw_5_angle(aTurtle, start_pos=(pos[0]*times, pos[1]*times), end_pos=(-10*times, 5*times), radius=1*times, color='yellow')
# 点击关闭窗口
window.exitonclick()
if __name__ == '__main__':
draw_5_star_flag()
</code>
❺ 怎么用Python画加纳国旗
#python6.6
importturtle
deftest():
#加纳共和国国旗呈长方形,长与宽之比为3∶2。
#自上而下由红、黄、绿三个平行相等的横长方形组成,黄色部分中间是一颗黑色五角星。
flag_h=300
flag_w=450
star_h=flag_h/3
turtle.pensize(2)
turtle.speed(5)
turtle.hideturtle()
defdraw_rectangle(color):
turtle.pencolor(color)
turtle.fillcolor(color)
turtle.pendown()
turtle.begin_fill()
turtle.forward(flag_w)
turtle.right(90)
turtle.forward(star_h)
turtle.right(90)
turtle.forward(flag_w)
turtle.right(90)
turtle.forward(star_h)
turtle.end_fill()
turtle.penup()
turtle.back(star_h)
turtle.right(90)
turtle.penup()
turtle.goto(-flag_w/2,flag_h/2)
draw_rectangle("red")
draw_rectangle("yellow")
draw_rectangle("green")
#五角星
turtle.penup()
turtle.goto(0,star_h/2)
turtle.pencolor("black")
turtle.fillcolor("black")
turtle.right(90-18)
turtle.pendown()
turtle.begin_fill()
foriinrange(5):
turtle.forward(star_h)
turtle.right(180-36)
turtle.end_fill()
turtle.done()
if__name__=="__main__":
test()
❻ 怎么用python的turtle库画出这个图案,要代码
import turtle as t
def quad(color):
t.begin_fill()
t.color(color)
t.forward(100)
t.left(36)
t.forward(100)
t.left(36*4)
t.forward(100)
t.left(36)
t.forward(100)
t.end_fill()
t.left(36*3)
for i in range(10):
if i%2:
quad('#99c8de')
else:
quad('#e5b9c4')
两三年没碰海龟了,觉得没啥用,看你赏金又提了就回去学了学
❼ 怎么利用python画五星红旗,求代码,
importturtle
t=turtle.Turtle()
whileTrue:
t.forward(200)
t.right(144)
ifabs(t.pos())<1:
break
turtle.done()
上什么课,最近好像很多人在画五角星,还要鼠标点什么的
❽ python turtle库画天安门
将#替换为空格,代码如下:
from turtle import *
speed('fastest')
def rectangle(h, v, c):#画长方形
####pendown()
####pensize(1)
####fillcolor(c)
####begin_fill()
####for counter in range(1, 3):
########forward(h)
########right(90)
########forward(v)
########right(90)
####end_fill()
####penup()
def gate(x, y, r, c):#画大门和小门
####fillcolor(c)
####begin_fill()
####penup()
####goto(x, y)
####pendown()
####setheading(0)
####right(90)
####forward(r*2)
####left(90)
####forward(r*2)
####left(90)
####forward(r*2)
####setheading(90)
####circle(r, 180)
####end_fill()
####setheading(0)
def trapezium(x, y, c):#画地下的大梯形
####fillcolor(c)
####begin_fill()
####penup()
####goto(x, y)#goto(-200, 0)
####pendown()
####forward(400)
####right(60)
####forward(150)
####right(120)
####forward(550)
####right(120)
####forward(150)
####right(60)
####end_fill()
def roof1(x, y, c):#画第1个屋檐
####fillcolor(c)
####begin_fill()
####penup()
####goto(x, y)
####pendown()
####left(60)
####forward(30)
####right(60)
####forward(225)
####right(60)
####forward(30)
####left(60)
####forward(-20)
####end_fill()
def roof2(x, y, c):#画第2个屋檐
####fillcolor(c)
####begin_fill()
####penup()
####goto(x, y)
####setheading(0)
####pendown()
####left(60)
####goto(-75, 155)
####right(60)
####goto(75, 155)
####right(60)
####goto(125, 95)
####right(120)
####goto(x ,y)
####penup()
####end_fill()
pencolor('black')
trapezium(-200, 0, 'red')
penup()
goto(-105, 95)
rectangle(210, 20, 'red')
goto(-115, 50)
rectangle(230, 50, 'red')
roof1(-125, 50, 'orange')
roof2(-125, 95, 'orange')
gate(-90, 25, 10, 'brown')
gate(-65, 25, 10, 'brown')
gate(-40, 25, 10, 'brown')####
penup()
forward(40)
gate(20, 25, 10, 'brown')
gate(45, 25, 10, 'brown')
gate(70, 25, 10, 'brown')####
gate(-160, -100, 15, 'brown')
gate(-95, -100, 15, 'brown')
gate(-30, -70, 30, 'brown')####
gate(60, -100, 15, 'brown')
gate(125, -100, 15, 'brown')
done()