python 小白之路(跳动的球)

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

"""
Spyder Editor

This is a temporary script file.
"""
import pygame,sys
pygame.init()
size = width,height =  600, 400
speend = [1,1]
WHITE = 255,255,255
screen =pygame.display.set_mode(size)
pygame.display.set_caption("dj")
ball = pygame.image.load("dj.gif")
ballrect =ball.get_rect()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
    ballrect = ballrect.move(speend[0],speend[1])
    if ballrect.left < 0 or ballrect.right >width:
           speend[0] = -speend[0]
    if ballrect.top < 0 or ballrect.bottom > height:
           speend[1] = -speend[1]
    screen.fill(WHITE)
    screen.blit(ball,ballrect)
    pygame.display.update()
    

—————————————————————————————————————————————————————

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import pygame,sys
pygame.init()
size = width,height = 600, 400
speend = [1,1]
WHITE = 255,255,255
screen =pygame.display.set_mode(size)
pygame.display.set_caption("dj")
ball = pygame.image.load("dj.gif")
ballrect =ball.get_rect()
fps = 300
fclock =pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speend[0],speend[1])
if ballrect.left < 0 or ballrect.right >width:
speend[0] = -speend[0]
if ballrect.top < 0 or ballrect.bottom > height:
speend[1] = -speend[1]
screen.fill(WHITE)
screen.blit(ball,ballrect)
pygame.display.update()
fclock.tick(fps)

—————————————————————————————————————————————————————

原文地址:https://www.cnblogs.com/llhhcc/p/10230759.html

时间: 2024-08-30 13:06:03

python 小白之路(跳动的球)的相关文章

python小白之路(基础知识一)

一.开篇输出:print("Hello World!") 二.中文自由行:#coding=utf-8 或 # -- coding:UTF-8 -- 三.Linux多行:#!/usr/bin/python 四.不能少的注释:1.#单行注释 2.'''多行注释''' 五.标识符由字母.下划线.数字组成,且数字不能开头 六.不能修改和使用的关键词 import keyword keyword.kwlist 七.命名规范:1.见名知意 2.驼峰命名法 八.字符串的格式化:1."我叫%

python小白之路(特性语法三之遍历、公共方法、引用)

一.遍历通过for...in...的语法结构,我们可以遍历字符串.列表.元组.字典等数据结构.1.字符串遍历a_str = "hello world"for char in a_str:print(char,end=' ')2.列表遍历a_list = [1,2,3,4,5]for num in a_list:print(num,end=' ')3.元组遍历a_tuple =(1,2,3,4,5)for num in a_tuple:print(num,end=' ')4.字典遍历1)

python小白之路(控制语句二)

1.判断语句:往往用来对是否满足条件进行判断.if.if...else....if...elif...else....if嵌套. 2.循环语句while:一般通过数值是否满足循环条件.for:一般是对能保存多个数据的变量,进行遍历. 3.break和continuebreak:用来结束整个循环.continue:用来结束本次循环,继续执行下一次循环.break/continue只能用在循环中,在嵌套循环中,遵循就近原则只对最近的一层循环起作用. 原文地址:http://blog.51cto.co

python小白之路(特性语法三之字符串)

1.字符串:双引号或单引号中的数据输出:print() 输入:input()切片:[起始下标:结束下标:步长] PS:选取区间属于左闭右开型.[1:5:1] [5:1:-1]常见操作:find: mystr.find(str, start=0, end=len(mystr)) 存在返回索引值,否则返回-1.index: mystr.index(str, start=0, end=len(mystr)) 同find一样,存在返回索引,不存在会报异常.count: mystr.count(str,

python小白之路(特性语法三应用名片管理器项目)

#encoding=utf-8 print("欢迎使用Pyhon名片系统") #定义列表存储名片信息 list_card = [{'编号':1,'姓名':'zhanshi','电话':'110'},{'编号':2,'姓名':'战士','电话':'119'}] while True: print("*"*20) #名片系统功能 print("添加名片[1]") print("删除名片[2]") print("修改名片[

python小白之路(特性语法三之列表)

列表一.列表的格式:变量为studentlist = ['zhangsan','male',29],元素可以是不同数据类型的.二.打印列表:打印学生姓名print(studentlist[0])三.列表的循环遍历1.for student in studentlist:print(studentlist)2.i = 0length = len(students)while i < length:print(studentslist[i])i += 1四.列表的增.删.改.排序1.添加元素:app

我的Python自学之路一:Python学习路线

作为以为小白,在学习Python的时候,必然会走一定的弯路,有人在弯路上走丢了,有人走出了弯路.我就是属于还未走出弯路的同学,所以我想谈谈我的Python学习之路. 我进入这个坑是因为这个最近几年比较火,想必大家都知道吧,我开始学习Python时,先学习的是linux基本命令,作为小白,在装linux时出现许多问题,小白安装可以看看http://blog.csdn.net/u013142781/article/details/50529030这个教程,可能能帮助你成功安装. 其次,学习linux

python小白-day6 time&datetime模块

time&datetime ?一.time模块 time模块提供各种操作时间的函数 说明:一般有两种表示时间的方式:       第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的       第二种以数组的形式表示即(struct_time),共有九个元素,分别表示,同一个时间戳的struct_time会因为时区不同而不同 1 2 3 4 5 6 7 8 9 10 11 12 import time print('clock():',time.cl

Python学习之路-Day1-Python基础

Python学习之路第一天 学习内容: 1.Python简介 2.安装 3.第一个Python程序 4.变量 5.字符编码 6.用户输入 7.表达式if..else语句 8.表达式for语句 9.break和continue 10.while循环 11.字符串格式化 1.python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承. 最新的TIOB