# File: Xiang/colorsRand.py # 500 Random colored circles # mycolor = color_rgb(r,g,b) # mix your own color """255 240 245 lavender blush 255 240 245 LavenderBlush 255 228 225 misty rose 255 228 225 MistyRose 255 255 255 white 0 0 0 black 47 79 79 dark slate gray 47 79 79 DarkSlateGray 47 79 79 dark slate grey 47 79 79 DarkSlateGrey 105 105 105 dim gray 105 105 105 DimGray 105 105 105 dim grey 105 105 105 DimGrey 112 128 144 slate gray 112 128 144 SlateGray 112 128 144 slate grey 112 128 144 SlateGrey 119 136 153 light slate gray 119 136 153 LightSlateGray """ from graphics import * import random WinXBR = 700 # window geometry WinYBR = 500 #---------------------------------------------------------------- # waitForClick: stops the GUI and displays a message. Returns # when the user has clicked the window, and # erases the message. # nothing returned #---------------------------------------------------------------- def waitForClick( win, message ): # wait for user to click mouse to start startMsg = Text( Point( WinXBR/2, WinYBR/2 ), message ) # message in the middle startMsg.draw( win ) # display message p = win.getMouse() # wait startMsg.undraw() # erase return p #---------------------------------------------------------------- #---------------------------------------------------------------- def main(): win = GraphWin( "Random colored circles", WinXBR, WinYBR ) waitForClick( win, "Click mouse to start" ) for i in range( 500 ): x=random.randint(7,690) # choose random center of the circle y=random.randint(7,490) c = Circle(Point(x,y) , 5 ) # make a circle radius 5 r=random.randint(0, 255) # RED Integer from 0 to 255 g=random.randint(0, 255) # GREEN Integer from 0 to 255 b=random.randint(0, 255) # BLUE Integer from 0 to 255 mycolor = color_rgb(r,g,b) # mix your own color c.setFill( mycolor ) # c.setFill("MistyRose") c.draw( win ) # draw circle with random color waitForClick( win, "Click mouse to stop" ) win.close() main()