520,送你四种Python画玫瑰的方法

今天又是520🧐掌柜在网上收集了四种画玫瑰花的方法,希望有你喜欢的一种!

  1. 第一种:顶上慢画玫瑰花🌹
#第一种:画玫瑰的方法
from turtle import *
import time

#初始化玫瑰
#画布大小
setup(600,800,0,0) 
speed(0)
penup() # 提起画笔
seth(90) #朝向90度
fd(340)  #向前移动指定的距离
seth(0)
pendown()  #放下画笔

#开始画
speed(5)      #画笔移动速度为5秒
begin_fill()  #开始填充
fillcolor('red') #为红色
circle(50,30)    #画一个半径为50,弧度为30的圆
  
for i in range(10):
    fd(1)
    left(10)    #逆时针转动画笔10度
circle(40,40)
  
for i in range(6):
    fd(1)
    left(3)
circle(80,40)
  
for i in range(20):
    fd(0.5)
    left(5)
circle(80,45)
  
for i in range(10):
    fd(2)
    left(1)
circle(80,25)
  
for i in range(20):
    fd(1)
    left(4)
circle(50,50)
  
time.sleep(0.1)
  
circle(120,55)
  
speed(3)
  
seth(-90)
fd(70)
  
right(150)   #顺时针转动画笔150度
fd(20)
  
left(140)
circle(140,90)
  
left(30)
circle(160,100)
  
left(130)
fd(25)
  
penup()
right(150)
circle(40,80)
pendown()
  
left(115)
fd(60)
  
penup()
left(180)
fd(60)
pendown()
  
end_fill()
  
right(120)
circle(-50,50)
circle(-20,90)
  
speed(1)
fd(75)
  
speed(1)
circle(90,110)
  
penup()
left(162)
fd(185)
left(170)
pendown()
circle(200,10)
circle(100,40)
circle(-52,115)
left(20)
circle(100,20)
circle(300,20)
speed(1)
fd(250)
  
penup()
speed(2)
left(180)
fd(250)
circle(-300,7)
right(80)
circle(200,5)
pendown()
  
left(60)
begin_fill()
fillcolor('green')
circle(-80,100)
right(90)
fd(10)
left(20)
circle(-63,127)
end_fill()
  
penup()
left(50)
fd(20)
left(180)
  
pendown()
circle(200,25)
  
penup()
right(150)
  
fd(180)
  
right(40)
pendown()
begin_fill()
fillcolor('green')
circle(-100,80)
right(150)
fd(10)
left(60)
circle(-80,98)
end_fill()
  
penup()
left(60)
fd(13)
left(180)
  
pendown()
speed(1)
circle(-200,23)
  
exitonclick() #当点击时退出

最后效果图:
在这里插入图片描述

  1. 第二种:中间玫瑰秒画叶
#首先代码一开始要引入turtle库
#第二种:这个画在画布中间了比上面的好
import turtle as t

#定义一个曲线绘制函数,定义一个简单的绘制曲线的函数
def DegreeCurve(n, r, d = 1):
    for i in range(n):
        t.left(d)
        t.circle(r, abs(d))
    
#初始位置设定,对绘制的初始值进行相关设定
s = 0.2  #size
t.setup(450 * 5 * s, 750 * 5 * s)
t.pencolor('black')
t.fillcolor('red')
t.speed(100)
t.penup()
t.goto(0, 900 * s)
t.pendown()

#绘制花朵形状,此时开始绘制花的主体部分
t.begin_fill()
t.circle(200 * s, 30)
DegreeCurve(60, 50 * s)
t.circle(200 * s, 30)
DegreeCurve(4, 100 * s)
t.circle(200 * s, 50)
DegreeCurve(50, 50 *s)
t.circle(350 * s, 65)
DegreeCurve(40, 70 * s)
t.circle(150 *s, 50)
DegreeCurve(20, 50 *s, -1)
t.circle(400 * s, 60)
DegreeCurve(18, 50 * s)
t.fd(250 * s)
t.right(150)
t.circle(-500 * s, 12)
t.left(140)
t.circle(550 * s, 110)
t.left(27)
t.circle(650 * s, 100)
t.left(130)
t.circle(-300 * s, 20)
t.right(123)
t.circle(220 * s, 57)
t.end_fill()

