python画椭圆、星形线、菱形、圆角矩形

目录

1、代码

2、结果


1、代码

import numpy as np
import matplotlib.pyplot as plt
def normp(num:int,ntype:int):
    delta = 2/(2*num)
    points1=np.zeros((2*(2*num+1),2),dtype=np.float64)
    points=np.zeros(((2*num+1),2),dtype=np.float64)
    for i in range(2*num+1):
        points[i,0] = -1.0+delta*i
        #points[i+2*num+1,0] = -1+delta*i
        points[i,1] = (1-(np.abs(-1+delta*i))**ntype)**(1./ntype)
        #points[i+2*num+1,1] = -(1-(np.abs(-1+delta*i))**ntype)**(1./ntype)
    points1[:2*num+1,0]=points[:,0]
    points1[2*num+1:,0] =points[:,0]
    #points1[:2*num+1,1]=points[:,1]
    #points1[2*num+1:,1] =-1*points[:,1]
    x=points[:,0]
    y=points[:,1]
    return [x,y]

def main():
    fig=plt.figure()
    num = 1024
    


    axes=fig.add_subplot(221)
    ntype =0.5
    [x,y] = normp(num,ntype)
    axes.plot(x,y,color='b')
    axes.plot(x,-1*y,color='b')
    axes=fig.add_subplot(222)
    ntype =1
    [x,y] = normp(num,ntype)
    axes.plot(x,y,color='b')
    axes.plot(x,-1*y,color='b')
    axes=fig.add_subplot(223)
    ntype =2
    [x,y] = normp(num,ntype)
    axes.plot(x,y,color='b')
    axes.plot(x,-1*y,color='b')
    axes=fig.add_subplot(224)
    ntype =5
    [x,y] = normp(num,ntype)
    axes.plot(x,y,color='b')
    axes.plot(x,-1*y,color='b')
    axes.axis('equal')
    plt.show()
    

if __name__ == '__main__':
    main()




2、结果

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在Python圆角矩形,可以使用Python的turtle或者pygame模块。下面是使用pygame模块圆角矩形的示例代码: ```python import pygame pygame.init() screen = pygame.display.set_mode((400, 400)) pygame.display.set_caption("Round Rectangle") def round_rect(x, y, width, height, radius, color): # 创建一个矩形对象 rect = pygame.Rect(x, y, width, height) # 创建一个矩形对象,用于绘制圆角 corner = pygame.Rect(0, 0, radius*2, radius*2) # 将圆角矩形分为四个部分 top_left = corner.copy() top_right = corner.copy() bottom_left = corner.copy() bottom_right = corner.copy() # 将圆角矩形的四个角都绘制成圆形 top_left.center = rect.topleft top_right.center = rect.topright bottom_left.center = rect.bottomleft bottom_right.center = rect.bottomright # 绘制圆角矩形 pygame.draw.rect(screen, color, rect) pygame.draw.circle(screen, color, top_left.center, radius) pygame.draw.circle(screen, color, top_right.center, radius) pygame.draw.circle(screen, color, bottom_left.center, radius) pygame.draw.circle(screen, color, bottom_right.center, radius) # 绘制一个红色的圆角矩形 round_rect(100, 100, 200, 100, 20, (255, 0, 0)) pygame.display.update() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() ``` 这段代码使用了pygame.Rect对象来表示圆角矩形圆角。使用pygame.draw.rect方法和pygame.draw.circle方法来绘制圆角矩形。你可以根据需要调整圆角矩形的位置、大小、圆角半径和颜色等参数。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荔枝科研社

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值