spygame

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import sys

from random import randint, seed

import pygame

from pygame.locals import *

SCREEN_X = 640

SCREEN_Y = 480

pygame.init()

def convert_strs_to_color(color_list):

return Color(int(color_list[0]), int(color_list[1]), int(color_list[2]))

//画圆方法

def draw_circle(surface, color):

radius = randint(10, 100)

pos = (randint(radius, SCREEN_X-radius), randint(radius, SCREEN_Y-radius))

pygame.draw.circle(surface, color, pos, radius, 1)

//画长方形方法

def draw_rectangle(surface, color):

height = randint(10, 100)

width = randint(20, 250)

left = randint(0, SCREEN_X-width)

top = randint(0, SCREEN_Y-height)

pygame.draw.rect(surface, color, (left, top, width, height), 1)

//画线方法

def draw_line(surface, color):

start_pos = (randint(0, SCREEN_X), randint(0, SCREEN_Y))

while True:

end_pos = (randint(0, SCREEN_X), randint(0, SCREEN_Y))

# make sure they are not on same spot

if end_pos != start_pos:

break

填充区域

Surface.fill方法可以用一种颜色填充一个矩形区域。比如

surface.fill((255,0,0), (100, 200, 100, 100))

第一个参数指定要填充的颜色,第二个参数指定填充的矩形区域。如果没有给定第二个参数,整个Surface会被填充。第二个参数会限制备填充的区域。这个函数会返回受影响的Surface区域。

/blog/static/483763592010386487676/