#绘制花枝形状,绘制花的枝叶部分
t.left(120)
t.fd(280 * s)
t.left(115)
t.circle(300 * s, 33)
t.left(180)
t.circle(-300 * s, 33)
DegreeCurve(70, 225 * s, -1)
t.circle(350 * s, 104)
t.left(90)
t.circle(200 * s, 105)
t.circle(-500 * s, 63)
t.penup()
t.goto(170 * s, -30 * s)
t.pendown()
t.left(160)
DegreeCurve(20, 2500 * s)
DegreeCurve(220, 250 * s, -1)

#绘制一个绿色叶子
t.fillcolor('green')
t.penup()
t.goto(670 * s, -180 * s)
t.pendown()
t.right(140)
t.begin_fill()
t.circle(300 * s, 120)
t.left(60)
t.circle(300 * s, 120)
t.end_fill()
t.penup()
t.goto(180 * s, -550 * s)
t.pendown()
t.right(85)
t.circle(600 * s, 40)

#绘制另一个叶子
t.penup()
t.goto(-150 * s, -1000 * s)
t.pendown()
t.begin_fill()
t.rt(120)
t.circle(300 * s, 115)
t.left(75)
t.circle(300 * s, 100)
t.end_fill()
t.penup()
t.goto(430 * s, -1070 * s)
t.pendown()
t.right(30)
t.circle(-600 * s, 35)
t.done()

最后的效果图:
在这里插入图片描述
其实细心的朋友会发现这是一朵玫瑰😂只是画的位置不一样。。。

  1. 第三种: 卷心对称横叶玫
#第三种:画法的玫瑰没有第二种的好看
import turtle


def initialization():
    turtle.setup(width=0.9, height=0.9)
    turtle.speed(10)


def flower():
    turtle.goto(0, 200)
    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()


def peta1():
    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)


def peta2():
    turtle.left(180)
    turtle.circle(90, 40)
    turtle.circle(-80, 98)
    turtle.setheading(-83)


def leaf1():
    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)


def leaf2():
    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)


if __name__ == '__main__':
    initialization()
    flower()
    peta1()
    peta2()
    leaf1()
    leaf2()

最后的效果图:
在这里插入图片描述

  1. 最后一种:描边盛开火玫瑰
#下面看第四种:据说最好看
import turtle as t

t.setup(800,800)
t.hideturtle()
t.speed(11)
t.penup()
t.goto(50,-450)
t.pensize(5)
t.pencolor("black")
t.seth(140)
t.pendown()
t.speed(10)
t.circle(-300,60)
t.fd(100)
#jiaodu80
#1ye
t.seth(10)
t.fd(50)
t.fillcolor("green")
t.begin_fill()
t.right(40)
t.circle(120,80)
t.left(100)
t.circle(120,80)
t.end_fill()
t.seth(10)
t.fd(90)
t.speed(11)
t.penup()
t.fd(-140)
t.seth(80)
#2ye
t.pendown()
t.speed(10)
t.fd(70)
t.seth(160)
t.fd(50)
t.fillcolor("green")
t.begin_fill()
t.right(40)
t.circle(120,80)
t.left(100)
t.circle(120,80)
t.end_fill()
t.seth(160)
t.fd(90)
t.speed(11)
t.penup()
t.fd(-140)
t.seth(80)
t.pendown()
t.speed(10)
#
t.fd(100)
#1ban
t.seth(-20)
t.fillcolor("crimson")
t.begin_fill()
t.circle(100,100)
t.circle(-110,70)
t.seth(179)
t.circle(223,76)
t.end_fill()
#2ban
t.speed(11)
t.fillcolor("red")
t.begin_fill()

t.left(180)
t.circle(-223,60)
t.seth(70)
t.speed(10)
t.circle(-213,15)#55
t.left(70)#125
t.circle(200,70)
t.seth(-80)
t.circle(-170,40)
t.circle(124,94)
t.end_fill()
#
t.speed(11)
t.penup()
t.right(180)
t.circle(-124,94)
t.circle(170,40)
t.pendown()
t.speed(10)

t.seth(-60)
t.circle(175,70)

t.seth(235)
t.circle(300,12)
t.right(180)
t.circle(-300,12)

t.seth(125)
t.circle(150,60)

t.seth(70)
t.fd(-20)
t.fd(20)

