1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #Author:ss4 5 ImportPygame6 ImportSYS7 8 #Initialize9 Pygame.init ()Ten OneSize = Width,height = 1000,600#Set Screen Size ABLUE = 0,0,255 -White = 255,255,255 -BLACK =0,0,0 theRED = 255, 0,0 -GREEN = 0,255, 0 - -Screen = Pygame.display.set_mode (size)#Create a Surface object +Pygame.display.set_caption ('drawing round and dragging')#Create a title - + #Center Position Definition APosition = size[0]//2, size[1]//2 at -moving =False - - whileTrue: - forEventinchpygame.event.get (): - ifEvent.type = =Pygame. QUIT: in sys.exit () - ifEvent.type = = Pygame. Mousebuttondown:#get mouse click events to ifEvent.button = = 1:#Click the left mouse button +moving =True - ifEvent.type = = Pygame. Mousebuttonup:#get release mouse event the ifEvent.button = = 1:#release the left mouse button *moving =False $ ifMoving:Panax NotoginsengPosition = Pygame.mouse.get_pos ()#Update Center position is the current position of the mouse - the + AScreen.fill (White)#Fill Screen the #draw a circle of various size colors +Pygame.draw.circle (screen,blue,position,30,1) -Pygame.draw.circle (screen, BLACK, Position, 50, 1) $Pygame.draw.circle (screen, RED, Position, 80, 1) $Pygame.draw.circle (screen, GREEN, position, 120, 1) - #Refresh Screen -Pygame.display.flip ()
Python game pygame Module Drawing Circle and moving method introduction