画圆、线、矩形
# Listing_16-3_drawing_a_circle.py
# Copyright Warren & Carter Sande, 2009-2019
# Released under MIT license https://opensource.org/licenses/mit-license.php
# ------------
import pygame, sys
import time
import numpy as np
from math import pi,sin,cos
pygame.init()
screen = pygame.display.set_mode([1100,650])
# Add these three lines
screen.fill([255,255,255]) # Fills the window with a white background
r = 200
pygame.draw.circle(screen, [255,0,0],[250,250], r, 1) # Draws a circle
pygame.draw.lines(screen, [255,0,0],False,[[250,250],[250+r*sin(0/3.0*pi),250+r*cos(0/3.0*pi)]], 1) # Draws a line
pygame.draw.lines(screen, [255,0,0],False,[[250,250],[250+r*sin(2/3.0*pi),250+r*cos(2/3.0*pi)]], 1) # Draws a line
pygame.draw.lines(screen, [255,0,0],False,[[250,250],[250+r*sin(4/3.0*pi),250+r*cos(4/3.0*pi)]], 1) # Draws a line
# Flips your monitor over … just kidding!
running = True
t = 0
K= 6
k_user = [k for k in range(K)]
ci=255
k_color = [[ci,0,0],[0,ci,0],[0,0,0],[0,0,ci], [0,ci,ci],[ci,0,ci],[ci,ci,0]];# colors for each user
k_Points=[[] for k in range(K)]
ks = 6 # user size
k0=[]
v = 1
for i in range(K):
x=int(5*(np.random.random(1)[0])*10)
y= int(50*(np.random.random(1)[0])*10)
k0.append([x,y])
pygame.draw.rect(screen, k_color[i], [x, y, ks, ks], 0) # Add code for y-speed (vertical motion)
print(k0)
pygame.display.flip()
t=0
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.time.delay(200)
t = t+1
for i in range(K):
# print(i)
x=k0[i][0]+ t*10
y= k0[i][1]
#k0.append([x,y])
pygame.draw.rect(screen, k_color[i], [x, y, ks, ks], 0) # Add code for y-speed (vertical motion)
pygame.display.flip()
pygame.quit()
当参数为0,代表填充。参数为其他代表线宽。