画十字架中的爱心

用tkinter画十字架中的爱心

from tkinter import *
import math
root = Tk()
w = Canvas(root, width=800, height=800)
w.pack()
# 画红色的坐标轴线
width=800
height=800
w0=width/2
h0=height/2
w.create_line(0, h0, width, h0, fill="red")
w.create_line(w0, 0, w0, height, fill="red")

def x(t):
    x = (w0 / 4) * (-2 * math.sin(t) + math.sin(2 * t))
    x+=w0    #平移x轴
    return x
def y(t):
    y = (h0 / 4) * (2 * math.cos(t) - math.cos(2 * t))
    y-=h0    #平移y轴
    y = -y    #y轴值反向
    return y
t = 0.0
while (t<(2*math.pi)):
    w.create_line(x(t), y(t), x(t+0.01), y(t+0.01),fill="blue")
    t+=0.01
root.mainloop()

运行结果:

 

 

利用turtle库绘制一个每方向为100像素长度的十字架

import turtle
for i in range(4):
    turtle.fd(100)
    turtle.fd(-100)
    turtle.seth((i+1)*90)    #seth 绝对角度

运行结果:

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
十字架,可以使用Python的turtle库。首先,调用turtle库并隐藏笔的turtle形状。然后,设置布的相关参数,如大小和颜色。接下来,设置笔的颜色、宽度和移动速度。然后,设置填充颜色并开始填充图案。接着,移动笔到特定位置并绘制图像。在需要的地方,使用penup()提起笔,使用pendown()放下笔。最后,结束颜色填充并保持图像显示在屏幕上。下面是一个示例代码来十字架: ``` import turtle turtle.hideturtle() turtle.screensize(800, 800, "white") turtle.pencolor("red") turtle.pensize(1) turtle.speed(50) turtle.fillcolor("red") turtle.begin_fill() turtle.goto(25, 0) turtle.goto(25, -5) turtle.goto(0, -5) turtle.goto(0, 0) turtle.penup() turtle.goto(10, 10) turtle.pendown() turtle.goto(15, 10) turtle.goto(15, -35) turtle.goto(10, -35) turtle.goto(10, 10) turtle.end_fill() turtle.mainloop() ``` 以上代码使用turtle库来绘制一个红色的填充十字架。你可以根据需要调整参数来改变十字架的大小和颜色。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Python海龟手册,Python turtle manual , Python海龟绘图用户手册李兴球版](https://download.csdn.net/download/avskya/85655966)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Python|出一个300像素的十字架](https://blog.csdn.net/gschen_cn/article/details/114528768)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [python - 09【turtle库的使用(绘制小猪佩奇)】](https://blog.csdn.net/weixin_39797780/article/details/113504518)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值