Tuesday, March 24, 2020

pygame colour filling in python


import pygame, sys
from pygame.locals import *
pygame.init()
displaysurf=pygame.display.set_mode((800,400),0,32)
pygame.display.set_caption('Drawing!')
#setup colour
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
SILVER = (192, 192, 192)
PINK=(255,105,180)

displaysurf.fill(WHITE)
pygame.draw.line(displaysurf, BLUE, [0, 0], [100, 100], 30)
pygame.draw.line(displaysurf, BLUE, [0, 0], [100, 100], 10)

#pygame.draw.line(displaysurf, GREEN, [0, 0], [60, 100], 5)
pygame.draw.line(displaysurf, GREEN, [0, 0], [0, 400], 100)
pygame.draw.line(displaysurf, RED, [100,0], [100, 400], 100)
pygame.draw.line(displaysurf, BLACK, [300,0], [300, 400], 100)
pygame.draw.line(displaysurf, BLUE, [400,0], [400, 400], 100)
pygame.draw.line(displaysurf, GREEN, [500, 0], [500, 400], 100)
pygame.draw.line(displaysurf, PINK, [600,0], [600, 400], 100)
pygame.draw.line(displaysurf, SILVER, [700,0], [700, 400], 100)
pygame.draw.line(displaysurf, BLUE, [800,0], [800, 400], 100)


pixobj=pygame.PixelArray(displaysurf)
pixobj[480][380]=BLACK
pixobj[482][382]=BLACK
pixobj[484][384]=BLACK
pixobj[486][386]=BLACK
pixobj[488][388]=BLACK
del pixobj


while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
           
    pygame.display.update()

output:


No comments:

Post a Comment

python class topic video