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..

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() simply sets the type of fill. You still need a function that actually performs the filling, like floodfill() or fillpoly() .

use
'bar()' to draw a rectangle !

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.