Ilikebugs

Drawing with Pygame Assignment

Mar 28th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.54 KB | None | 0 0
  1. '''File name: ICS Assignment- Drawing with pygame
  2. Author: Rayton Lin
  3. Teacher: Mr.Saleem
  4. Date created: March 25th, 2019
  5. Purpose: To use the built-in pygame functions to draw on the GUI.
  6. '''
  7. import pygame
  8. pygame.init()
  9.  
  10. SIZE=(WIDTH,HEIGHT)=(400,400)
  11.  
  12. RED=(255,0,0)
  13. GREEN=(0,255,0)
  14. BLUE=(0,0,255)
  15. WHITE=(255,255,255)
  16. CYAN=(0,255,255)
  17. YELLOW=(255,255,0)
  18. BLACK=(0,0,0)
  19. color=[0,0,0]
  20.  
  21. clock=pygame.time.Clock()
  22. screen=pygame.display.set_mode(SIZE)
  23. pygame.display.set_caption("Drawing with pygame")
  24.  
  25. screen.fill(CYAN)
  26.  
  27.  
  28. def drawSubfigure(numCircles,rows,columns,sizeofsubf,topleft):
  29.     for i in range(rows):
  30.         for j in range(columns):
  31.             pygame.draw.rect(screen,GREEN,[topleft[0]+sizeofsubf[0]*i,topleft[1]+sizeofsubf[0]*j,sizeofsubf[0],sizeofsubf[1]])
  32.             pygame.draw.circle(screen,YELLOW,[topleft[0]+sizeofsubf[0]*i+sizeofsubf[0]//2,topleft[1]+sizeofsubf[1]*j+sizeofsubf[1]//2],sizeofsubf[0]//2)
  33.             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
  34.             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
  35.             #Square side lines
  36.             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
  37.             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
  38.             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
  39.             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
  40.             for k in range(numCircles): #Drawing the concentric circles
  41.                 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)
  42.                
  43.            
  44.                
  45.        
  46.  
  47. running=True
  48. while running:
  49.     clock.tick(1)
  50.     #Event loop
  51.    
  52.  
  53.     #Game Logic section
  54.    
  55.  
  56.     #Draw section
  57.     drawSubfigure(5,1,1,[100,100],[0,0]) #Top Left
  58.  
  59.     drawSubfigure(4,5,5,[24,24],[10,120]) #Bottom Left
  60.  
  61.     drawSubfigure(5,6,6,[40,40],[150,20]) #Top Right
  62.  
  63.     drawSubfigure(3,3,3,[36,36],[130,275]) #Bottom Right
  64.     pygame.display.flip()
  65.  
  66. '''
  67. '''File name: ICS Assignment- Drawing with pygame
  68. Author: Rayton Lin
  69. Teacher: Mr.Saleem
  70. Date created: March 25th, 2019
  71. Purpose: To use the built-in pygame functions to draw on the GUI.
  72. '''
  73. import pygame
  74. pygame.init()
  75.  
  76. SIZE=(WIDTH,HEIGHT)=(400,400)
  77.  
  78. RED=(255,0,0)
  79. GREEN=(0,255,0)
  80. BLUE=(0,0,255)
  81. WHITE=(255,255,255)
  82. CYAN=(0,255,255)
  83. YELLOW=(255,255,0)
  84. BLACK=(0,0,0)
  85. color=[0,0,0]
  86.  
  87. screen=pygame.display.set_mode(SIZE)
  88. pygame.display.set_caption("Drawing with pygame")
  89. screen.fill(CYAN)
  90.  
  91. '''
  92. def drawCircles(numCircles):
  93.     for k in range(numCircles): #Drawing the concentric circles
  94.         pygame.draw.circle(screen,BLACK,[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]+sizeOfSubF[1]//2],(sizeOfSubF[1]//2)*(k+1)//numCircles,1)
  95.      '''          
  96. def drawBackground(sizeOfSubF,topLeft):
  97.    #Drawing backgrounds
  98.    pygame.draw.rect(screen,GREEN,[topLeft[0],topLeft[1],sizeOfSubF[0],sizeOfSubF[1]]) #Green Square Background
  99.    pygame.draw.circle(screen,YELLOW,[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]+sizeOfSubF[1]//2],sizeOfSubF[0]//2) #Yellow Circle Background
  100.    #Drawing vertical and horizontal axes
  101.    pygame.draw.line(screen,BLACK,[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]],[topLeft[0]+sizeOfSubF[0]//2,topLeft[1]+sizeOfSubF[1]],1) #Vertical Line
  102.    pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]+sizeOfSubF[1]//2],[topLeft[0]+sizeOfSubF[0],topLeft[1]+sizeOfSubF[1]//2],1) #Horizontal Line
  103.    #Square side lines
  104.    pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]],[topLeft[0]+sizeOfSubF[0],topLeft[1]],1) #Top Side
  105.    pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]+sizeOfSubF[1]],[topLeft[0]+sizeOfSubF[0],topLeft[1]+sizeOfSubF[1]],1) #Bottom Side
  106.    pygame.draw.line(screen,BLACK,[topLeft[0],topLeft[1]],[topLeft[0],topLeft[1]+sizeOfSubF[1]],1) #Left Side
  107.    pygame.draw.line(screen,BLACK,[topLeft[0]+sizeOfSubF[0],topLeft[1]],[topLeft[0]+sizeOfSubF[0],topLeft[1]+sizeOfSubF[1]],1) #Right Side
  108.  
  109.    
  110. def drawFigures(numCircles,rows,columns,sizeOfSubF,topLeft):
  111.    currentTopLeft=topLeft[:]
  112.    for i in range(rows+1):
  113.        for j in range(columns):
  114.            drawBackground(sizeOfSubF,currentTopLeft)
  115.            currentTopLeft[1]=topLeft[1]+sizeOfSubF[1]*j
  116.            for k in range(numCircles): #Drawing the concentric circles
  117.                pygame.draw.circle(screen,BLACK,[currentTopLeft[0]+sizeOfSubF[0]//2,currentTopLeft[1]+sizeOfSubF[1]//2],(sizeOfSubF[1]//2)*(k+1)//numCircles,1)
  118.        currentTopLeft[0]=topLeft[0]+sizeOfSubF[0]*i
  119.                    
  120.  
  121.            
  122.            
  123.                
  124.        
  125.  
  126.  
  127. #Draw section
  128. drawFigures(5,1,1,[100,100],[0,0]) #Top Left
  129.  
  130. drawFigures(4,5,5,[24,24],[10,120]) #Bottom Left
  131.  
  132. drawFigures(5,6,6,[40,40],[150,20]) #Top Right
  133.  
  134. drawFigures(3,3,3,[36,36],[130,275]) #Bottom Right
  135. pygame.display.flip()
  136.  
  137. '''
Add Comment
Please, Sign In to add comment