当前位置:网站首页>pygame图像连续旋转
pygame图像连续旋转
2022-08-02 14:09:00 【天山没有长寿茶】
我们通过搜索可以知道pygame中关于图像旋转的方法是pygame.transform.rotate(),但是在实际使用中,我们会发现如果我们要连续旋转一个物体,简单地使用这个方法会导致图像扭曲变形,最后完全丧失了本来的样子。
经过研究发现图像扭曲的原因就是每次使用上面方法旋转之后,图像的中心点会发生变化,所以我们的解决方案是在每次旋转的时候设置旋转中心不变。代码如下:
x = 0
y = 0
# 导入原始图像
image_raw = pygame.image.load("your image").convert_alpha()
# 设置旋转中心
core = (x,y)
# 设置角度(0~360)
angle = 60
# 旋转图像
image = pygame.transform.rotate(image_raw, angle)
# 绘制图像,并且设置中心位置,注意这里中心一定要是元组tuple
self.screen.blit(image, image.get_rect(center=tuple(core)))
如果我们需要连续旋转以及改变转转中心位置,调整core与angle的值即可。注意angle的范围用的是角度制(0~360)
边栏推荐
- The overlapping effect of the two surfaceviews is similar to the video and handout practice in the live effect
- How to update Win11 sound card driver?Win11 sound card driver update method
- Do Windows 10 computers need antivirus software installed?
- yolov5官方代码解读——前向传播
- Spark及相关生态组件安装配置——快速回忆
- Win10 Settings screen out from lack of sleep?Win10 set the method that never sleep
- FP7195转模拟恒流调光芯片在机器视觉光源的应用优势
- 内存申请(malloc)和释放(free)之下篇
- 2021-10-14
- Win10 cannot directly use photo viewer to open the picture
猜你喜欢
随机推荐
Win11没有本地用户和组怎么解决
source /build/envsetup.sh和lunch)
使用 腾讯云搭建一个个人博客
【我的电赛日记(一)】HMI USART串口屏
Impressions of Embrace Jetpack
Win10 Settings screen out from lack of sleep?Win10 set the method that never sleep
DP4344兼容CS4344-DA转换器
机器学习---监督学习、无监督学习
Tensorflow常用函数
图像配置分类及名词解释
使用预训练语言模型进行文本生成的常用微调策略
GICv3/v4-软件概述
【深度学习中的损失函数整理与总结】
LORA芯片ASR6601支持M4内核的远距离传输芯片
PHY6222蓝牙5.2支持MESH组网M0内核超低功耗
vscode镜像
2022TI杯D题混沌信号产生实验装置
ECP2459耐压60V降压BUCK电路用于WIFI模块供电方案原理图
基于深度学习的配准框架
LeetCode2 电话号码的字母组合