pygame 动画初学

画圆、线、矩形

# 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,代表填充。参数为其他代表线宽。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值