用pygame绘制对角椭圆 [英] drawing a diagonal ellipse with pygame

查看:82
本文介绍了用pygame绘制对角椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道绘制不与 x & 对齐的椭圆的简单方法吗?y 轴.我对 pygame 很陌生,所以请原谅我的无知,但我找不到任何与之相关的内容.

Does anyone know of an easy way to draw ellipses that are not aligned to the x & y axis. I am very new to pygame so please forgive my ignorance, but I cannot find anything related to it.

如果没有简单的方法存在,除了在椭圆上生成许多点并绘制所有点之外,有人可以帮助我如何绘制它吗?

If no easy method exists, can someone help me in how I might draw this besides generating many many points on the ellipse and plotting all of them?

推荐答案

你可以这样做.创建一个曲面,将椭圆绘制到该曲面上,然后旋转整个曲面(椭圆在其上).这是我的测试代码:

You can do that. Create a surface, draw the ellipse onto that surface and then rotate the entire surface (with the ellipse on it). Here's my test code:

import pygame, sys

screen = pygame.display.set_mode((1024, 640))

running = True

#let's create a surface to hold our ellipse:
surface = pygame.Surface((320, 240))

red = (180, 50, 50)
size = (0, 0, 300, 200)

#drawing an ellipse onto the 
ellipse = pygame.draw.ellipse(surface, red, size)

#new surface variable for clarity (could use our existing though)
#we use the pygame.transform module to rotate the original surface by 45°
surface2 = pygame.transform.rotate(surface, 45)

while running:
    screen.fill((255, 250, 200))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    screen.blit(surface2, (100, 100))
    pygame.display.update()

结果将是一个旋转的椭圆.可以使椭圆的保持器"透明.检查模块上的文档:

The result will be a rotated ellipse. It would be possible to make the "holder" of the ellipse transparent. Check the documentations on the modules:

http://www.pygame.org/docs/ref/transform.html#pygame.transform.rotate

http://www.pygame.org/docs/ref/surface.html

希望有帮助!

这篇关于用pygame绘制对角椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