用python 画太阳_Python PIL画一个太阳神的圆圈

这里有一个小功能可以调整import Image, ImageDraw

from math import sin, cos, pi

width, height = 400, 400

skyBlue = (135, 206, 235)

im = Image.new("RGBA", (width, height), skyBlue)

#Draw Sun

draw = ImageDraw.Draw(im)

def drawSun(draw, centre, radius, rays=False, startAngle=0, finishAngle=360, rayAngle=10, rayGap=10, rayLength=1000, rayColour="Yellow", rayOutline="Orange"):

x1,x2 = centre[0] - radius, centre[0] + radius

y1,y2 = centre[1] - radius, centre[1] + radius

if rays:

for rayStart in range(startAngle, finishAngle, rayAngle+rayGap):

rayEnd = (rayStart+rayAngle) * pi/180

rayStart *= pi/180

corner1 = centre[0] + rayLength*cos(rayStart), centre[1] + rayLength*sin(rayStart)

corner2 = centre[0] + rayLength*cos(rayEnd), centre[1] + rayLength*sin(rayEnd)

print [centre, corner1, corner2]

draw.polygon([centre, corner1, corner2], fill="Yellow", outline="Orange")

draw.ellipse((x1, y1, x2, y2), fill="Yellow", outline="Orange")

drawSun(draw, (100, 100), 40, rays=True, startAngle=0, finishAngle=145, rayAngle=3, rayGap=5)

im.save("example.png")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,作为一名语言模型,我没有绘功能。但我可以为您提供一些使用Python绘制图像的库和代码示例。 1. PILPILPython Imaging Library)是Python图像处理库,可以使用它来创建和修改图像。以下是绘制一个简单的洛天依图像的示例代码: ```python from PIL import Image, ImageDraw # create a new image with a white background img = Image.new('RGB', (400, 400), color='white') # create a draw object draw = ImageDraw.Draw(img) # draw the head draw.ellipse((100, 50, 300, 250), fill='pink', outline='black') # draw the eyes draw.ellipse((150, 100, 170, 120), fill='black') draw.ellipse((230, 100, 250, 120), fill='black') # draw the mouth draw.arc((150, 150, 250, 200), start=190, end=350, fill='black', width=5) # save the image img.save('luotianyi.png') ``` 2. Turtle库 Turtle是Python标准库中的一个绘图库,使用它可以绘制各种形状和图案。以下是使用Turtle库绘制一个洛天依图像的示例代码: ```python import turtle # create a turtle object t = turtle.Turtle() # set the fill color and draw the head t.fillcolor('pink') t.begin_fill() t.circle(100) t.end_fill() # move to the first eye position and draw the eyes t.penup() t.goto(-50, 50) t.pendown() t.fillcolor('black') t.begin_fill() t.circle(20) t.end_fill() t.penup() t.goto(50, 50) t.pendown() t.fillcolor('black') t.begin_fill() t.circle(20) t.end_fill() # move to the mouth position and draw the mouth t.penup() t.goto(-50, -20) t.pendown() t.pensize(5) t.setheading(45) t.circle(70, -90) # hide the turtle t.hideturtle() # save the image turtle.getcanvas().postscript(file='luotianyi.eps') ``` 以上是两个使用Python绘制图像的示例,希望能对您有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值