[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] hoe to create the RoundRect ?
You can make images like that, you know. Then you can scale them to the size you need. I included a file containing a little script that makes a rounded rectangle. The theory of it is to draw various rects of different sizes in differing locations to approximate a curve. Then, filled rectangles are drawn inside of the others to take away the parts that are not needed. I'll see if I can clean it up a little later--I want to include it in PAdLib.
HTH
Ian
import pygame
from pygame.locals import *
import sys, os
if sys.platform == 'win32' or sys.platform == 'win64':
os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()
Screen = (800,600)
icon = pygame.Surface((1,1)); icon.set_alpha(0); pygame.display.set_icon(icon)
pygame.display.set_caption("Rounded Rectangle Demo - Ian Mallett - 2008")
Surface = pygame.display.set_mode(Screen)
def GetInput():
key = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == QUIT or key[K_ESCAPE]:
pygame.quit(); sys.exit()
def Draw():
Surface.fill((0,0,0))
BorderColor = (0,255,0)
FillColor = (0,0,0)
pygame.draw.rect(Surface,BorderColor,(15,15,200,200),1)
pygame.draw.rect(Surface,BorderColor,(16,14,198,202),1)
pygame.draw.rect(Surface,BorderColor,(14,16,202,198),1)
pygame.draw.rect(Surface,BorderColor,(19,13,192,204),1)
pygame.draw.rect(Surface,BorderColor,(13,19,204,192),1)
pygame.draw.rect(Surface,FillColor,(16,16,198,198),0)
pygame.draw.rect(Surface,FillColor,(17,15,196,200),0)
pygame.draw.rect(Surface,FillColor,(15,17,200,196),0)
pygame.draw.rect(Surface,FillColor,(20,14,190,202),0)
pygame.draw.rect(Surface,FillColor,(14,20,202,190),0)
pygame.display.flip()
def main():
while True:
GetInput()
Draw()
if __name__ == '__main__': main()