python绘制螺旋正方形(用python画一个旋转的正方形)

http://www.itjxue.com  2023-03-17 12:15  来源:未知  点击次数: 

求教python中的turtle

简介:turtle是一个简单的绘图工具。它提供了一个海龟,你可以把它理解为一个机器人,只听得懂有限的指令。

1.在文件头写上如下行,这能让我们在语句中插入中文

#-*- coding: utf-8 -*-

2.用import turtle导入turtle库

3.绘图窗口的原点(0,0)在正中间。默认情况下,海龟向正右方移动。

4.操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令

(1)运动命令:

forward(d)

向前移动距离d代表距离

backward(d)

向后移动距离d代表距离

right(degree)

向右转动多少度

left(degree)

向左转动多少度

goto(x,y)

将画笔移动到坐标为(x,y)的位置

stamp()

绘制当前图形

speed(speed)

画笔绘制的速度范围[0,10]整数

(2)画笔控制命令:

down()

画笔落下,移动时绘制图形

up()

画笔抬起,移动时不绘制图形

setheading(degree)

海龟朝向,degree代表角度

reset()

恢复所有设置

pensize(width)

画笔的宽度

pencolor(colorstring)

画笔的颜色

fillcolor(colorstring)

绘制图形的填充颜色

fill(Ture)

fill(False)

circle(radius, extent)

绘制一个圆形,其中radius为半径,extent为度数,例如若extent为180,则画一个半圆;如要画一个圆形,可不必写第二个参数

5.几个例子

1)画一个边长为60的三角形

#-*- coding: utf-8 -*-

importturtle

a=60

turtle.forward(a)

turtle.left(120)

turtle.forward(a)

turtle.left(120)

turtle.forward(a)

turtle.left(120)

2)画一个边长为60的正方形,并填充为红色,边框为蓝色

#-*- coding: utf-8 -*-

importturtle

turtle.reset()

a= 60

turtle.fillcolor("red")

turtle.pencolor("blue")

turtle.pensize(10)

turtle.fill(True)

turtle.left(90)

turtle.forward(a)

turtle.left(90)

turtle.forward(a)

turtle.left(90)

turtle.forward(a)

turtle.left(90)

turtle.forward(a)

turtle.fill(False)

6.练习:

1)画一个五边形

2)画一个六边形

3)任意输入一个正整数m(=3),画一个多边形(m条边)

4)画一个五角星,如下所示,注意填充为红色

5)画一个中国象棋棋盘,如下图所示,其中汉字不必显示出来:

6)绘制奥运五环图,其中五种颜色分别为蓝色、黑色、红色、黄色和绿色。注意根据实际效果调整圆形的大小和位置。

编写 python ,绘制以原点为中心,边平行于坐标轴的正方形,求问怎么做?

public void sort(int []array, int len){

int i,j,temp;

for (i=1;ilen;i++){

temp = array[i];

j=i-1;

while(j=0 array[j]temp){

array[j+1] = array[j];

j--;

}

array[j+1] = temp;

}

有大神可以用python的turtle模块画图吗,求解

from turtle import*

pensize(4)

penup()

fd(150)

right(90)

fd(200)

pendown()

seth(100)

fd(150)

seth(31)

circle(130,300)

seth(170)

fd(80)#shou

seth(85)

fd(30)#qiang

left(90)#qiang

fd(120)#qiang

left(90)#qiang

fd(40)#qiang

left(90)#qiang

fd(80)#qiang

right(90)

fd(45)

left(90)

fd(40)

left(90)

fd(21)

penup()

fd(30)

pendown()

seth(100)

circle(20,290)

seth(340)

fd(90)

seth(270)

fd(100)

penup()

seth(90)

fd(250)

pendown()

pensize(20)

seth(270)

fd(7)

penup()

seth(0)

fd(100)

pendown()

seth(90)

fd(7)

penup()

python无边正方形绘制代码?

你好,答案如下所示。

程序缩进如图所示

运行结果如图所示

希望你能够详细查看。

如果你有不会的,你可以提问

我有时间就会帮你解答。

希望你好好学习。

每一天都过得充实。

在python里,如何实现点击开始按钮,开始慢慢在不同位置出现不同颜色的不同图形?

示例代码

# 导入Tkinter模块

from tkinter import *

# 创建一个窗口

window = Tk()

# 定义一个函数,用来生成图形

def generate_shape():

# 使用随机数生成不同的图形和颜色

shape = random.choice(["circle", "square", "triangle"])

color = random.choice(["red", "green", "blue"])

# 使用随机数生成不同的位置

x = random.randint(0, 200)

y = random.randint(0, 200)

# 在窗口中绘制图形

if shape == "circle":

# 绘制圆形

canvas.create_oval(x, y, x + 50, y + 50, fill=color)

elif shape == "square":

# 绘制正方形

canvas.create_rectangle(x, y, x + 50, y + 50, fill=color)

else:

# 绘制三角形

points = [x, y, x + 50, y + 50, x + 25, y + 75]

canvas.create_polygon(points, fill=color)

# 创建一个画布

canvas = Canvas(window, width=200, height=200)

canvas.pack()

# 创建一个按钮

button = Button(window, text="Start", command=generate_shape)

button.pack()

# 进入消息循环

window.mainloop()

(责任编辑:IT教学网)

更多
上一篇:没有了

推荐网络创业文章