Python学习打卡—海龟画图

Python学习第一天——turtle画国旗

由于已经有了C的基础,所以基础知识不再讲解,直接上代码!

一、画国旗背景
import turtle

#画国旗背景
turtle.up()#抬笔
turtle.goto(-200,200)#将笔移动到坐标(-200,200)
turtle.down()#开始画
turtle.begin_fill()#准备开始填充颜色
turtle.fillcolor("red")#填充颜色为红色
turtle.pencolor("red")#画笔颜色为红色
#turtle.color('red','red')

for i in range(2):
    turtle.forward(300)#向前画300像素长度
    turtle.right(90)#顺时针旋转90度
    turtle.forward(200)#向前画200像素长度
    turtle.right(90)#顺时针旋转90度
turtle.end_fill()#填充完成

turtle.forward(distance) :向当前画笔方向移动distance像素长度
turtle.right(degree) : 顺时针移动degree°
turtle.goto(x,y) : 将画笔移动到坐标为x,y的位置
turtle.penup() : 提起笔移动,不绘制图形,用于另起一个地方绘制
turtle.pendown() : 移动时绘制图形,缺省时也为绘制
turtle.begin_fill() : 准备开始填充图形
turtle.end_fill() : 填充完成
turtle.color(color1, color2) : 同时设置pencolor=color1, fillcolor=color2

二、画五角星
#画第一个大五角星
turtle.up()
turtle.goto(-170,145)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

for x in range(5):
    turtle.forward(45)
    turtle.right(144)
turtle.end_fill()
#第二个五角星
turtle.up()
turtle.goto(-115,175)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()
#第三个五角星 
turtle.up()
turtle.goto(-90,157)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()
#第四个五角星 
turtle.up()
turtle.goto(-87,130)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()
#最后一个五角星
turtle.up()
turtle.goto(-106,106)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()

turtle.hideturtle()#隐藏画笔形状
turtle.done()#落笔

turtle.hideturtle() : 隐藏画笔的turtle形状
turtle.showturtle() : 显示画笔的turtle形状

以下为效果图

全部评论

相关推荐

面试官全程关摄像头1.自我介绍一下2.React和Vue哪个更熟悉一点3.你在之前那段实习经历中有没有什么技术性的突破(我只是实习了44天工作28天,我把我能说的都说了)4.你封装的哪个表单组件支不支持动态传值5.自己在实习阶段Vue3项目封装过hook吗6.hook有什么作用7.Vue2和Vue3的响应式区别(我说一个是proxy是拦截所有的底层操作,Object.defineProperty本身就是一个底层操作,有些东西拦截不了,比如数组的一些操作还有等等,面试官就说实在要拦截能不能拦截????我心想肯定不行呀,他的底层机制就不允许吧)8.pinia和vuex的区别(这个回答不出来是我太久没用了)9.pinia和zustand的区别,怎么选(直接给我干懵了)(我说react能用pinia吗  他说要用的话也可以)10.渲染一万条数据,怎么解决页面卡顿问题(我说分页、监听滚轮动态加载,纯数据展示好像还可以用canvas画)(估计是没说虚拟表单,感觉不满意)11.type和interface的区别12.ts的泛型有哪些作用(我就说了一个结构相同但是类型不同的时候可以用,比如请求响应的接口,每次的data不同,这里能用一个泛型,他问我还有什么)13.你项目用的是React,如果让你再写一遍你会选择什么14.pnpm、npm、yarn的区别15.dependencies和devdependencies的区别总而言之太久没面试了,上一段实习的面试js问了很多。结果这次js一点没问,网络方面也没考,表现得很一般,但是知道自己的问题了  好好准备,等待明天的影石360和周四的腾讯了  加油!!!
解zj:大三的第一段面试居然是这样的结局
查看15道真题和解析
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
2025-12-04 21:05
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务