• 七夕玫瑰花合集



    图片来源:百度动图

    图片
图片
      

    一年一度的七夕又快到了,用Python画一朵玫瑰花送给你的那个TA吧图片。更多表白代码可以到”阿黎逸阳的代码“公众号中翻看表白合集中的文章。

      
      

    一、绘制结果

      

    1. 玫瑰花1

      
    在这里插入图片描述

      
      

    2. 玫瑰花2

      

      
      

    二、画玫瑰花代码

      

    1. 用turtle库画一朵玫瑰花版本1

      

    # -*- coding: UTF-8 -*-
    '''
    代码用途 :画玫瑰花
    作者     :阿黎逸阳
    博客     :  https://blog.csdn.net/qq_32532663/article/details/106176609
    '''
    
    #绘制玫瑰花并添加文字
    import turtle 
    # 设置画布大小
    # turtle.screensize(canvwidth=None, canvheight=None, bg=None)
    turtle.setup(width=0.6, height=0.6)
    # 设置初始位置
    turtle.penup()
    turtle.left(90)
    turtle.fd(200)
    turtle.pendown()
    turtle.right(90)
     
    # 输出文字
    printer = turtle.Turtle()
    printer.hideturtle()
    printer.penup()
    printer.back(200)
    printer.write("赠给亲爱的 XX\n\n", align="right", font=("楷体", 16, "bold"))
    printer.write("from XXX", align="center", font=("楷体", 12, "normal"))
     
    # 花蕊
    turtle.fillcolor("red")
    turtle.begin_fill()
    turtle.circle(10, 180)
    turtle.circle(25, 110)
    turtle.left(50)
    turtle.circle(60, 45)
    turtle.circle(20, 170)
    turtle.right(24)
    turtle.fd(30)
    turtle.left(10)
    turtle.circle(30, 110)
    turtle.fd(20)
    turtle.left(40)
    turtle.circle(90, 70)
    turtle.circle(30, 150)
    turtle.right(30)
    turtle.fd(15)
    turtle.circle(80, 90)
    turtle.left(15)
    turtle.fd(45)
    turtle.right(165)
    turtle.fd(20)
    turtle.left(155)
    turtle.circle(150, 80)
    turtle.left(50)
    turtle.circle(150, 90)
    turtle.end_fill()
     
    # 花瓣1
    turtle.left(150)
    turtle.circle(-90, 70)
    turtle.left(20)
    turtle.circle(75, 105)
    turtle.setheading(60)
    turtle.circle(80, 98)
    turtle.circle(-90, 40)
     
    # 花瓣2
    turtle.left(180)
    turtle.circle(90, 40)
    turtle.circle(-80, 98)
    turtle.setheading(-83)
     
    # 叶子1
    turtle.fd(30)
    turtle.left(90)
    turtle.fd(25)
    turtle.left(45)
    turtle.fillcolor("green")
    turtle.begin_fill()
    turtle.circle(-80, 90)
    turtle.right(90)
    turtle.circle(-80, 90)
    turtle.end_fill()
    turtle.right(135)
    turtle.fd(60)
    turtle.left(180)
    turtle.fd(85)
    turtle.left(90)
    turtle.fd(80)
     
    # 叶子2
    turtle.right(90)
    turtle.right(45)
    turtle.fillcolor("green")
    turtle.begin_fill()
    turtle.circle(80, 90)
    turtle.left(90)
    turtle.circle(80, 90)
    turtle.end_fill()
    turtle.left(135)
    turtle.fd(60)
    turtle.left(180)
    turtle.fd(60)
    turtle.right(90)
    turtle.circle(200, 60)
     
    turtle.done()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106

    效果图
      
    在这里插入图片描述

      
      

    2. 用turtle库画一朵玫瑰花版本2

      

    # -*- coding: UTF-8 -*-
    '''
    代码用途 :画玫瑰花
    作者     :阿黎逸阳
    博客     :  https://blog.csdn.net/qq_32532663/article/details/106176609
    '''
    import os
    import time
    import pygame
    import turtle as t 
    
    #播放音乐
    print('播放音乐')
    pygame.mixer.init()
    pygame.mixer.music.load(r"F:\公众号\62.玫瑰花\Eran - 春の思い出.mp3") 
    pygame.mixer.music.set_volume(0.5) 
    pygame.mixer.music.play(1, 10)
    
    t.title('阿黎逸阳的代码公众号')
    t.speed(3)
    t.setup(startx=0, starty = 0, width=800, height = 600)
    #画爱心
    def red_heart():
        t.penup()
        t.goto(0, 200)
        t.pendown()
        t.pensize(2)
        t.color('black', 'red')   
        t.begin_fill()
        t.setheading(110)
        t.circle(30, 150)
        t.left(15)
        t.circle(50, 70)
        t.circle(-50, 30)
        t.left(100)
        t.circle(-50, 30)
        t.right(10)
        t.circle(50, 70)
        t.left(5)
        t.circle(29, 175)
        t.end_fill()
    def top_arc():
        #画花上面的部分
        t.penup()
        t.goto(18, 224)
        t.pendown()
        t.begin_fill()
        t.setheading(125)
        t.pensize(2)
        t.color('black', 'red')
        t.circle(25, 125)
        t.color('red')
        t.circle(25, 360-125)
        t.end_fill()
    def under_arc():
        #画下弧线
        t.penup()
        t.goto(-58, 190)
        t.pendown()
        t.begin_fill()
        t.color('black', 'red')
        t.setheading(290)
        t.circle(-120, 50)
        t.circle(60, 120)
        t.setheading(-10)
        t.circle(60, 120)
        t.left(4)
        t.circle(-120, 50)
        t.end_fill()
    def stamen():
        #画花蕊
        t.penup()
        t.goto(0, 185)
        t.pendown()
        t.setheading(90)
        t.circle(5, 270)
        t.right(5)
        t.circle(100, 8)
        #t.right(10)
        t.circle(10, 180)
        t.circle(100, 8)
        t.right(10)
        t.circle(15, 160)
        t.circle(80, 5)
        t.right(34)
        t.circle(-30, 80)
        #画花身
        t.right(10)
        t.circle(100, 82)
        #画竖线
        t.penup()
        t.goto(-10, 183)
        t.pendown()
        t.setheading(-90)
        t.forward(15)
        t.penup()
        t.goto(-21, 179)
        t.pendown()
        t.setheading(-90)
        t.forward(25)
        t.penup()
        t.goto(18, 185)
        t.pendown()
        t.setheading(-90)
        t.forward(29)
    print('画心')
    red_heart()
    print('画顶部弧线')
    top_arc()
    print('画下弧线')
    under_arc()
    print('画心')
    red_heart()
    print('画花蕊')
    stamen() 
    # 写文字
    t.hideturtle()
    t.penup()
    t.goto(-200, -200)
    t.pendown()
    t.write("赠给亲爱的 XX\n\n", align="right", font=("楷体", 16, "bold"))
    t.penup()
    t.goto(-200, -200)
    t.pendown()
    t.write("from XXX", align="right", font=("楷体", 12, "normal"))
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125

    效果视频

    注:如需视频源代码,请在 ”阿黎逸阳的代码“ 公众号中回复 “玫瑰花2”,即可免费获取。
      
    祝大家七夕节日快乐,有情人终成眷属。
      
    你可能感兴趣:
    用Python绘制皮卡丘
    用Python绘制词云图
    用Python绘制520永恒心动
    Python人脸识别—我的眼里只有你
    Python画好看的星空图(唯美的背景)
    【Python】情人节表白烟花(带声音和文字)
    用Python中的py2neo库操作neo4j,搭建关联图谱
    Python浪漫表白源码合集(爱心、玫瑰花、照片墙、星空下的告白)

    长按(扫一扫)识别上方二维码学习更多Python和建模知识,让你的学习和工作更出彩
  • 相关阅读:
    虚函数表、函数地址、虚函数指针问题!
    RocketMQ实战之在线停机和扩容
    SpringMVC的请求映射:路由请求的精准导航
    店匠独立站站外引流之Facebook引流
    创建定时任务——crontab的使用
    [vue] 嵌套iframe,$router.go(-1)后退bug
    遇到Bug漏测,不能总想着甩锅吧
    TCL基础入门
    将文件从windows传入到ubuntu
    [C++][算法基础]分组背包问题(动态规划)
  • 原文地址:https://blog.csdn.net/qq_32532663/article/details/126090867