t.seth(-45)
t.circle(150,40)
t.seth(66)
t.fd(-18.5)
t.fd(18.5)

t.seth(140)
t.circle(150,27)
t.seth(60)
t.fd(-8)

t.speed(11)
t.penup()
t.left(20.8)
t.fd(-250.5)

#3ban

t.pendown()
t.speed(10)
t.fillcolor("crimson")
t.begin_fill()
t.seth(160)

t.circle(-140,85)
t.circle(100,70)
t.right(165)
t.circle(-200,32)
t.speed(11)
t.seth(-105)
t.circle(-170,14.5)
t.circle(123,94)
t.end_fill()

最后的效果图:
在这里插入图片描述
综上,确实最后一种最好看!😄好了,玫瑰花get了,对象✔🐘在哪里?

PS:里面的代码参数可以自行修改,画出你要的形状
参考资料:
玫瑰花绘制

  • 17
    点赞
  • 80
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
### 回答1: 为了玫瑰花,您可以使用 Python 的绘图库如 Matplotlib。下面是一个简单的例子: ``` import numpy as np import matplotlib.pyplot as plt t = np.linspace(0, 2 * np.pi, 100) x = np.sin(t) y = np.cos(t) plt.plot(x, y) plt.show() ``` 这段代码定义了一个 $\theta$ 的变量 $t$,在 $[0, 2\pi]$ 范围内取 100 个值,然后根据 $\sin(\theta)$ 和 $\cos(\theta)$ 得到 $x$ 和 $y$ 坐标。最后使用 Matplotlib 库绘制出这些坐标对应的曲线。 ### 回答2: Python可以使用turtle模块来玫瑰花turtle模块是一种图形绘制工具,它可以帮助我们通过编程来控制一个小海龟的运动,进而出各种图形。 下面是用Python玫瑰花的代码示例: ```python import turtle # 设置布的大小和背景颜色 turtle.screensize(800, 600) turtle.bgcolor("black") # 设置笔的颜色和形状 turtle.color("red") turtle.shape("turtle") # 定义玫瑰花的函数 def draw_rose(): for i in range(180): # 设置笔的运动方向和速度 turtle.right(1) turtle.forward(2) turtle.right(90) turtle.forward(200) # 调用玫瑰花的函数 draw_rose() ``` 运行以上代码,就可以在turtle布上看到一个绘制的玫瑰花。其中,使用for循环来让海龟旋转180度,通过turtle.right()函数来控制旋转的角度,turtle.forward()函数来控制笔的运动距离,从而绘制出玫瑰花的形状。 这只是一个简单的示例,你也可以根据自己的需求和创造力来设计更加复杂和炫酷的玫瑰花图案。 ### 回答3: Python是一种功能强大的编程语言,可以用来绘制各种形状和图像,包括玫瑰花。要用Python绘制玫瑰花,我们可以使用turtle库来操作绘图窗口,并使用数学函数来计算绘制的路径。 首先,我们需要导入turtle库来绘制图形,并设置绘图窗口的大小和背景颜色。然后,我们可以定义一个函数来绘制玫瑰花的花瓣。在这个函数中,我们使用turtle的旋转和移动操作来绘制花瓣的形状,然后使用循环来重复绘制花瓣的数量。最后,我们可以调用这个函数来绘制整个玫瑰花。 下面是一个简单的示例代码: ``` import turtle import math # 设置绘图窗口的大小和背景颜色 turtle.setup(800, 600) turtle.bgcolor("black") # 定义绘制花瓣的函数 def draw_petal(): turtle.seth(60) # 设置绘制的初始角度 for i in range(2): turtle.circle(50, 60) # 绘制弧线 turtle.left(120) # 旋转角度 # 绘制玫瑰花 turtle.color("red") # 设置笔颜色为红色 turtle.speed(10) # 设置绘图速度为最快 for i in range(6): draw_petal() turtle.left(60) # 旋转角度 turtle.hideturtle() # 隐藏turtle.done() # 结束绘图 ``` 运行以上代码,就可以看到一个使用Python绘制的玫瑰花。代码中使用turtle库来操作绘图窗口,使用循环和数学函数来计算并绘制花瓣的形状,最后调用draw_petal函数和旋转操作来绘制整个玫瑰花。这只是一个简单的示例,你可以根据自己的需求和创意来进一步改进和美化玫瑰花的绘制效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值