Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''File name: ICS Assignment- Drawing with pygame
- Author: Rayton Lin
- Teacher: Mr.Saleem
- Date created: March 25th, 2019
- Purpose: To use the built-in pygame functions to draw on the GUI.
- '''
- import pygame
- pygame.init()
- SIZE=(WIDTH,HEIGHT)=(400,400)
- RED=(255,0,0)
- GREEN=(0,255,0)
- BLUE=(0,0,255)
- WHITE=(255,255,255)
- CYAN=(0,255,255)
- YELLOW=(255,255,0)
- BLACK=(0,0,0)
- color=[0,0,0]
- clock=pygame.time.Clock()
- screen=pygame.display.set_mode(SIZE)
- pygame.display.set_caption("Drawing with pygame")
- screen.fill(CYAN)
- def drawSubfigure(numCircles,rows,columns,sizeofsubf,topleft):
- for i in range(rows):
- for j in range(columns):
- pygame.draw.rect(screen,GREEN,[topleft[0]+sizeofsubf[0]*i,topleft[1]+sizeofsubf[0]*j,sizeofsubf[0],sizeofsubf[1]])
- pygame.draw.circle(screen,YELLOW,[topleft[0]+sizeofsubf[0]*i+sizeofsubf[0]//2,topleft[1]+sizeofsubf[1]*j+sizeofsubf[1]//2],sizeofsubf[0]//2)
- pygame.draw.line(screen,BLACK,[topleft[0]+sizeofsubf[0]*i+sizeofsubf[0]//2,topleft[1]],[topleft[0]+sizeofsubf[0]*i+sizeofsubf[0]//2,topleft[1]+sizeofsubf[1]*j+sizeofsubf[1]],1) #Vertical Line
- pygame.draw.line(screen,BLACK,[topleft[0]+sizeofsubf[0]*i,topleft[1]+sizeofsubf[1]*j+sizeofsubf[1]//2],[topleft[0]+sizeofsubf[0]*i+sizeofsubf[0],topleft[1]+sizeofsubf[1]*j+sizeofsubf[1]//2],1) #Horizontal Line
- #Square side lines
- pygame.draw.line(screen,BLACK,[topleft[0]+sizeofsubf[0]*i,topleft[1]+sizeofsubf[1]*j],[topleft[0]+sizeofsubf[0]*(i+1),topleft[1]+sizeofsubf[1]*j],1) #Top Side
- pygame.draw.line(screen,BLACK,[topleft[0]+sizeofsubf[0]*i,topleft[1]+sizeofsubf[1]*(j+1)],[topleft[0]+sizeofsubf[0]*(i+1),topleft[1]+sizeofsubf[1]*(j+1)],1) #Bottom Side
- pygame.draw.line(screen,BLACK,[topleft[0]+sizeofsubf[0]*i,topleft[1]+sizeofsubf[1]*(j)],[topleft[0]+sizeofsubf[0]*i,topleft[1]+sizeofsubf[1]*(j+1)],1) #Left Side
- pygame.draw.line(screen,BLACK,[topleft[0]+sizeofsubf[0]*(i+1),topleft[1]+sizeofsubf[1]*(j)],[topleft[0]+sizeofsubf[0]*(i+1),topleft[1]+sizeofsubf[1]*(j+1)],1) #Right Side
- for k in range(numCircles): #Drawing the concentric circles
- pygame.draw.circle(screen,BLACK,[topleft[0]+sizeofsubf[0]*i+sizeofsubf[0]//2,topleft[1]+sizeofsubf[1]*j+sizeofsubf[1]//2],(sizeofsubf[1]//2)*(k+1)//numCircles,1)
- running=True
- while running:
- clock.tick(1)
- #Event loop
- #Game Logic section
- #Draw section
- drawSubfigure(5,1,1,[100,100],[0,0]) #Top Left
- drawSubfigure(4,5,5,[24,24],[10,120]) #Bottom Left
- drawSubfigure(5,6,6,[40,40],[150,20]) #Top Right
- drawSubfigure(3,3,3,[36,36],[130,275]) #Bottom Right
- pygame.display.flip()
- '''
- '''File name: ICS Assignment- Drawing with pygame
- Author: Rayton Lin
- Teacher: Mr.Saleem
- Date created: March 25th, 2019
- Purpose: To use the built-in pygame functions to draw on the GUI.
- '''
- import pygame
- pygame.init()
- SIZE=(WIDTH,HEIGHT)=(400,400)
- RED=(255,0,0)
- GREEN=(0,255,0)
- BLUE=(0,0,255)
- WHITE=(255,255,255)
- CYAN=(0,255,255)
- YELLOW=(255,255,0)
- BLACK=(0,0,0)
- color=[0,0,0]
- screen=pygame.display.set_mode(SIZE)
- pygame.display.set_caption("Drawing with pygame")
- screen.fill(CYAN)
- '''
- def drawCircles(numCircles):
- for k in range(numCircles): #Drawing the concentric circles
- pygame.draw.circle(screen,BLACK,[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]+sizeOfSubF[1]//2],(sizeOfSubF[1]//2)*(k+1)//numCircles,1)
- '''
- def drawBackground(sizeOfSubF,topLeft):
- #Drawing backgrounds
- pygame.draw.rect(screen,GREEN,[topLeft[0],topLeft[1],sizeOfSubF[0],sizeOfSubF[1]]) #Green Square Background
- pygame.draw.circle(screen,YELLOW,[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]+sizeOfSubF[1]//2],sizeOfSubF[0]//2) #Yellow Circle Background
- #Drawing vertical and horizontal axes
- pygame.draw.line(screen,BLACK,[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]],[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]+sizeOfSubF[1]],1) #Vertical Line
- pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]+sizeOfSubF[1]//2],[topLeft[0]+sizeOfSubF[0],topLeft[1]+sizeOfSubF[1]//2],1) #Horizontal Line
- #Square side lines
- pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]],[topLeft[0]+sizeOfSubF[0],topLeft[1]],1) #Top Side
- pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]+sizeOfSubF[1]],[topLeft[0]+sizeOfSubF[0],topLeft[1]+sizeOfSubF[1]],1) #Bottom Side
- pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]],[topLeft[0],topLeft[1]+sizeOfSubF[1]],1) #Left Side
- pygame.draw.line(screen,BLACK,[topLeft[0]+sizeOfSubF[0],topLeft[1]],[topLeft[0]+sizeOfSubF[0],topLeft[1]+sizeOfSubF[1]],1) #Right Side
- def drawFigures(numCircles,rows,columns,sizeOfSubF,topLeft):
- currentTopLeft=topLeft[:]
- for i in range(rows+1):
- for j in range(columns):
- drawBackground(sizeOfSubF,currentTopLeft)
- currentTopLeft[1]=topLeft[1]+sizeOfSubF[1]*j
- for k in range(numCircles): #Drawing the concentric circles
- pygame.draw.circle(screen,BLACK,[currentTopLeft[0]+sizeOfSubF[0]//2,currentTopLeft[1]+sizeOfSubF[1]//2],(sizeOfSubF[1]//2)*(k+1)//numCircles,1)
- currentTopLeft[0]=topLeft[0]+sizeOfSubF[0]*i
- #Draw section
- drawFigures(5,1,1,[100,100],[0,0]) #Top Left
- drawFigures(4,5,5,[24,24],[10,120]) #Bottom Left
- drawFigures(5,6,6,[40,40],[150,20]) #Top Right
- drawFigures(3,3,3,[36,36],[130,275]) #Bottom Right
- pygame.display.flip()
- '''
Add Comment
Please, Sign In to add comment