最近很火一些简单图形构成的小游戏,这里介绍一些绘制图形的函数。
1.绘制矩形
rect(Surface,color,Rect,width=0)
第一个参数指定矩形绘制到哪个Surface对象上
第二个参数指定颜色
第三个参数指定矩形的范围(left,top,width,height)
第四个参数指定矩形边框的大小(0表示填充矩形)
例如绘制三个矩形:
pygame.draw.rect(screen, BLACK, (50, 50, 150, 50), 0) pygame.draw.rect(screen, BLACK, (250, 50, 150, 50), 1) pygame.draw.rect(screen, BLACK, (450, 50, 150, 50), 10)
2.绘制多边形
polygon(Surface,color,pointlist,width=