[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Tiling a Rotated Bitmap
Well, that was interesting, but also didn't work. It's similar to my
attempt of tiling then rotating then cutting a piece out of the middle.
I've modified the code to show what happens when that tile is tiled.
Interesting, tho!
--Kamilche
import pygame
import math
filename=r"G:\Incarnation\Models\Textures\test.png"
SCREENWIDTH = 800
SCREENHEIGHT = 600
def Rotated(surf, degrees = 0):
# rotate surface
rotsurf = pygame.transform.rotozoom(surf, degrees, 1)
# compute the offsets needed
c = math.cos(math.radians(degrees))
s = math.sin(math.radians(degrees))
widthx = (surf.get_width() - 1) * c
widthy = (surf.get_width() - 1) * s
heightx = (surf.get_height() - 1) * s
heighty = (surf.get_height() - 1) * c
# the 8 positions, corners first
positions = [
(widthx, -widthy),
(-widthx, widthy),
(heightx, heighty),
(-heightx, -heighty),
]
rot_copy = rotsurf.copy()
# apply the blits
for pos in positions:
rotsurf.blit(rot_copy, pos)
return rotsurf
def Tile(surf, pic, rect):
x = rect[0]
y = rect[1]
while y < rect[3]:
x = 0
while x < rect[2]:
surf.blit(pic, [x, y])
x += pic.get_width()
y += pic.get_height()
def main():
pygame.init()
bg = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT), 0, 32)
quit = 0
pic = pygame.image.load(filename).convert_alpha()
pic2 = pic
while not quit:
bg.fill((255, 0, 0, 255))
bg.blit(pic2, (0, 0))
Tile(bg, pic2, [0, 200, 512, 512])
pygame.display.flip()
for e in pygame.event.get():
if e.type == pygame.QUIT:
quit = 1
break
elif e.type == pygame.MOUSEMOTION:
pic2 = Rotated(pic, e.pos[0])
pygame.quit()
main()