954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Filling objects with colour

how do you fill an object such as a rectangle with a colour using setfillstyle(); ?? I dont want to use flood fill as i am having more problems with that..

joydsouza90
Light Poster
25 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 
how do you fill an object such as a rectangle with a colour using setfillstyle(); ?? I dont want to use flood fill as i am having more problems with that..


You don't. setfillstyle() simplysets the type of fill. You still need a function that actually performs the filling, like floodfill() or fillpoly() .

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

use
'bar()' to draw a rectangle !

apurv
Light Poster
45 posts since Jan 2007
Reputation Points: 9
Solved Threads: 3
 

Plz help

import pygame
from pygame.locals import *
import sys

White=(255, 255, 255)
Yellow=(255, 255, 0)
#WIDTH=848
#HEIGHT=640
IMAGE="baby.jpg"
graphic = pygame.image.load(IMAGE)
screen = pygame.display.set_mode((graphic.get_width(),graphic.get_height()))
graphic=graphic.convert()
pygame.display.set_caption('Coloring')
screen.blit(graphic, (0, 0))
pygame.display.flip()
mousex = 0
mousey = 0

def flood(oldcolour,newColour,x,y):
    workpile=[]
    workpile.append((x,y))
    while len(workpile)> 0:
        x,y=workpile[0]
	del workpile[0]
        if graphic.get_at((x,y))==oldcolour:
            graphic.set_at((x,y),newColour)
            if graphic.get_at((x-1,y))==oldcolour and x-1>0 and x-1<graphic.get_width()and y>0 and y<graphic.get_height()-1:
		    print x,y
		    workpile.append((x-1,y))
            if graphic.get_at((x+1,y))==oldcolour and x+1>0 and x+1<graphic.get_width() and y>0 and y<graphic.get_height()-1:
		    workpile.append((x+1,y))
		    print x,y
            if graphic.get_at((x,y-1))==oldcolour and y-1>0 and y-1<graphic.get_height()-1 and x>0 and x< graphic.get_width()-1:
		    workpile.append((x,y-1))
		    print x,y
            if graphic.get_at((x,y+1))==oldcolour and y+1>0 and y+1<graphic.get_height()-1 and x>0 and x<graphic.get_width():
		    print x,y
		    workpile.append((x,y+1))
while True:
	for event in pygame.event.get():
		if event.type == QUIT:
			pygame.quit()
			sys.exit()
            	if event.type == MOUSEBUTTONUP:
            	    	mousex, mousey = event.pos
			print mousex,mousey
			flood(White,Yellow,mousex,mousey)
			pygame.display.update()
		screen.blit(graphic,(0, 0)) #Display image at 0, 0
		pygame.display.flip()#Update screen
007himanshujain
Newbie Poster
1 post since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You