Python

您所在的位置:网站首页 turtle画三角形 Python

Python

2023-08-25 12:53| 来源: 网络整理| 查看: 265

第一题

1 .画一个由两个直角三角形组成的正方形,边长为180像素

2 .左上三角形填充为黄色,右下三角形填充为红色

3 .设置画笔速度为1,线条为黑色

4 .画图结束,隐藏并停止画

import turtle as t t.speed(1) t.fillcolor("red") #背景填充为红色 t.begin_fill() t.forward(180) t.left(90) t.forward(180) t.goto(0,0) #起点坐标 t.end_fill() t.fillcolor("yellow") #背景填充为黄色 t.begin_fill() t.forward(180) t.right(90) t.forward(180) t.goto(0,0) #起点坐标 t.end_fill() t.hideturtle() #隐藏画笔 t.done()  第二题

画出半径为100的风轮,具体要求如下:

1 .风轮由四个扇叶组成,每个扇叶大小相等,相邻两个扇叶间距相等

2.四个扇叶的颜色分别是("red","yellow","blue","green"

import turtle as t t.speed(9) colors=["red","yellow","blue","green"] #创建颜色这个列表 def drawleave(x): #定义一个函数 t.seth(x*90) t.fillcolor( colors[x] ) #填充颜色选取颜色列表 t.begin_fill() t.forward(100) t.right(90) t.circle(-100,45) t.right(90) t.forward(100) t.end_fill() for x in range(4): drawleave(x) t.hideturtle() t.done() 第三题 

使用turtle绘制图形,中间是半径为120的圆,四周是边长为80的12个菱形。

1)背景为白色,中间为红色轮廓线,不填充

2)图中菱形的长对角线经过圆心

3)菱形为黑色轮廓线 、黄色填充,其中锐角为60度

4)绘图过程中隐藏画笔,能清楚看到图形绘制过

import turtle as t t.speed(0) t.pensize(1) for i in range(12): #画菱形 t.color("black","yellow") t.begin_fill() t.penup() t.forward(120) t.pendown() t.left(30) t.forward(80) t.right(60) t.forward(80) t.right(120) t.forward(80) t.right(60) t.forward(80) t.right(150) t.penup() t.back(120) t.pendown() t.right(30) t.end_fill() #绘制圆形 t.pencolor("red") t.penup() t.forward(120) t.pendown() t.left(90) t.circle(120) t.hideturtle() #隐藏画笔 t.done()

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3